from .. import util
from ..autogenerate import compare
from ..util.compat import string_types
+from ..util.sqla_compat import _is_mariadb
from ..util.sqla_compat import _is_type_bound
from ..util.sqla_compat import sqla_100
):
return False
elif inspector_column.type._type_affinity is sqltypes.Integer:
- rendered_inspector_default = re.sub(
- r"^'|'$", "", rendered_inspector_default
- ) if rendered_inspector_default is not None else None
+ rendered_inspector_default = (
+ re.sub(r"^'|'$", "", rendered_inspector_default)
+ if rendered_inspector_default is not None
+ else None
+ )
return rendered_inspector_default != rendered_metadata_default
elif rendered_inspector_default and rendered_metadata_default:
# adjust for "function()" vs. "FUNCTION"
# 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),
- compiler.preparer.format_constraint(constraint),
- )
+ if _is_mariadb(compiler.dialect):
+ return "ALTER TABLE %s DROP CONSTRAINT %s" % (
+ compiler.preparer.format_table(constraint.table),
+ compiler.preparer.format_constraint(constraint),
+ )
+ else:
+ return "ALTER TABLE %s DROP CHECK %s" % (
+ compiler.preparer.format_table(constraint.table),
+ compiler.preparer.format_constraint(constraint),
+ )
else:
raise NotImplementedError(
"No generic 'DROP CONSTRAINT' in MySQL - "
opts["as_sql"] = as_sql
if literal_binds:
opts["literal_binds"] = literal_binds
- ctx_dialect = _get_dialect(dialect)
+ if dialect == "mariadb":
+ ctx_dialect = _get_dialect("mysql")
+ ctx_dialect.server_version_info = (10, 0, 0, "MariaDB")
+
+ else:
+ ctx_dialect = _get_dialect(dialect)
if native_boolean is not None:
ctx_dialect.supports_native_boolean = native_boolean
# this is new as of SQLAlchemy 1.2.7 and is used by SQL Server,
def _is_mariadb(mysql_dialect):
- return "MariaDB" in mysql_dialect.server_version_info
+ return (
+ mysql_dialect.server_version_info
+ and "MariaDB" in mysql_dialect.server_version_info
+ )
def _mariadb_normalized_version_info(mysql_dialect):
--- /dev/null
+.. change::
+ :tags: bug, mysql
+ :tickets: 554
+
+ Added support for MySQL "DROP CHECK", which is added as of MySQL 8.0.16,
+ separate from MariaDB's "DROP CONSTRAINT" for CHECK constraints. The MySQL
+ Alembic implementation now checks for "MariaDB" in server_version_info to
+ decide which one to use.
+
+
op.drop_constraint("MyUnique", "MyTable", "unique")
context.assert_("ALTER TABLE `MyTable` DROP INDEX `MyUnique`")
- def test_drop_check(self):
- context = op_fixture("mysql")
+ def test_drop_check_mariadb(self):
+ context = op_fixture("mariadb")
op.drop_constraint("f1", "t1", "check")
context.assert_("ALTER TABLE t1 DROP CONSTRAINT f1")
- def test_drop_check_quoted(self):
- context = op_fixture("mysql")
+ def test_drop_check_quoted_mariadb(self):
+ context = op_fixture("mariadb")
op.drop_constraint("MyCheck", "MyTable", "check")
context.assert_("ALTER TABLE `MyTable` DROP CONSTRAINT `MyCheck`")
+ def test_drop_check_mysql(self):
+ context = op_fixture("mysql")
+ op.drop_constraint("f1", "t1", "check")
+ context.assert_("ALTER TABLE t1 DROP CHECK f1")
+
+ def test_drop_check_quoted_mysql(self):
+ context = op_fixture("mysql")
+ op.drop_constraint("MyCheck", "MyTable", "check")
+ context.assert_("ALTER TABLE `MyTable` DROP CHECK `MyCheck`")
+
def test_drop_unknown(self):
op_fixture("mysql")
assert_raises_message(