I have an alembic migration script and I want to add some exception handling but not sure what is the best practice.
Basically, I have several issues to handle:
- A change was already made and not needed (e.g. if I try to add_column, and this column already exists, I want it to continue)
- A table is locked (if I try to perform some operation on a table and it is locked, I want to raise an exception)
other exceptions?
def upgrade(): engine = op.get_bind().engine op.add_column('t_break_employee', sa.Column('auto', sa.Boolean())) op.add_column('t_employee', sa.Column('settings', sa.Text()))
I thought about adding a class to be used with the 'with'
statement on every change. Does it sound reasonable?
for example:
def upgrade():
engine = op.get_bind().engine
with my_test():
op.add_column('t_break_employee', sa.Column('auto', sa.Boolean()))
with my_test():
op.add_column('t_employee', sa.Column('settings', sa.Text()))
In that case, what are the exceptions I need to handle and how do I know if a table is locked?