]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Disable index quoting when applying truncated DDL rules
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 2 Jan 2018 22:10:43 +0000 (17:10 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 3 Jan 2018 22:34:13 +0000 (17:34 -0500)
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
alembic/util/sqla_compat.py
docs/build/unreleased/472.rst [new file with mode: 0644]
tests/test_autogen_indexes.py

index 2a337658914da4f712684eb0b2ac04d2a079122a..a0991495f69c87d1241e73c85d3f44fa0ee714b2 100644 (file)
@@ -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 (file)
index 0000000..617b7b8
--- /dev/null
@@ -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.
+
index e426a678aaa576d539e1fd0a76825cd6a4904a4a..2eaf7d6853b25c131484cd9b8666dc2810236861 100644 (file)
@@ -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