From 9b1ed58ff2989cfd4d2318b85ad58a634721e954 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 11 Nov 2015 09:48:16 +0100 Subject: [PATCH] only migrate AnnotationSequence if we have items --- .../0006_add_annotation_sequence.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pandora/item/migrations/0006_add_annotation_sequence.py b/pandora/item/migrations/0006_add_annotation_sequence.py index 18f4978e..f2d59c66 100644 --- a/pandora/item/migrations/0006_add_annotation_sequence.py +++ b/pandora/item/migrations/0006_add_annotation_sequence.py @@ -21,23 +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) + 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] + 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() + annotation.public_id = "%s/%s" % (item.public_id, ox.toAZ(nextid)) + annotation.save() def backwards(self, orm): # Deleting model 'AnnotationSequence'