diff options
-rw-r--r-- | omaha_server/omaha/migrations/0027_auto_20160707_0720.py | 39 | ||||
-rw-r--r-- | omaha_server/omaha/migrations/0028_auto_20160707_0825.py | 19 | ||||
-rw-r--r-- | omaha_server/omaha/models.py | 4 |
3 files changed, 62 insertions, 0 deletions
diff --git a/omaha_server/omaha/migrations/0027_auto_20160707_0720.py b/omaha_server/omaha/migrations/0027_auto_20160707_0720.py new file mode 100644 index 0000000..4c35f02 --- /dev/null +++ b/omaha_server/omaha/migrations/0027_auto_20160707_0720.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-07-07 07:20 +from __future__ import unicode_literals + +from django.db import migrations + + +def delete_duplicated_os(apps, schema_editor): + Os = apps.get_model("omaha", "Os") + Request = apps.get_model("omaha", "Request") + list_args = Os.objects.all().values('platform', 'version', 'sp', 'arch') + not_dup_args = [] + dup_args = [] + + for args in list_args: + if args in not_dup_args: + if args not in dup_args: + dup_args.append(args) + else: + not_dup_args.append(args) + + print "\nDuplicated arguments: %s" % dup_args + for args in dup_args: + dups = list(Os.objects.filter(**args)) + original = dups[0] + for os in dups[1:]: + Request.objects.filter(os=os.id).update(os=original.id) + os.delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('omaha', '0026_grant_permission_django_site'), + ] + + operations = [ + migrations.RunPython(delete_duplicated_os, reverse_code=migrations.RunPython.noop), + ] diff --git a/omaha_server/omaha/migrations/0028_auto_20160707_0825.py b/omaha_server/omaha/migrations/0028_auto_20160707_0825.py new file mode 100644 index 0000000..8d5f529 --- /dev/null +++ b/omaha_server/omaha/migrations/0028_auto_20160707_0825.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-07-07 08:25 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('omaha', '0027_auto_20160707_0720'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='os', + unique_together=set([('platform', 'version', 'sp', 'arch')]), + ), + ] diff --git a/omaha_server/omaha/models.py b/omaha_server/omaha/models.py index d908b44..01acec3 100644 --- a/omaha_server/omaha/models.py +++ b/omaha_server/omaha/models.py @@ -242,6 +242,10 @@ class Os(models.Model): sp = models.CharField(max_length=40, null=True, blank=True) arch = models.CharField(max_length=10, null=True, blank=True) + class Meta: + unique_together = ( + ('platform', 'version', 'sp', 'arch'), + ) class Hw(models.Model): sse = models.PositiveIntegerField(null=True, blank=True) |