I'm trying to use alembic with a MySQL engine to perform online migrations. I've found that when an operation in my onupgrade() method fails my database gets stuck in an inconsistent state and i can't use alembic until I manually clean up any operations that happened before the failure in onupgrade()
Example:
def upgrade():
op.create_table('sometable',
Column('id', INTEGER, primary_key=True),
Column('name', VARCHAR(150), nullable=False, unique=True))
op.add_column('anothertable' Column('id', INTEGER))
op.create_table('secondtable')
So if I run this and the op.add_column fails, even if I fix the add_column line, now "sometable" exists so the first operation will always fail. I can't run my downgrade script, because alembic never updated the version since it didn't complete the upgrade.
I was thinking if there was a way to force run my ondowngrade(), that might be useful. I'd have to ignore errors, as there are sure to be some. Like dropping "secondtable". I couldn't find anyway to do this though.
Anyone have a good way to handle this?