misc/migration/bootstrapmigration_repository.py
changeset 9585 3f5b59527d31
parent 9543 39f981482e34
child 9708 b36bc18f6ef7
--- a/misc/migration/bootstrapmigration_repository.py	Thu Feb 06 19:04:03 2014 +0100
+++ b/misc/migration/bootstrapmigration_repository.py	Mon Mar 24 18:14:22 2014 +0100
@@ -35,6 +35,23 @@
     ss.execschemarql(rql, rdef, ss.rdef2rql(rdef, CSTRMAP, groupmap=None))
     commit(ask_confirm=False)
 
+def replace_eid_sequence_with_eid_numrange(session):
+    dbh = session.repo.system_source.dbhelper
+    cursor = session.cnxset.cu
+    try:
+        cursor.execute(dbh.sql_sequence_current_state('entities_id_seq'))
+        lasteid = cursor.fetchone()[0]
+    except: # programming error, already migrated
+        return
+
+    cursor.execute(dbh.sql_drop_sequence('entities_id_seq'))
+    cursor.execute(dbh.sql_create_numrange('entities_id_seq'))
+    cursor.execute(dbh.sql_restart_numrange('entities_id_seq', initial_value=lasteid))
+    session.commit()
+
+if applcubicwebversion < (3, 19, 0) and cubicwebversion >= (3, 19, 0):
+    replace_eid_sequence_with_eid_numrange(session)
+
 if applcubicwebversion < (3, 17, 0) and cubicwebversion >= (3, 17, 0):
     try:
         add_cube('sioc', update_database=False)