From: Johannes Erdfelt Date: Thu, 4 Dec 2014 17:42:46 +0000 (-0800) Subject: MySQL: Ignore unique indexes when removing implicit indexes X-Git-Tag: rel_0_7_2~7^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22667c19df7e30469b61f901cd6404f5d3a5cc14;p=thirdparty%2Fsqlalchemy%2Falembic.git MySQL: Ignore unique indexes when removing implicit indexes MySQL will implicitly create indexes when using foreign keys. Alembic attempts to remove those implicit indexes so they don't appear as removes when comparing metadata. However, unique indexes with the same name as a column are considered as possibly implicitly created causing alembic to emit a spurious 'remove_constraint'. Since MySQL will never implicitly create unique indexes, they can be safely ignored when removing the implicit indexes. Fixes #251 --- diff --git a/alembic/ddl/mysql.py b/alembic/ddl/mysql.py index b93d29fc..cb9d6349 100644 --- a/alembic/ddl/mysql.py +++ b/alembic/ddl/mysql.py @@ -102,6 +102,8 @@ class MySQLImpl(DefaultImpl): # the name of the index may be the column name or it may # be the name of the FK constraint. for col in idx.columns: + if idx.unique: + continue if idx.name == col.name: conn_indexes.remove(idx) removed.add(idx.name) diff --git a/tests/test_autogen_indexes.py b/tests/test_autogen_indexes.py index ad839c83..e2d9b4ea 100644 --- a/tests/test_autogen_indexes.py +++ b/tests/test_autogen_indexes.py @@ -586,6 +586,25 @@ class MySQLUniqueIndexTest(AutogenerateUniqueIndexTest): else: assert False, "unexpected success" + def test_unique_index_foreign_key(self): + m1 = MetaData() + m2 = MetaData() + + Table('unq_idx', m1, + Column('id', Integer, primary_key=True), + Column('x', String(20)), + Index('x', 'x', unique=True) + ) + + Table('unq_idx', m2, + Column('id', Integer, primary_key=True), + Column('x', String(20)), + Index('x', 'x', unique=True) + ) + + diffs = self._fixture(m1, m2) + eq_(diffs, []) + class NoUqReflectionIndexTest(NoUqReflection, AutogenerateUniqueIndexTest): reports_unique_constraints = False