Skip to content

How to use insert_before/insert_after using a rewriter. #1170

Discussion options

You must be logged in to vote

I came up with my own solution for this. We have substantial amount of tables/columns and we adopted alembic to reduce human error so the more we can do programmatically the better. Here is the solution I did, I will also do a pull request sometime for this once I've run it enough.

But here is the code you would put in your env.py.

def _add_column_custom(autogen_context, op):
    kwargs = None
    if op.kw:
        kwargs = [(key, str(value)) for key, value in op.kw.items()]
    schema, tname, column = op.schema, op.table_name, op.column
    if autogen_context._has_batch:
        template = "%(prefix)sadd_column(%(column)s)"

    else:
        template = "%(prefix)sadd_column(%(tname)r, %…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
6 replies
@zzzeek
Comment options

@jtknights08
Comment options

@zzzeek
Comment options

@jtknights08
Comment options

@zzzeek
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by jtknights08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants