[migration] add rollback when replace_eid_sequence_with_eid_numrange fails

If we get here, the current transaction is aborted, so if we are to assume everything is fine and continue we need to rollback first.

authorJulien Cristau <julien.cristau@logilab.fr>
changeset97bb66a6809c
branchdefault
phasedraft
hiddenyes
parent revision#2dafcdd19c99 pep8 bits
child revision#e1b44f8a25c2 [migration] attempt at idempotency when dropping columns from the entities table
files modified by this revision
cubicweb/misc/migration/bootstrapmigration_repository.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1455714095 -3600
# Wed Feb 17 14:01:35 2016 +0100
# Node ID 97bb66a6809c98abc35ebac9eac3515adc38bb45
# Parent 2dafcdd19c9918f6d0bde86b6afdcaf07c1722b3
[migration] add rollback when replace_eid_sequence_with_eid_numrange fails

If we get here, the current transaction is aborted, so if we are to
assume everything is fine and continue we need to rollback first.

diff --git a/cubicweb/misc/migration/bootstrapmigration_repository.py b/cubicweb/misc/migration/bootstrapmigration_repository.py
@@ -43,10 +43,11 @@
1      cursor = session.cnxset.cu
2      try:
3          cursor.execute(dbh.sql_sequence_current_state('entities_id_seq'))
4          lasteid = cursor.fetchone()[0]
5      except: # programming error, already migrated
6 +        session.rollback()
7          return
8 
9      cursor.execute(dbh.sql_drop_sequence('entities_id_seq'))
10      cursor.execute(dbh.sql_create_numrange('entities_id_seq'))
11      cursor.execute(dbh.sql_restart_numrange('entities_id_seq', initial_value=lasteid))