Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bluethon/219be51d7c2bffa1ffd916509374d072 to your computer and use it in GitHub Desktop.
Save bluethon/219be51d7c2bffa1ffd916509374d072 to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment