]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Repair server default comparison for MySQL / MariaDB
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 19 Feb 2018 19:00:11 +0000 (14:00 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 19 Feb 2018 21:42:19 +0000 (16:42 -0500)
The regexp for comparing the TIMESTAMP function
was obliterating all other comparisons as it was incorrect.
Add new regexp for integers that also adjusts for
mariadb 10.2 quoting differences vs. mariadb 10.1

Change-Id: I7bdaceb7e0dbe06bc2c3690cd5dd8e737716278c
Fixes: #455
Fixes: #483
alembic/ddl/mysql.py
docs/build/unreleased/455.rst [new file with mode: 0644]
docs/build/unreleased/483.rst [new file with mode: 0644]
tests/test_mysql.py

index 71b186cd75f344fd7c86d450737a97c5643142da..32e67ee3fbadfb2291333b121d0f8596114d1719 100644 (file)
@@ -89,20 +89,25 @@ class MySQLImpl(DefaultImpl):
         # partially a workaround for SQLAlchemy issue #3023; if the
         # column were created without "NOT NULL", MySQL may have added
         # an implicit default of '0' which we need to skip
+        # TODO: this is not really covered anymore ?
         if metadata_column.type._type_affinity is sqltypes.Integer and \
             inspector_column.primary_key and \
                 not inspector_column.autoincrement and \
                 not rendered_metadata_default and \
                 rendered_inspector_default == "'0'":
             return False
+        elif inspector_column.type._type_affinity is sqltypes.Integer:
+            rendered_inspector_default = re.sub(
+                r"^'|'$", '', rendered_inspector_default)
+            return rendered_inspector_default != rendered_metadata_default
         elif rendered_inspector_default and rendered_metadata_default:
             # adjust for "function()" vs. "FUNCTION"
             return (
                 re.sub(
-                    r'(.*)(\(\))?$', '\1',
+                    r'(.*?)(?:\(\))?$', r'\1',
                     rendered_inspector_default.lower()) !=
                 re.sub(
-                    r'(.*)(\(\))?$', '\1',
+                    r'(.*?)(?:\(\))?$', r'\1',
                     rendered_metadata_default.lower())
             )
         else:
diff --git a/docs/build/unreleased/455.rst b/docs/build/unreleased/455.rst
new file mode 100644 (file)
index 0000000..c9d439d
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, autogenerate, mysql
+    :tickets: 455
+
+    The fix for :ticket:`455` in version 0.9.6 involving MySQL server default
+    comparison was entirely non functional, as the test itself was also broken
+    and didn't reveal that it wasn't working. The regular expression to compare
+    server default values like CURRENT_TIMESTAMP to current_timestamp() is
+    repaired.
diff --git a/docs/build/unreleased/483.rst b/docs/build/unreleased/483.rst
new file mode 100644 (file)
index 0000000..fc4ca12
--- /dev/null
@@ -0,0 +1,11 @@
+.. change::
+    :tags: bug, mysql, autogenerate
+    :tickets: 483
+
+    Fixed bug where MySQL server default comparisons were basically not working
+    at all due to incorrect regexp added in :ticket:`455`.  Also accommodates
+    for MariaDB 10.2 quoting differences in reporting integer based server
+    defaults.
+
+
+
index e7b1cf08c32d93c27d1571fa53dc891ff167b792..321488fab026bb59c36efe017d9a519da04ff402 100644 (file)
@@ -277,9 +277,11 @@ class MySQLDefaultCompareTest(TestBase):
         t1.create(self.bind)
         insp = Inspector.from_engine(self.bind)
         cols = insp.get_columns(t1.name)
+        refl = Table(t1.name, MetaData())
+        insp.reflecttable(refl, None)
         ctx = self.autogen_context['context']
         return ctx.impl.compare_server_default(
-            None,
+            refl.c[cols[0]['name']],
             col,
             rendered,
             cols[0]['default'])
@@ -295,3 +297,23 @@ class MySQLDefaultCompareTest(TestBase):
             TIMESTAMP(),
             None, "CURRENT_TIMESTAMP",
         )
+
+    def test_compare_integer_same(self):
+        self._compare_default_roundtrip(
+            Integer(), "5"
+        )
+
+    def test_compare_integer_diff(self):
+        self._compare_default_roundtrip(
+            Integer(), "5", "7"
+        )
+
+    def test_compare_boolean_same(self):
+        self._compare_default_roundtrip(
+            Boolean(), "1"
+        )
+
+    def test_compare_boolean_diff(self):
+        self._compare_default_roundtrip(
+            Boolean(), "1", "0"
+        )