From f106379b5382b2b82aa56466c8d3acaae58327a9 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 15 Jan 2013 21:29:30 -0600 Subject: Clean up and make several migrations modern This moves most migrations to the v2 format that have been presenting some issues. One missing depends_on relationship has been added, and we allow an index to not be dropped if it does not exist due to the shittyness in sqlite3 actually keeping indexes across DDL on that table. Signed-off-by: Dan McGee --- main/migrations/0002_make_maintainer_nullable.py | 23 +++++++---------------- main/migrations/0003_migrate_maintainer.py | 8 +++----- main/migrations/0005_fix_empty_url_pkgdesc.py | 10 +++------- main/migrations/0013_mark_repos_testing.py | 6 +++--- main/migrations/0055_unique_package_in_repo.py | 7 ++++++- 5 files changed, 22 insertions(+), 32 deletions(-) (limited to 'main') diff --git a/main/migrations/0002_make_maintainer_nullable.py b/main/migrations/0002_make_maintainer_nullable.py index 138b103..675635d 100644 --- a/main/migrations/0002_make_maintainer_nullable.py +++ b/main/migrations/0002_make_maintainer_nullable.py @@ -1,26 +1,17 @@ - +# encoding: utf-8 from south.db import db +from south.v2 import SchemaMigration from django.db import models -from main.models import * -class Migration: - +class Migration(SchemaMigration): + def forwards(self, orm): - - # Changing field 'Package.maintainer' - # (to signature: django.db.models.fields.related.ForeignKey(null=True, to=orm['auth.User'])) db.alter_column('packages', 'maintainer_id', orm['main.package:maintainer']) - - - + def backwards(self, orm): - - # Changing field 'Package.maintainer' - # (to signature: django.db.models.fields.related.ForeignKey(to=orm['auth.User'])) db.alter_column('packages', 'maintainer_id', orm['main.package:maintainer']) - - - + + models = { 'auth.group': { 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), diff --git a/main/migrations/0003_migrate_maintainer.py b/main/migrations/0003_migrate_maintainer.py index a3a4793..4169a5c 100644 --- a/main/migrations/0003_migrate_maintainer.py +++ b/main/migrations/0003_migrate_maintainer.py @@ -1,11 +1,9 @@ - +# -*- coding: utf-8 -*- from south.db import db +from south.v2 import DataMigration from django.db import models -from main.models import * - -class Migration: - no_dry_run = True +class Migration(DataMigration): def forwards(self, orm): orm.Package.objects.filter(maintainer=0).update(maintainer=None) diff --git a/main/migrations/0005_fix_empty_url_pkgdesc.py b/main/migrations/0005_fix_empty_url_pkgdesc.py index c7cc1d8..54658c1 100644 --- a/main/migrations/0005_fix_empty_url_pkgdesc.py +++ b/main/migrations/0005_fix_empty_url_pkgdesc.py @@ -1,14 +1,11 @@ - +# -*- coding: utf-8 -*- from south.db import db +from south.v2 import DataMigration from django.db import models -from main.models import * -class Migration: +class Migration(DataMigration): - no_dry_run = True - def forwards(self, orm): - "Write your forwards migration here" for p in orm.Package.objects.filter(pkgdesc=''): p.pkgdesc = None p.save() @@ -24,7 +21,6 @@ class Migration: def backwards(self, orm): - "Write your backwards migration here" for p in orm.Package.objects.filter(pkgdesc=None): p.pkgdesc = '' p.save() diff --git a/main/migrations/0013_mark_repos_testing.py b/main/migrations/0013_mark_repos_testing.py index 617a3ab..e50010b 100644 --- a/main/migrations/0013_mark_repos_testing.py +++ b/main/migrations/0013_mark_repos_testing.py @@ -1,9 +1,9 @@ +# -*- coding: utf-8 -*- from south.db import db +from south.v2 import DataMigration from django.db import models -from main.models import * -class Migration: - no_dry_run = True +class Migration(DataMigration): def forwards(self, orm): orm.Repo.objects.filter(name__endswith="Testing").update(testing=True) diff --git a/main/migrations/0055_unique_package_in_repo.py b/main/migrations/0055_unique_package_in_repo.py index 36cc719..9ae3371 100644 --- a/main/migrations/0055_unique_package_in_repo.py +++ b/main/migrations/0055_unique_package_in_repo.py @@ -2,11 +2,16 @@ from south.db import db from south.v2 import SchemaMigration from django.db import models +from django.db.utils import DatabaseError class Migration(SchemaMigration): def forwards(self, orm): - db.delete_index('packages', ['pkgname']) + try: + db.delete_index('packages', ['pkgname']) + except DatabaseError as e: + if not 'no such index' in str(e): + raise e db.create_unique('packages', ['pkgname', 'repo_id', 'arch_id']) def backwards(self, orm): -- cgit v1.2.3-24-g4f1b