]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Open up mysql CHECK constraint detection to include new versions
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 4 May 2019 17:19:10 +0000 (13:19 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 5 May 2019 05:04:06 +0000 (23:04 -0600)
MySQL 8.0.16 introduces real CHECK constraints and MariaDB has also
added them into the 10.2 series sometime before 10.2.22.

Change-Id: Ia0f1be69f99df935aae069f63381bcc994f73cc7

lib/sqlalchemy/dialects/mysql/base.py
test/engine/test_reflection.py
test/requirements.py

index 9d83541ae48d53f7df6080a33e532fda9311211c..02929fc5dc6776bd7a982c628f7b5be85c7096c6 100644 (file)
@@ -2617,7 +2617,6 @@ class MySQLDialect(default.DefaultDialect):
 
     @reflection.cache
     def get_check_constraints(self, connection, table_name, schema=None, **kw):
-
         parsed_state = self._parsed_state_or_create(
             connection, table_name, schema, **kw
         )
index 273cc73565149044dd744b09d9cea485d2dd2758..b414e15ad4426866d21f1837fce0f6995730bd9c 100644 (file)
@@ -1388,7 +1388,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables):
             if isinstance(const, sa.CheckConstraint)
         ][0]
 
-        eq_regex(ck.sqltext.text, r".?q.? > 10")
+        eq_regex(ck.sqltext.text, r"[\(`]*q[\)`]* > 10")
         eq_(ck.name, "ck1")
 
     @testing.provide_metadata
index ab3f01d04a0d00ab42a8e9873ae460ad554c14cb..059ce01871923ecde2de315773ba94afae72810f 100644 (file)
@@ -52,7 +52,7 @@ class DefaultRequirements(SuiteRequirements):
         """Target database must also enforce check constraints."""
 
         return self.check_constraints + fails_on(
-            self._mysql_not_mariadb_102,
+            self._mysql_check_constraints_dont_exist,
             "check constraints don't enforce on MySQL, MariaDB<10.2",
         )
 
@@ -457,7 +457,10 @@ class DefaultRequirements(SuiteRequirements):
     @property
     def check_constraint_reflection(self):
         return fails_on_everything_except(
-            "postgresql", "sqlite", "oracle", self._mariadb_102
+            "postgresql",
+            "sqlite",
+            "oracle",
+            self._mysql_and_check_constraints_exist,
         )
 
     @property
@@ -1311,6 +1314,33 @@ class DefaultRequirements(SuiteRequirements):
             and config.db.dialect._mariadb_normalized_version_info > (10, 2)
         )
 
+    def _mysql_and_check_constraints_exist(self, config):
+        # 1. we have mysql / mariadb and
+        # 2. it enforces check constraints
+        if exclusions.against(config, "mysql"):
+            if config.db.dialect._is_mariadb:
+                norm_version_info = (
+                    config.db.dialect._mariadb_normalized_version_info
+                )
+                return norm_version_info >= (10, 2)
+            else:
+                norm_version_info = config.db.dialect.server_version_info
+                return norm_version_info >= (8, 0, 16)
+        else:
+            return False
+
+    def _mysql_check_constraints_exist(self, config):
+        # 1. we dont have mysql / mariadb or
+        # 2. we have mysql / mariadb that enforces check constraints
+        return not exclusions.against(
+            config, "mysql"
+        ) or self._mysql_and_check_constraints_exist(config)
+
+    def _mysql_check_constraints_dont_exist(self, config):
+        # 1. we have mysql / mariadb and
+        # 2. they dont enforce check constraints
+        return not self._mysql_check_constraints_exist(config)
+
     def _mysql_not_mariadb_102(self, config):
         return against(config, "mysql") and (
             not config.db.dialect._is_mariadb