Browse Source

Optimize sequence reset on migration

pull/6/head
Marcio Mazza 10 years ago
parent
commit
e80c233960
  1. 11
      legacy/scripts/migration.py

11
legacy/scripts/migration.py

@ -63,10 +63,13 @@ def migrate_model(model, to_delete, count_limit=None):
model.objects.all().delete() model.objects.all().delete()
def reset_seq(id): def reset_seq(id):
# resets id sequence # resets id sequence
sql_reset_seq = 'ALTER SEQUENCE %s_id_seq RESTART WITH %s;' % (model._meta.db_table, id) if id > reset_seq.last_id + 1:
cursor = connection.cursor() sql_reset_seq = 'ALTER SEQUENCE %s_id_seq RESTART WITH %s;' % (model._meta.db_table, id)
cursor.execute(sql_reset_seq) cursor = connection.cursor()
cursor.execute(sql_reset_seq)
reset_seq.last_id = id
reset_seq.last_id = -1
legacy_model = legacy_app.get_model(model.__name__) legacy_model = legacy_app.get_model(model.__name__)
old_pk_name = legacy_model._meta.pk.name old_pk_name = legacy_model._meta.pk.name

Loading…
Cancel
Save