only migrate AnnotationSequence if we have items
This commit is contained in:
parent
9be454dfba
commit
9b1ed58ff2
1 changed files with 15 additions and 15 deletions
|
@ -21,23 +21,23 @@ class Migration(SchemaMigration):
|
||||||
for i in item.models.Item.objects.all():
|
for i in item.models.Item.objects.all():
|
||||||
item.models.AnnotationSequence.reset(i)
|
item.models.AnnotationSequence.reset(i)
|
||||||
for a in item.models.Annotation.objects.filter(public_id=None): a.save()
|
for a in item.models.Annotation.objects.filter(public_id=None): a.save()
|
||||||
Annotation = orm['annotation.Annotation']
|
Annotation = orm['annotation.Annotation']
|
||||||
AnnotationSequence = item.models.AnnotationSequence
|
AnnotationSequence = item.models.AnnotationSequence
|
||||||
for annotation in Annotation.objects.filter(public_id=None).order_by('item'):
|
for annotation in Annotation.objects.filter(public_id=None).order_by('item'):
|
||||||
item = annotation.item
|
item = annotation.item
|
||||||
s, created = AnnotationSequence.objects.get_or_create(item=item)
|
s, created = AnnotationSequence.objects.get_or_create(item=item)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
nextid = s.value
|
nextid = s.value
|
||||||
else:
|
else:
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
sql = "UPDATE %s SET value = value + 1 WHERE item_id = %s RETURNING value" % (
|
sql = "UPDATE %s SET value = value + 1 WHERE item_id = %s RETURNING value" % (
|
||||||
AnnotationSequence._meta.db_table, item.id)
|
AnnotationSequence._meta.db_table, item.id)
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
nextid = cursor.fetchone()[0]
|
nextid = cursor.fetchone()[0]
|
||||||
|
|
||||||
annotation.public_id = "%s/%s" % (item.public_id, ox.toAZ(nextid))
|
annotation.public_id = "%s/%s" % (item.public_id, ox.toAZ(nextid))
|
||||||
annotation.save()
|
annotation.save()
|
||||||
|
|
||||||
def backwards(self, orm):
|
def backwards(self, orm):
|
||||||
# Deleting model 'AnnotationSequence'
|
# Deleting model 'AnnotationSequence'
|
||||||
|
|
Loading…
Reference in a new issue