From: Mike Bayer Date: Tue, 2 Jan 2018 22:10:43 +0000 (-0500) Subject: Disable index quoting when applying truncated DDL rules X-Git-Tag: rel_0_9_7~4^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6307f4d3e1ceac555684b0a073a77b304b166a53;p=thirdparty%2Fsqlalchemy%2Falembic.git Disable index quoting when applying truncated DDL rules Fixed regression caused by :ticket:`421` which would cause case-sensitive quoting rules to interfere with the comparison logic for index names, thus causing indexes to show as added for indexes that have case-sensitive names. Change-Id: Ibd73456109cc95362503576f379acd9f4f0d6d65 Fixes: #472 --- diff --git a/alembic/util/sqla_compat.py b/alembic/util/sqla_compat.py index 2a337658..a0991495 100644 --- a/alembic/util/sqla_compat.py +++ b/alembic/util/sqla_compat.py @@ -178,6 +178,21 @@ def _get_index_column_names(idx): def _get_index_final_name(dialect, idx): if sqla_08: + # trying to keep the truncation rules totally localized on the + # SQLA side while also stepping around the quoting issue. Ideally + # the _prepared_index_name() method on the SQLA side would have + # a quoting option or the truncation routine would be broken out. + # + # test for SQLA quoted_name construct, introduced in + # 0.9 or thereabouts. + # this doesn't work in 0.8 and the "quote" option on Index doesn't + # seem to work in 0.8 either. + if hasattr(idx.name, "quote"): + # might be quoted_name, might be truncated_name, keep it the + # same + quoted_name_cls = type(idx.name) + new_name = quoted_name_cls(str(idx.name), quote=False) + idx = schema.Index(name=new_name) return dialect.ddl_compiler(dialect, None)._prepared_index_name(idx) else: return idx.name diff --git a/docs/build/unreleased/472.rst b/docs/build/unreleased/472.rst new file mode 100644 index 00000000..617b7b8e --- /dev/null +++ b/docs/build/unreleased/472.rst @@ -0,0 +1,10 @@ +.. change:: + :tags: bug, autogenerate + :tickets: 472 + + Fixed regression caused by :ticket:`421` which would + cause case-sensitive quoting rules to interfere with the + comparison logic for index names, thus causing indexes to show + as added for indexes that have case-sensitive names. Works with + SQLAlchemy 0.9 and later series. + diff --git a/tests/test_autogen_indexes.py b/tests/test_autogen_indexes.py index e426a678..2eaf7d68 100644 --- a/tests/test_autogen_indexes.py +++ b/tests/test_autogen_indexes.py @@ -557,6 +557,34 @@ class AutogenerateUniqueIndexTest(AutogenFixtureTest, TestBase): eq_(diffs, []) + # fails in the 0.8 series where we have truncation rules, + # but no control over quoting. passes in 0.7.9 where we don't have + # truncation rules either. dropping these ancient versions + # is long overdue. + + @config.requirements.sqlalchemy_09 + def test_unchanged_case_sensitive_implicit_idx(self): + m1 = MetaData() + m2 = MetaData() + Table('add_ix', m1, Column('regNumber', String(50), index=True)) + Table('add_ix', m2, Column('regNumber', String(50), index=True)) + diffs = self._fixture(m1, m2) + + eq_(diffs, []) + + @config.requirements.sqlalchemy_09 + def test_unchanged_case_sensitive_explicit_idx(self): + m1 = MetaData() + m2 = MetaData() + t1 = Table('add_ix', m1, Column('reg_number', String(50))) + Index('regNumber_idx', t1.c.reg_number) + t2 = Table('add_ix', m2, Column('reg_number', String(50))) + Index('regNumber_idx', t2.c.reg_number) + + diffs = self._fixture(m1, m2) + + eq_(diffs, []) + class PGUniqueIndexTest(AutogenerateUniqueIndexTest): reports_unnamed_constraints = True