"""Add ColorSettings table

Revision ID: ca9026520dad
Revises: 76da0573e84b
Create Date: 2025-05-25 21:08:37.158900

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

# revision identifiers, used by Alembic.
revision = 'ca9026520dad'
down_revision = '76da0573e84b'
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 'color_settings' not in tables:
        op.create_table('color_settings',
            sa.Column('id', sa.Integer(), nullable=False),
            sa.Column('primary_color', sa.String(length=7), nullable=True),
            sa.Column('secondary_color', sa.String(length=7), nullable=True),
            sa.Column('updated_at', sa.DateTime(), nullable=True),
            sa.PrimaryKeyConstraint('id')
        )
    with op.batch_alter_table('room_file', schema=None) as batch_op:
        batch_op.alter_column('deleted',
               existing_type=sa.BOOLEAN(),
               nullable=True,
               existing_server_default=sa.text('false'))

    with op.batch_alter_table('trashed_file', schema=None) as batch_op:
        batch_op.alter_column('deleted_at',
               existing_type=postgresql.TIMESTAMP(),
               nullable=True)

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('trashed_file', schema=None) as batch_op:
        batch_op.alter_column('deleted_at',
               existing_type=postgresql.TIMESTAMP(),
               nullable=False)

    with op.batch_alter_table('room_file', schema=None) as batch_op:
        batch_op.alter_column('deleted',
               existing_type=sa.BOOLEAN(),
               nullable=False,
               existing_server_default=sa.text('false'))

    op.drop_table('color_settings')
    # ### end Alembic commands ### 