summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/mysql/base.py
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2020-12-14 16:35:56 +0000
committerGerrit Code Review <gerrit@bbpush.zzzcomputing.com>2020-12-14 16:35:56 +0000
commitaa47eca615eaf8277f6a6365a05539fda1b725e2 (patch)
tree28567a48673024bd80473ff0a62f3f82a4ccc2f3 /lib/sqlalchemy/dialects/mysql/base.py
parent8d3254b6727b306e19dd0db299586b95caa46c9e (diff)
parent0d50b0c7c5b0a9fda4c962f09900e45bebeb1a02 (diff)
downloadsqlalchemy-aa47eca615eaf8277f6a6365a05539fda1b725e2.tar.gz
Merge "Support IF EXISTS/IF NOT EXISTS for DDL constructs"
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index e4cfa79df..911c0d522 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -2036,7 +2036,10 @@ class MySQLDDLCompiler(compiler.DDLCompiler):
if index_prefix:
text += index_prefix + " "
- text += "INDEX %s ON %s " % (name, table)
+ text += "INDEX "
+ if create.if_not_exists:
+ text += "IF NOT EXISTS "
+ text += "%s ON %s " % (name, table)
length = index.dialect_options[self.dialect.name]["length"]
if length is not None:
@@ -2086,8 +2089,11 @@ class MySQLDDLCompiler(compiler.DDLCompiler):
def visit_drop_index(self, drop):
index = drop.element
+ text = "\nDROP INDEX "
+ if drop.if_exists:
+ text += "IF EXISTS "
- return "\nDROP INDEX %s ON %s" % (
+ return text + "%s ON %s" % (
self._prepared_index_name(index, include_schema=False),
self.preparer.format_table(index.table),
)