From: Mike Bayer Date: Wed, 21 Mar 2018 13:21:58 +0000 (-0400) Subject: Ensure CHECK constraint name is quoted for MySQL X-Git-Tag: rel_0_9_9~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=533c965f253bdb80b3c4b129c4c8ecabaacb070a;p=thirdparty%2Fsqlalchemy%2Falembic.git Ensure CHECK constraint name is quoted for MySQL Change-Id: Ib85de299c5f3c2631c64fe30006879ba274fca15 Fixes: #487 --- diff --git a/alembic/ddl/mysql.py b/alembic/ddl/mysql.py index 32e67ee3..1f4b345a 100644 --- a/alembic/ddl/mysql.py +++ b/alembic/ddl/mysql.py @@ -342,7 +342,8 @@ def _mysql_drop_constraint(element, compiler, **kw): # 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) + (compiler.preparer.format_table(constraint.table), + compiler.preparer.format_constraint(constraint)) else: raise NotImplementedError( "No generic 'DROP CONSTRAINT' in MySQL - " diff --git a/docs/build/unreleased/487.rst b/docs/build/unreleased/487.rst new file mode 100644 index 00000000..273edf20 --- /dev/null +++ b/docs/build/unreleased/487.rst @@ -0,0 +1,6 @@ +.. change:: + :tags: bug, operations, mysql + :tickets: 487 + + Fixed bug in ``op.drop_constraint()`` for MySQL where + quoting rules would not be applied to the constraint name. diff --git a/tests/test_mysql.py b/tests/test_mysql.py index 321488fa..dd872f7f 100644 --- a/tests/test_mysql.py +++ b/tests/test_mysql.py @@ -174,6 +174,13 @@ class MySQLOpTest(TestBase): "ALTER TABLE t1 DROP FOREIGN KEY f1" ) + def test_drop_fk_quoted(self): + context = op_fixture('mysql') + op.drop_constraint("MyFk", "MyTable", "foreignkey") + context.assert_( + "ALTER TABLE `MyTable` DROP FOREIGN KEY `MyFk`" + ) + def test_drop_constraint_primary(self): context = op_fixture('mysql') op.drop_constraint('primary', 't1', type_='primary') @@ -188,6 +195,13 @@ class MySQLOpTest(TestBase): "ALTER TABLE t1 DROP INDEX f1" ) + def test_drop_unique_quoted(self): + context = op_fixture('mysql') + op.drop_constraint("MyUnique", "MyTable", "unique") + context.assert_( + "ALTER TABLE `MyTable` DROP INDEX `MyUnique`" + ) + def test_drop_check(self): context = op_fixture('mysql') op.drop_constraint("f1", "t1", "check") @@ -195,6 +209,13 @@ class MySQLOpTest(TestBase): "ALTER TABLE t1 DROP CONSTRAINT f1" ) + def test_drop_check_quoted(self): + context = op_fixture('mysql') + op.drop_constraint("MyCheck", "MyTable", "check") + context.assert_( + "ALTER TABLE `MyTable` DROP CONSTRAINT `MyCheck`" + ) + def test_drop_unknown(self): op_fixture('mysql') assert_raises_message(