]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Add DROP CONSTRAINT to MySQL for mariadb
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 23 Jan 2018 22:33:49 +0000 (17:33 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 23 Jan 2018 22:39:23 +0000 (17:39 -0500)
Added support for DROP CONSTRAINT to the MySQL Alembic
dialect to support MariaDB 10.2 which now has real
CHECK constraints.  Note this change does **not**
add autogenerate support, only support for op.drop_constraint()
to work.

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

index aff7561a56e90d5066d515a198e16158577bd538..71b186cd75f344fd7c86d450737a97c5643142da 100644 (file)
@@ -333,8 +333,11 @@ def _mysql_drop_constraint(element, compiler, **kw):
                   ):
         return compiler.visit_drop_constraint(element, **kw)
     elif isinstance(constraint, schema.CheckConstraint):
-        raise NotImplementedError(
-            "MySQL does not support CHECK constraints.")
+        # note that SQLAlchemy as of 1.2 does not yet support
+        # DROP CONSTRAINT for MySQL/MariaDB, so we implement fully
+        # here.
+        return "ALTER TABLE %s DROP CONSTRAINT %s" % \
+            (compiler.preparer.format_table(constraint.table), constraint.name)
     else:
         raise NotImplementedError(
             "No generic 'DROP CONSTRAINT' in MySQL - "
diff --git a/docs/build/unreleased/479.rst b/docs/build/unreleased/479.rst
new file mode 100644 (file)
index 0000000..feebb89
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, mysql
+    :tickets: 479
+
+    Added support for DROP CONSTRAINT to the MySQL Alembic
+    dialect to support MariaDB 10.2 which now has real
+    CHECK constraints.  Note this change does **not**
+    add autogenerate support, only support for op.drop_constraint()
+    to work.
index ac20f9bcaba59047964e98d1814f8c5c3cd7791f..e7b1cf08c32d93c27d1571fa53dc891ff167b792 100644 (file)
@@ -189,11 +189,10 @@ class MySQLOpTest(TestBase):
         )
 
     def test_drop_check(self):
-        op_fixture('mysql')
-        assert_raises_message(
-            NotImplementedError,
-            "MySQL does not support CHECK constraints.",
-            op.drop_constraint, "f1", "t1", "check"
+        context = op_fixture('mysql')
+        op.drop_constraint("f1", "t1", "check")
+        context.assert_(
+            "ALTER TABLE t1 DROP CONSTRAINT f1"
         )
 
     def test_drop_unknown(self):