migrate annotation sequence in item not annotation
This commit is contained in:
parent
36ebdf0a1c
commit
4ed2d940cf
2 changed files with 20 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue