]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Accommodate for mariadb 10.2 function reflection style
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 4 Oct 2017 20:01:33 +0000 (16:01 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 5 Oct 2017 14:19:16 +0000 (10:19 -0400)
Fixed bug where server default comparison of CURRENT_TIMESTAMP would fail
on MariaDB 10.2 due to a change in how the function is
represented by the database during reflection.

Also implement mariadb 10.2 checks from SQLAlchemy to skip
other CHECK contraint related tests that can't pass.

Change-Id: Id77b527d3215d06e2f44a6cddeb77583e5b39101
Fixes: #455
alembic/ddl/mysql.py
alembic/util/sqla_compat.py
docs/build/unreleased/455.rst [new file with mode: 0644]
tests/requirements.py
tests/test_batch.py

index 3af4fa65ea2a1f9542e72ab0ceb30fcb98096cc5..aff7561a56e90d5066d515a198e16158577bd538 100644 (file)
@@ -11,6 +11,7 @@ from .base import ColumnNullable, ColumnName, ColumnDefault, \
 from .base import alter_table
 from ..autogenerate import compare
 from ..util.sqla_compat import _is_type_bound, sqla_100
+import re
 
 
 class MySQLImpl(DefaultImpl):
@@ -94,6 +95,16 @@ class MySQLImpl(DefaultImpl):
                 not rendered_metadata_default and \
                 rendered_inspector_default == "'0'":
             return False
+        elif rendered_inspector_default and rendered_metadata_default:
+            # adjust for "function()" vs. "FUNCTION"
+            return (
+                re.sub(
+                    r'(.*)(\(\))?$', '\1',
+                    rendered_inspector_default.lower()) !=
+                re.sub(
+                    r'(.*)(\(\))?$', '\1',
+                    rendered_metadata_default.lower())
+            )
         else:
             return rendered_inspector_default != rendered_metadata_default
 
index e0507f89e27f7010576449c4d8c09b1653dd5bec..b90316a52f79a15936fa7438eb69233b3e1f7edb 100644 (file)
@@ -180,3 +180,14 @@ def _get_index_final_name(dialect, idx):
         return dialect.ddl_compiler(dialect, None)._prepared_index_name(idx)
     else:
         return idx.name
+
+
+def _is_mariadb(mysql_dialect):
+    return 'MariaDB' in mysql_dialect.server_version_info
+
+
+def _mariadb_normalized_version_info(mysql_dialect):
+    if len(mysql_dialect.server_version_info) > 5:
+        return mysql_dialect.server_version_info[3:]
+    else:
+        return mysql_dialect.server_version_info
diff --git a/docs/build/unreleased/455.rst b/docs/build/unreleased/455.rst
new file mode 100644 (file)
index 0000000..8622fa3
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, mysql
+    :tickets: 455
+
+    Fixed bug where server default comparison of CURRENT_TIMESTAMP would fail
+    on MariaDB 10.2 due to a change in how the function is
+    represented by the database during reflection.
index 2129e4329ebee7b9107a8090e5b3d34d4b37cde7..660ae21aaa2ab607bb18eea99de2e098482551a1 100644 (file)
@@ -1,6 +1,7 @@
 from alembic.testing.requirements import SuiteRequirements
 from alembic.testing import exclusions
 from alembic import util
+from alembic.util import sqla_compat
 
 
 class DefaultRequirements(SuiteRequirements):
@@ -123,3 +124,16 @@ class DefaultRequirements(SuiteRequirements):
     def integer_subtype_comparisons(self):
         """if a compare of Integer and BigInteger is supported yet."""
         return exclusions.skip_if(["oracle"], "not supported by alembic impl")
+
+    def _mariadb_102(self, config):
+        return exclusions.against(config, "mysql") and \
+            sqla_compat._is_mariadb(config.db.dialect) and \
+            sqla_compat._mariadb_normalized_version_info(
+                config.db.dialect) > (10, 2)
+
+    def _mysql_not_mariadb_102(self, config):
+        return exclusions.against(config, "mysql") and (
+            not sqla_compat._is_mariadb(config.db.dialect) or
+            sqla_compat._mariadb_normalized_version_info(
+                config.db.dialect) < (10, 2)
+        )
index 99d79560be4edee87ae5966f978eefbeb5dd4705..734fc869e81a376255827242fad7313289673e67 100644 (file)
@@ -1438,6 +1438,10 @@ class BatchRoundTripMySQLTest(BatchRoundTripTest):
     def test_create_drop_index(self):
         super(BatchRoundTripMySQLTest, self).test_create_drop_index()
 
+    @exclusions.fails_if(config.requirements._mariadb_102)
+    def test_rename_column_boolean(self):
+        super(BatchRoundTripMySQLTest, self).test_rename_column_boolean()
+
 
 class BatchRoundTripPostgresqlTest(BatchRoundTripTest):
     __only_on__ = "postgresql"