diff options
Diffstat (limited to 'bitbake/lib/toaster/orm/migrations/0012_use_release_instead_of_up_branch.py')
-rw-r--r-- | bitbake/lib/toaster/orm/migrations/0012_use_release_instead_of_up_branch.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/orm/migrations/0012_use_release_instead_of_up_branch.py b/bitbake/lib/toaster/orm/migrations/0012_use_release_instead_of_up_branch.py new file mode 100644 index 0000000000..0e6bb83311 --- /dev/null +++ b/bitbake/lib/toaster/orm/migrations/0012_use_release_instead_of_up_branch.py | |||
@@ -0,0 +1,62 @@ | |||
1 | # -*- coding: utf-8 -*- | ||
2 | from __future__ import unicode_literals | ||
3 | |||
4 | from django.db import migrations, models | ||
5 | from django.db.models import Q | ||
6 | |||
7 | |||
8 | def branch_to_release(apps, schema_editor): | ||
9 | Layer_Version = apps.get_model('orm', 'Layer_Version') | ||
10 | Release = apps.get_model('orm', 'Release') | ||
11 | |||
12 | print("Converting all layer version up_branches to releases") | ||
13 | # Find all the layer versions which have an upbranch and convert them to | ||
14 | # the release that they're for. | ||
15 | for layer_version in Layer_Version.objects.filter( | ||
16 | Q(release=None) & ~Q(up_branch=None)): | ||
17 | try: | ||
18 | # HEAD and local are equivalent | ||
19 | if "HEAD" in layer_version.up_branch.name: | ||
20 | release = Release.objects.get(name="local") | ||
21 | layer_version.commit = "HEAD" | ||
22 | layer_version.branch = "HEAD" | ||
23 | else: | ||
24 | release = Release.objects.get( | ||
25 | name=layer_version.up_branch.name) | ||
26 | |||
27 | layer_version.release = release | ||
28 | layer_version.save() | ||
29 | except Exception as e: | ||
30 | print("Couldn't work out an appropriate release for %s " | ||
31 | "the up_branch was %s " | ||
32 | "user the django admin interface to correct it" % | ||
33 | (layer_version.layer.name, layer_version.up_branch.name)) | ||
34 | print(e) | ||
35 | |||
36 | continue | ||
37 | |||
38 | |||
39 | class Migration(migrations.Migration): | ||
40 | |||
41 | dependencies = [ | ||
42 | ('orm', '0011_delete_layersource'), | ||
43 | ] | ||
44 | |||
45 | operations = [ | ||
46 | migrations.AddField( | ||
47 | model_name='layer_version', | ||
48 | name='release', | ||
49 | field=models.ForeignKey(to='orm.Release', default=None, null=True), | ||
50 | ), | ||
51 | migrations.RunPython(branch_to_release, | ||
52 | reverse_code=migrations.RunPython.noop), | ||
53 | |||
54 | migrations.RemoveField( | ||
55 | model_name='layer_version', | ||
56 | name='up_branch', | ||
57 | ), | ||
58 | |||
59 | migrations.DeleteModel( | ||
60 | name='Branch', | ||
61 | ), | ||
62 | ] | ||