0012_target.py 2.7 KB
Newer Older
Guilhem Saurel's avatar
Guilhem Saurel committed
1
2
3
# Generated by Django 2.0.5 on 2018-05-15 15:55

from enum import IntEnum
Guilhem Saurel's avatar
Guilhem Saurel committed
4

Guilhem Saurel's avatar
Guilhem Saurel committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import autoslug.fields
from django.db import migrations, models

TARGETS = IntEnum('Targets', '14.04 16.04 17.10 18.04 dubnium jessie')


def add_targets(apps, schema_editor):
    Target = apps.get_model('rainboard', 'Target')
    Target.objects.create(name='14.04')
    Target.objects.create(name='16.04')
    Target.objects.create(name='17.10')
    Target.objects.create(name='18.04')
    Target.objects.create(name='dubnium')
    Target.objects.create(name='jessie')


def update_targets(apps, schema_editor):
    Image, Target = [apps.get_model('rainboard', model) for model in [Image, Target]]
    images = {Target.objects.get(name=target.name): Image.objects.filter(target=target)}
    for target, qs in images.items():
        qs.update(target=target)


class Migration(migrations.Migration):

    dependencies = [
        ('rainboard', '0011_null_true'),
    ]

    operations = [
        migrations.CreateModel(
            name='Target',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=200, unique=True)),
                ('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name', unique=True)),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.RunPython(add_targets),
        migrations.AlterField(
            model_name='image',
            name='target',
            field=models.ForeignKey(on_delete=models.deletion.CASCADE, to='rainboard.Target'),
        ),
        migrations.RemoveField(
            model_name='robotpkgbuild',
            name='robotpkg',
        ),
        migrations.RemoveField(
            model_name='robotpkgbuild',
            name='target',
        ),
        migrations.RemoveField(
            model_name='systemdependency',
            name='project',
        ),
        migrations.RemoveField(
            model_name='systemdependency',
            name='target',
        ),
        migrations.RemoveField(
            model_name='test',
            name='branch',
        ),
        migrations.RemoveField(
            model_name='test',
            name='commit',
        ),
        migrations.RemoveField(
            model_name='test',
            name='project',
        ),
        migrations.RemoveField(
            model_name='test',
            name='target',
        ),
        migrations.DeleteModel(
            name='RobotpkgBuild',
        ),
        migrations.DeleteModel(
            name='SystemDependency',
        ),
        migrations.DeleteModel(
            name='Test',
        ),
    ]