[migration] Fix 3.23.0 migration script, broken by a703f00718c2 3.23
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 17 Nov 2016 17:26:49 +0100
branch3.23
changeset 11845 eed83dee2c79
parent 11722 4b52c358b0ff
child 11846 7e03f38c8d5f
child 11961 a25e52cd8be4
[migration] Fix 3.23.0 migration script, broken by a703f00718c2 * first query use "IN" where it should use "=" -> crash * second query is missing an interpolation -> crash * third query is attempting to remove constraint that have already been removed by the second query -> crash
cubicweb/misc/migration/3.23.0_Any.py
--- a/cubicweb/misc/migration/3.23.0_Any.py	Wed Oct 19 22:31:32 2016 +0200
+++ b/cubicweb/misc/migration/3.23.0_Any.py	Thu Nov 17 17:26:49 2016 +0100
@@ -16,18 +16,18 @@
     SELECT DISTINCT tc.table_name, tc.constraint_name
     FROM information_schema.table_constraints tc,
          information_schema.key_column_usage kc
-    WHERE tc.constraint_type IN 'PRIMARY KEY'
+    WHERE tc.constraint_type = 'PRIMARY KEY'
           AND kc.table_name = tc.table_name
           AND kc.table_name LIKE '%\_relation'
           AND kc.table_schema = tc.table_schema
           AND kc.constraint_name = tc.constraint_name;
 '''):
-    sql('ALTER TABLE %s DROP CONSTRAINT' % (table, cstr))
+    sql('ALTER TABLE %s DROP CONSTRAINT %s' % (table, cstr))
 
 for table, cstr in sql("""
     SELECT DISTINCT table_name, constraint_name FROM information_schema.constraint_column_usage
     WHERE table_name LIKE 'cw\_%' AND constraint_name LIKE '%\_key'"""):
-    sql("ALTER TABLE %(table)s DROP CONSTRAINT %(cstr)s" % locals())
+    sql('ALTER TABLE %s DROP CONSTRAINT %s' % (table, cstr))
 
 for rschema in schema.relations():
     if rschema.rule or rschema in PURE_VIRTUAL_RTYPES:
@@ -36,10 +36,6 @@
         for rdef in rschema.rdefs.values():
             table = 'cw_{0}'.format(rdef.subject)
             column = 'cw_{0}'.format(rdef.rtype)
-            if any(isinstance(cstr, UniqueConstraint) for cstr in rdef.constraints):
-                old_name = '%s_%s_key' % (table.lower(), column.lower())
-                sql('ALTER TABLE %s DROP CONSTRAINT %s' % (table, old_name))
-                source.create_index(cnx, table, column, unique=True)
             if rschema.inlined or rdef.indexed:
                 old_name = '%s_%s_idx' % (table.lower(), column.lower())
                 sql('DROP INDEX IF EXISTS %s' % old_name)