Alembic

Database Tools

忽略一些表

如果在产生自动迁移的时候忽略某些表:https://gist.github.com/utek/6163250

添加列自动产生 MySQL 中需要的 AFTER 值

# in env.py
from sqlalchemy.ext.compiler import compiles
from alembic.ddl.base import AddColumn, alter_table, add_column

@compiles(AddColumn)
def visit_add_column(element, compiler, **kw):
    sql = "%s %s" % (
        alter_table(compiler, element.table_name, element.schema),
        add_column(compiler, element.column, **kw)
    )
    if 'after' in element.column.info:
        sql += ' AFTER `%s`' % element.column.info['after']
    return sql
END

Published @ Aug 15, 2017