[migration/bootstrap] add explicit index removal for sqlserver, be tolerant to migration replay
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Mon, 24 Nov 2014 11:49:28 +0100
changeset 10058 d47c318f95b2
parent 10047 a1fde2d343b6
child 10059 dab538127d72
[migration/bootstrap] add explicit index removal for sqlserver, be tolerant to migration replay Closes #4618944.
misc/migration/bootstrapmigration_repository.py
--- a/misc/migration/bootstrapmigration_repository.py	Mon Nov 24 17:43:29 2014 +0100
+++ b/misc/migration/bootstrapmigration_repository.py	Mon Nov 24 11:49:28 2014 +0100
@@ -50,8 +50,14 @@
     session.commit()
 
 if applcubicwebversion < (3, 19, 0) and cubicwebversion >= (3, 19, 0):
-    sql('ALTER TABLE "entities" DROP COLUMN "mtime"')
-    sql('ALTER TABLE "entities" DROP COLUMN "source"')
+    try: 
+        # need explicit drop of the indexes on some database systems (sqlserver)
+        sql(repo.system_source.dbhelper.sql_drop_index('entities', 'mtime'))
+        sql('ALTER TABLE "entities" DROP COLUMN "mtime"')
+        sql('ALTER TABLE "entities" DROP COLUMN "source"')
+    except: # programming error, already migrated
+        print "Failed to drop mtime or source database columns"
+        print "'entities' table of the database has probably been already updated"
 
     commit()