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,23 +19,23 @@ depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
conn = op.get_bind()
inspector = inspect(conn)
tables = inspector.get_table_names()
if 'email_templates' not in tables:
op.create_table('email_templates',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('subject', sa.String(length=200), nullable=False),
sa.Column('body', sa.Text(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('created_by', sa.Integer(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['created_by'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('subject', sa.String(length=200), nullable=False),
sa.Column('body', sa.Text(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('created_by', sa.Integer(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['created_by'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.drop_table('notification')
with op.batch_alter_table('events', schema=None) as batch_op:
batch_op.alter_column('details',
@@ -60,22 +60,22 @@ def downgrade():
type_=postgresql.JSONB(astext_type=sa.Text()),
existing_nullable=True)
conn = op.get_bind()
conn = op.get_bind()
inspector = inspect(conn)
tables = inspector.get_table_names()
if 'notification' not in tables:
op.create_table('notification',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('title', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
sa.Column('message', sa.TEXT(), autoincrement=False, nullable=False),
sa.Column('type', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
sa.Column('is_read', sa.BOOLEAN(), autoincrement=False, nullable=True),
sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.Column('link', sa.VARCHAR(length=512), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('notification_user_id_fkey')),
sa.PrimaryKeyConstraint('id', name=op.f('notification_pkey'))
)
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('title', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
sa.Column('message', sa.TEXT(), autoincrement=False, nullable=False),
sa.Column('type', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
sa.Column('is_read', sa.BOOLEAN(), autoincrement=False, nullable=True),
sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.Column('link', sa.VARCHAR(length=512), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('notification_user_id_fkey')),
sa.PrimaryKeyConstraint('id', name=op.f('notification_pkey'))
)
op.drop_table('email_templates')
# ### end Alembic commands ###
# ### end Alembic commands ###