# HG changeset patch # User Sylvain Thénault # Date 1479400009 -3600 # Node ID eed83dee2c793eff7b70c4f0c20e279856c55e2f # Parent 4b52c358b0ff101c3962e4d3adbc0b47e1e7fea5 [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 diff -r 4b52c358b0ff -r eed83dee2c79 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)