🐛 fix(alembic): add exception handling to prevent migration failure if columns already exist

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-10-18 18:18:07 -03:00
commit a65086c8e4

View file

@ -21,6 +21,7 @@ depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None: def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
try:
with op.batch_alter_table("flow", schema=None) as batch_op: with op.batch_alter_table("flow", schema=None) as batch_op:
batch_op.add_column(sa.Column("is_component", sa.Boolean(), nullable=False)) batch_op.add_column(sa.Column("is_component", sa.Boolean(), nullable=False))
@ -30,16 +31,19 @@ def upgrade() -> None:
"store_api_key", sqlmodel.sql.sqltypes.AutoString(), nullable=True "store_api_key", sqlmodel.sql.sqltypes.AutoString(), nullable=True
) )
) )
except Exception as exc:
pass
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade() -> None: def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
try:
with op.batch_alter_table("user", schema=None) as batch_op: with op.batch_alter_table("user", schema=None) as batch_op:
batch_op.drop_column("store_api_key") batch_op.drop_column("store_api_key")
with op.batch_alter_table("flow", schema=None) as batch_op: with op.batch_alter_table("flow", schema=None) as batch_op:
batch_op.drop_column("is_component") batch_op.drop_column("is_component")
except Exception as exc:
pass
# ### end Alembic commands ### # ### end Alembic commands ###