"""add file attachment fields to message model

Revision ID: 0f48943140fa
Revises: bd04430cda95
Create Date: 2025-05-26 14:00:05.521776

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import inspect


# revision identifiers, used by Alembic.
revision = '0f48943140fa'
down_revision = 'bd04430cda95'
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('message')]
    
    with op.batch_alter_table('message', schema=None) as batch_op:
        if 'has_attachment' not in columns:
            batch_op.add_column(sa.Column('has_attachment', sa.Boolean(), nullable=True))
        if 'attachment_name' not in columns:
            batch_op.add_column(sa.Column('attachment_name', sa.String(length=255), nullable=True))
        if 'attachment_path' not in columns:
            batch_op.add_column(sa.Column('attachment_path', sa.String(length=512), nullable=True))
        if 'attachment_type' not in columns:
            batch_op.add_column(sa.Column('attachment_type', sa.String(length=100), nullable=True))
        if 'attachment_size' not in columns:
            batch_op.add_column(sa.Column('attachment_size', sa.Integer(), nullable=True))

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    conn = op.get_bind()
    inspector = inspect(conn)
    columns = [col['name'] for col in inspector.get_columns('message')]
    
    with op.batch_alter_table('message', schema=None) as batch_op:
        if 'attachment_size' in columns:
            batch_op.drop_column('attachment_size')
        if 'attachment_type' in columns:
            batch_op.drop_column('attachment_type')
        if 'attachment_path' in columns:
            batch_op.drop_column('attachment_path')
        if 'attachment_name' in columns:
            batch_op.drop_column('attachment_name')
        if 'has_attachment' in columns:
            batch_op.drop_column('has_attachment')

    # ### end Alembic commands ###
