"""Add trashed file table

Revision ID: add_trashed_file_table
Revises: 6651332488d9
Create Date: 2024-03-19 10:00:00.000000

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import inspect
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'add_trashed_file_table'
down_revision = '6651332488d9'
branch_labels = None
depends_on = None

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    conn = op.get_bind()
    inspector = inspect(conn)
    tables = inspector.get_table_names()
    
    if 'trashed_file' not in tables:
        op.create_table('trashed_file',
            sa.Column('id', sa.Integer(), nullable=False),
            sa.Column('room_id', sa.Integer(), nullable=False),
            sa.Column('name', sa.String(length=255), nullable=False),
            sa.Column('original_path', sa.String(length=255), nullable=False),
            sa.Column('type', sa.String(length=10), nullable=False),
            sa.Column('size', sa.Integer(), nullable=True),
            sa.Column('modified', sa.Float(), nullable=True),
            sa.Column('uploaded_by', sa.Integer(), nullable=True),
            sa.Column('uploaded_at', sa.DateTime(), nullable=True),
            sa.Column('deleted_by', sa.Integer(), nullable=False),
            sa.Column('deleted_at', sa.DateTime(), nullable=False),
            sa.ForeignKeyConstraint(['deleted_by'], ['user.id'], ),
            sa.ForeignKeyConstraint(['room_id'], ['room.id'], ),
            sa.ForeignKeyConstraint(['uploaded_by'], ['user.id'], ),
            sa.PrimaryKeyConstraint('id')
        )
    # ### end Alembic commands ###

def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('trashed_file')
    # ### end Alembic commands ### 