-
-
Notifications
You must be signed in to change notification settings - Fork 300
Closed
Labels
Milestone
Description
I was using alembic's rewrite feature to ignore comment changes (temporarily, not important for the issue):
@writer.rewrites(ops.AlterColumnOp)
def rewrite_alter_column(context, revision, op):
op.modify_comment = False
if not op.has_changes():
return []
return opthe resulting migration file has many pass lines:
def upgrade():
pass
pass
pass
...It would be nice if alembic wouldn't add unnecessary pass lines.
I found the cause:
alembic/alembic/autogenerate/render.py
Line 117 in d46de05
| return ["pass"] |
I found a workaround by rewriting ModifyTableOps after the first rewriter has finished:
writer1 = Rewriter()
writer2 = Rewriter()
@writer1.rewrites(ops.AlterColumnOp)
def rewrite_alter_column(context, revision, op):
op.modify_comment = False
if not op.has_changes():
return []
return op
@writer2.rewrites(ops.ModifyTableOps)
def rewrite_modify_table_ops(context, revision, op):
if op.is_empty():
return []
return op
writer = writer1.chain(writer2)