88 lines
4.1 KiB
Python
88 lines
4.1 KiB
Python
"""add version tracking fields to instances
|
|
|
|
Revision ID: c94c2b2b9f2e
|
|
Revises: a1fd98e6630d
|
|
Create Date: 2025-06-23 09:15:13.092801
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = 'c94c2b2b9f2e'
|
|
down_revision = 'a1fd98e6630d'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.drop_table('email_template')
|
|
op.drop_table('notification')
|
|
|
|
# Check if columns already exist before adding them
|
|
connection = op.get_bind()
|
|
inspector = sa.inspect(connection)
|
|
existing_columns = [col['name'] for col in inspector.get_columns('instances')]
|
|
|
|
with op.batch_alter_table('instances', schema=None) as batch_op:
|
|
if 'deployed_version' not in existing_columns:
|
|
batch_op.add_column(sa.Column('deployed_version', sa.String(length=50), nullable=True))
|
|
if 'deployed_branch' not in existing_columns:
|
|
batch_op.add_column(sa.Column('deployed_branch', sa.String(length=100), nullable=True))
|
|
if 'latest_version' not in existing_columns:
|
|
batch_op.add_column(sa.Column('latest_version', sa.String(length=50), nullable=True))
|
|
if 'version_checked_at' not in existing_columns:
|
|
batch_op.add_column(sa.Column('version_checked_at', sa.DateTime(), nullable=True))
|
|
|
|
with op.batch_alter_table('room_file', schema=None) as batch_op:
|
|
batch_op.drop_constraint(batch_op.f('fk_room_file_deleted_by_user'), type_='foreignkey')
|
|
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade():
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
with op.batch_alter_table('room_file', schema=None) as batch_op:
|
|
batch_op.create_foreign_key(batch_op.f('fk_room_file_deleted_by_user'), 'user', ['deleted_by'], ['id'])
|
|
|
|
# Check if columns exist before dropping them
|
|
connection = op.get_bind()
|
|
inspector = sa.inspect(connection)
|
|
existing_columns = [col['name'] for col in inspector.get_columns('instances')]
|
|
|
|
with op.batch_alter_table('instances', schema=None) as batch_op:
|
|
if 'version_checked_at' in existing_columns:
|
|
batch_op.drop_column('version_checked_at')
|
|
if 'latest_version' in existing_columns:
|
|
batch_op.drop_column('latest_version')
|
|
if 'deployed_branch' in existing_columns:
|
|
batch_op.drop_column('deployed_branch')
|
|
if 'deployed_version' in existing_columns:
|
|
batch_op.drop_column('deployed_version')
|
|
|
|
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=200), 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('read', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False),
|
|
sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
|
|
sa.Column('updated_at', postgresql.TIMESTAMP(), 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.create_table('email_template',
|
|
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
|
|
sa.Column('name', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
|
|
sa.Column('subject', sa.VARCHAR(length=200), autoincrement=False, nullable=False),
|
|
sa.Column('body', sa.TEXT(), autoincrement=False, nullable=False),
|
|
sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
|
|
sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
|
|
sa.PrimaryKeyConstraint('id', name=op.f('email_template_pkey')),
|
|
sa.UniqueConstraint('name', name=op.f('email_template_name_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
|
|
)
|
|
# ### end Alembic commands ###
|