diff options
author | Hannes Hansen <hannes.jakob.hansen@cern.ch> | 2019-05-23 16:27:21 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-05-27 16:57:37 -0400 |
commit | c55023641d390b2b09601b10dbc5663e4bd5a466 (patch) | |
tree | 72b58c77440b9247691e298c39f3c97d9b3de480 /test/dialect/mysql/test_compiler.py | |
parent | 90882ed43cce26c069b6696b441b6ad8a7372301 (diff) | |
download | sqlalchemy-c55023641d390b2b09601b10dbc5663e4bd5a466.tar.gz |
MYSQL: added support for drop check/constraint
Added support for DROP CHECK constraint which is required by MySQL 8.0.16
to drop a CHECK constraint; MariaDB supports plain DROP CONSTRAINT. The
logic distinguishes between the two syntaxes by checking the server version
string for MariaDB presence. Alembic migrations has already worked
around this issue by implementing its own DROP for MySQL / MariaDB CHECK
constraints, however this change implements it straight in Core so that its
available for general use. Pull request courtesy Hannes Hansen.
Fixes: #4650
Closes: #4659
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4659
Pull-request-sha: 5b654a55e23c2ca498ca3b1cae4f53859e93e8f7
Change-Id: I967710f890722f11cf1f40406adbb17464d16194
Diffstat (limited to 'test/dialect/mysql/test_compiler.py')
-rw-r--r-- | test/dialect/mysql/test_compiler.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/dialect/mysql/test_compiler.py b/test/dialect/mysql/test_compiler.py index 54767a913..60e11ca29 100644 --- a/test/dialect/mysql/test_compiler.py +++ b/test/dialect/mysql/test_compiler.py @@ -5,6 +5,7 @@ from sqlalchemy import BOOLEAN from sqlalchemy import Boolean from sqlalchemy import cast from sqlalchemy import CHAR +from sqlalchemy import CheckConstraint from sqlalchemy import CLOB from sqlalchemy import Column from sqlalchemy import DATE @@ -128,6 +129,35 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): "CREATE INDEX test_idx2 ON testtbl (data(5))", ) + def test_drop_constraint_mysql(self): + m = MetaData() + table_name = "testtbl" + constraint_name = "constraint" + constraint = CheckConstraint("data IS NOT NULL", name=constraint_name) + tbl = Table(table_name, m, Column("data", String(255)), constraint) + dialect = mysql.dialect() + self.assert_compile( + schema.DropConstraint(constraint), + "ALTER TABLE %s DROP CHECK `%s`" + % (table_name, constraint_name), + dialect=dialect + ) + + def test_drop_constraint_mariadb(self): + m = MetaData() + table_name = "testtbl" + constraint_name = "constraint" + constraint = CheckConstraint("data IS NOT NULL", name=constraint_name) + tbl = Table(table_name, m, Column("data", String(255)), constraint) + dialect = mysql.dialect() + dialect.server_version_info = (10, 1, 1, "MariaDB") + self.assert_compile( + schema.DropConstraint(constraint), + "ALTER TABLE %s DROP CONSTRAINT `%s`" + % (table_name, constraint_name), + dialect=dialect + ) + def test_create_index_with_length_quoted(self): m = MetaData() tbl = Table( |