From: Mike Bayer Date: Tue, 23 Jan 2018 22:33:49 +0000 (-0500) Subject: Add DROP CONSTRAINT to MySQL for mariadb X-Git-Tag: rel_0_9_8~7^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b34e1c564527450b3a483ab11de04962589fdbb;p=thirdparty%2Fsqlalchemy%2Falembic.git Add DROP CONSTRAINT to MySQL for mariadb 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 --- diff --git a/alembic/ddl/mysql.py b/alembic/ddl/mysql.py index aff7561a..71b186cd 100644 --- a/alembic/ddl/mysql.py +++ b/alembic/ddl/mysql.py @@ -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 index 00000000..feebb891 --- /dev/null +++ b/docs/build/unreleased/479.rst @@ -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. diff --git a/tests/test_mysql.py b/tests/test_mysql.py index ac20f9bc..e7b1cf08 100644 --- a/tests/test_mysql.py +++ b/tests/test_mysql.py @@ -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):