more robust migrations

This commit is contained in:
2025-06-02 18:58:48 +02:00
parent 4dbaa27cba
commit 5c6c3f436e
51 changed files with 401 additions and 273 deletions

View File

@@ -19,11 +19,14 @@ depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('contact')
conn = op.get_bind()
inspector = inspect(conn)
tables = inspector.get_table_names()
columns = [col['name'] for col in inspector.get_columns('user')]
if 'contact' in tables:
op.drop_table('contact')
with op.batch_alter_table('user', schema=None) as batch_op:
if 'profile_picture' not in columns:
batch_op.add_column(sa.Column('profile_picture', sa.String(length=255), nullable=True))
@@ -33,8 +36,13 @@ def upgrade():
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('user')]
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('profile_picture')
if 'profile_picture' in columns:
batch_op.drop_column('profile_picture')
op.create_table('contact',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),