diff --git a/pandora/annotation/migrations/0003_fill_in_null_public_id.py b/pandora/annotation/migrations/0003_fill_in_null_public_id.py index e82bc4df2..256bfbec7 100644 --- a/pandora/annotation/migrations/0003_fill_in_null_public_id.py +++ b/pandora/annotation/migrations/0003_fill_in_null_public_id.py @@ -8,21 +8,7 @@ import ox class Migration(DataMigration): def forwards(self, orm): - AnnotationSequence = orm['item.AnnotationSequence'] - for annotation in orm.Annotation.objects.filter(public_id=None).order_by('item'): - item = annotation.item - s, created = AnnotationSequence.objects.get_or_create(item=item) - - if created: - nextid = s.value - else: - cursor = connection.cursor() - sql = "UPDATE %s SET value = value + 1 WHERE item_id = %s RETURNING value" % (AnnotationSequence._meta.db_table, item.id) - cursor.execute(sql) - nextid = cursor.fetchone()[0] - - annotation.public_id = "%s/%s" % (item.public_id, ox.toAZ(nextid)) - annotation.save() + pass def backwards(self, orm): pass diff --git a/pandora/item/migrations/0006_add_annotation_sequence.py b/pandora/item/migrations/0006_add_annotation_sequence.py index 191f4c95f..18f4978e9 100644 --- a/pandora/item/migrations/0006_add_annotation_sequence.py +++ b/pandora/item/migrations/0006_add_annotation_sequence.py @@ -2,7 +2,8 @@ from south.utils import datetime_utils as datetime from south.db import db from south.v2 import SchemaMigration -from django.db import models +from django.db import connection +import ox class Migration(SchemaMigration): @@ -20,6 +21,23 @@ class Migration(SchemaMigration): for i in item.models.Item.objects.all(): item.models.AnnotationSequence.reset(i) for a in item.models.Annotation.objects.filter(public_id=None): a.save() + Annotation = orm['annotation.Annotation'] + AnnotationSequence = item.models.AnnotationSequence + for annotation in Annotation.objects.filter(public_id=None).order_by('item'): + item = annotation.item + s, created = AnnotationSequence.objects.get_or_create(item=item) + + if created: + nextid = s.value + else: + cursor = connection.cursor() + sql = "UPDATE %s SET value = value + 1 WHERE item_id = %s RETURNING value" % ( + AnnotationSequence._meta.db_table, item.id) + cursor.execute(sql) + nextid = cursor.fetchone()[0] + + annotation.public_id = "%s/%s" % (item.public_id, ox.toAZ(nextid)) + annotation.save() def backwards(self, orm): # Deleting model 'AnnotationSequence'