Changes between Version 2 and Version 5 of Ticket #27871


Ignore:
Timestamp:
Feb 28, 2017, 11:53:34 AM (8 years ago)
Author:
Kyle Agronick
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #27871

    • Property Component Database layer (models, ORM)Migrations
  • Ticket #27871 – Description

    v2 v5  
    1 This is what the migration looks like:
     1Here are all the models:
     2
     3{{{
     4
     5from django.contrib.auth.models import User
     6from django.db import models
     7
     8job_state = (('P', 'Pending'), ('A', 'Active'), ('C', 'Completed'), ('F', 'Failed'))
     9app_type = (('R', 'RX'), ('W', 'WAR'))
     10server_types = #taken out
    211
    312
    4 {{{
    5 class Migration(migrations.Migration):
    6 
    7     dependencies = [
    8         ('jobs', '0003_auto_20170222_1154'),
    9     ]
    10 
    11     operations = [
    12         migrations.AlterField(
    13             model_name='joblog',
    14             name='job',
    15             field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='logs', to='jobs.Job'),
    16         ),
    17     ]
    18 
    19 }}}
     13class JobGroup(models.Model):
     14    job_type = models.CharField(max_length=100, db_index=True)
     15    created_by = models.ForeignKey(User)
     16    queued_date = models.DateTimeField(null=True, db_index=True)
     17    created_date = models.DateTimeField(auto_now_add=True, db_index=True)
    2018
    2119
    22 Running ./mange.py migrate makes no difference. I recently moved the codebase to Python 3.
     20class JobParameter(models.Model):
     21    job_group = models.ForeignKey(JobGroup, related_name='job_param', on_delete=models.CASCADE)
     22    name = models.CharField(max_length=100, db_index=True)
     23    value = models.TextField()
    2324
    24 Below is the create table syntax for the relevant tables:
     25    def split_values(self):
     26        if ',' in self.value and isinstance(self.value, str):
     27            return self.value.split(', ')
     28        else:
     29            return [self.value]
     30
     31    class Meta:
     32        unique_together = ('job_group', 'name')
    2533
    2634
    27 {{{
    28 CREATE TABLE `jobs_jobparameter` (
    29   `id` int(11) NOT NULL AUTO_INCREMENT,
    30   `name` varchar(100) NOT NULL,
    31   `value` longtext NOT NULL,
    32   `job_group_id` int(11) NOT NULL,
    33   PRIMARY KEY (`id`),
    34   UNIQUE KEY `jobs_jobparameter_job_group_id_bbb541f6_uniq` (`job_group_id`,`name`),
    35   KEY `jobs_jobparameter_name_84b3d6ba_uniq` (`name`),
    36   CONSTRAINT `jobs_jobparameter_job_group_id_7205c657_fk_jobs_jobgroup_id` FOREIGN KEY (`job_group_id`) REFERENCES `jobs_jobgroup` (`id`)
    37 ) ENGINE=InnoDB AUTO_INCREMENT=45338 DEFAULT CHARSET=utf8
     35class Job(models.Model):
     36    job_group = models.ForeignKey(JobGroup, related_name='jobs', on_delete=models.CASCADE)
     37    state = models.CharField(max_length=1, choices=job_state, default='P', db_index=True)
     38    start_date = models.DateTimeField(null=True, db_index=True)
     39    end_date = models.DateTimeField(null=True)
     40    store = models.CharField(max_length=40, db_index=True)
     41    payload = models.TextField()
    3842
    39 CREATE TABLE `jobs_joblog` (
    40   `id` int(11) NOT NULL AUTO_INCREMENT,
    41   `command` longtext NOT NULL,
    42   `command_output` longtext NOT NULL,
    43   `result` tinyint(1) NOT NULL,
    44   `job_id` int(11) NOT NULL,
    45   PRIMARY KEY (`id`),
    46   KEY `jobs_joblog_job_id_734186c1ec7977e9_fk_jobs_job_id` (`job_id`),
    47   CONSTRAINT `jobs_joblog_job_id_ae8f8e96_fk_jobs_job_id` FOREIGN KEY (`job_id`) REFERENCES `jobs_job` (`id`)
    48 ) ENGINE=InnoDB AUTO_INCREMENT=7749677 DEFAULT CHARSET=latin1
     43    def get_full_state(self):
     44        return self.get_state_display() if self.state in dict(job_state) else 'Unknown'
    4945
    50 CREATE TABLE `jobs_jobgroup` (
    51   `id` int(11) NOT NULL AUTO_INCREMENT,
    52   `job_type` varchar(100) NOT NULL,
    53   `created_by_id` int(11) NOT NULL,
    54   `created_date` datetime NOT NULL,
    55   `queued_date` datetime DEFAULT NULL,
    56   PRIMARY KEY (`id`),
    57   KEY `jobs_jobgroup_created_by_id_769ccba8b90c80f8_fk_auth_user_id` (`created_by_id`),
    58   KEY `jobs_jobgroup_job_type_c2db1010_uniq` (`job_type`),
    59   KEY `jobs_jobgroup_created_date_852898d7_uniq` (`created_date`),
    60   KEY `jobs_jobgroup_queued_date_c38be898_uniq` (`queued_date`),
    61   CONSTRAINT `jobs_jobgroup_created_by_id_769ccba8b90c80f8_fk_auth_user_id` FOREIGN KEY (`created_by_id`) REFERENCES `auth_user` (`id`)
    62 ) ENGINE=InnoDB AUTO_INCREMENT=15290 DEFAULT CHARSET=latin1
     46    class Meta:
     47        permissions = (
     48            ('deployment_job', 'Access Deployment job'),
     49            ('services_job', 'Access System Services job'),
     50            ('offline_status_job', 'Access Offline Status job'),
     51        )
    6352
    64 CREATE TABLE `jobs_job` (
    65   `id` int(11) NOT NULL AUTO_INCREMENT,
    66   `state` varchar(1) NOT NULL,
    67   `start_date` datetime DEFAULT NULL,
    68   `end_date` datetime DEFAULT NULL,
    69   `job_group_id` int(11) NOT NULL,
    70   `store` varchar(40) NOT NULL,
    71   `payload` longtext NOT NULL,
    72   PRIMARY KEY (`id`),
    73   KEY `jobs_job_be96d149` (`job_group_id`),
    74   KEY `jobs_job_store_6681c0e7_uniq` (`store`),
    75   KEY `jobs_job_start_date_b8aefdc3_uniq` (`start_date`),
    76   KEY `jobs_job_state_6ec9b5f7_uniq` (`state`),
    77   CONSTRAINT `jobs_job_job_group_id_93d2fccf_fk_jobs_jobgroup_id` FOREIGN KEY (`job_group_id`) REFERENCES `jobs_jobgroup` (`id`)
    78 ) ENGINE=InnoDB AUTO_INCREMENT=3316872 DEFAULT CHARSET=latin1
     53
     54class JobLog(models.Model):
     55    job = models.ForeignKey(Job, related_name='logs', on_delete=models.CASCADE)
     56    command = models.TextField()
     57    command_output = models.TextField()
     58    result = models.BooleanField(default=False)
     59
     60
     61class Service(models.Model):
     62    service_name = models.CharField(max_length=40)
     63    human_readable_name = models.CharField(max_length=40)
     64    server_type = models.CharField(choices=server_types, max_length=5)
     65
     66    def __str__(self):
     67        return self.human_readable_name
     68
     69    class Meta:
     70        ordering = ['human_readable_name']
     71        unique_together = ['service_name', 'server_type']
    7972}}}
    80 
    81 The migrations are attached.
Back to Top