"""Add deleted_by column to room_file table Revision ID: add_deleted_by_to_room_file Revises: add_deleted_column_to_room_file Create Date: 2024-03-19 10:45:00.000000 """ from alembic import op import sqlalchemy as sa from sqlalchemy import inspect # revision identifiers, used by Alembic. revision = 'add_deleted_by_to_room_file' down_revision = 'add_deleted_column_to_room_file' branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### conn = op.get_bind() inspector = inspect(conn) columns = [col['name'] for col in inspector.get_columns('room_file')] with op.batch_alter_table('room_file', schema=None) as batch_op: if 'deleted_by' not in columns: batch_op.add_column(sa.Column('deleted_by', sa.Integer(), nullable=True)) if 'deleted_at' not in columns: batch_op.add_column(sa.Column('deleted_at', sa.DateTime(), nullable=True)) batch_op.create_foreign_key('fk_room_file_deleted_by_user', 'user', ['deleted_by'], ['id']) # ### 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.drop_constraint('fk_room_file_deleted_by_user', type_='foreignkey') batch_op.drop_column('deleted_at') batch_op.drop_column('deleted_by') # ### end Alembic commands ###