summaryrefslogtreecommitdiff
path: root/alembic/autogenerate
diff options
context:
space:
mode:
authorJet Zhou <jet@gem.com>2021-05-27 14:26:51 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-05-27 14:31:32 -0400
commite799e42f18f6f84ee2bca9618719b4cf7ba895ee (patch)
treeaa02faba6d163a016a24d8d4c30d9fee1a84d5da /alembic/autogenerate
parent9c73d0a95788c3a067a74524216a816bf3d77fbd (diff)
downloadalembic-e799e42f18f6f84ee2bca9618719b4cf7ba895ee.tar.gz
Add kwargs support to DropIndexOp autogenerate render
Fixed issue where dialect-specific keyword arguments within the :class:`.DropIndex` operation directive would not render in the autogenerated Python code. As support was improved for adding dialect specific arguments to directives as part of :ticket:`803`, in particular arguments such as "postgresql_concurrently" which apply to the actual create/drop of the index, support was needed for these to render even in a drop index operation. Pull request courtesy Jet Zhou. Fixes: #849 Closes: #852 Pull-request: https://github.com/sqlalchemy/alembic/pull/852 Pull-request-sha: 6392a287179ed746f709ba1e0e07ccab3ea8e4c6 Change-Id: I9b602178c32d6c6a41c0dbe0969a19bd4fa329bd
Diffstat (limited to 'alembic/autogenerate')
-rw-r--r--alembic/autogenerate/render.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/alembic/autogenerate/render.py b/alembic/autogenerate/render.py
index 58b469c..79d0261 100644
--- a/alembic/autogenerate/render.py
+++ b/alembic/autogenerate/render.py
@@ -272,14 +272,16 @@ def _add_index(autogen_context, op):
@renderers.dispatch_for(ops.DropIndexOp)
def _drop_index(autogen_context, op):
+ index = op.to_index()
+
has_batch = autogen_context._has_batch
if has_batch:
- tmpl = "%(prefix)sdrop_index(%(name)r)"
+ tmpl = "%(prefix)sdrop_index(%(name)r%(kwargs)s)"
else:
tmpl = (
"%(prefix)sdrop_index(%(name)r, "
- "table_name=%(table_name)r%(schema)s)"
+ "table_name=%(table_name)r%(schema)s%(kwargs)s)"
)
text = tmpl % {
@@ -287,6 +289,18 @@ def _drop_index(autogen_context, op):
"name": _render_gen_name(autogen_context, op.index_name),
"table_name": _ident(op.table_name),
"schema": ((", schema=%r" % _ident(op.schema)) if op.schema else ""),
+ "kwargs": (
+ ", "
+ + ", ".join(
+ [
+ "%s=%s"
+ % (key, _render_potential_expr(val, autogen_context))
+ for key, val in index.kwargs.items()
+ ]
+ )
+ )
+ if len(index.kwargs)
+ else "",
}
return text