"""Align models with existing database schema

Revision ID: c5e9c4fdd34a
Revises:
Create Date: 2025-08-06 06:10:27.186799

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'c5e9c4fdd34a'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    # Check if the table exists before trying to inspect it
    conn = op.get_bind()
    inspector = sa.inspect(conn)
    
    # Only proceed if the jobs table exists
    if 'jobs' in inspector.get_table_names():
        columns = [col['name'] for col in inspector.get_columns('jobs')]
        
        if 'risk_level' in columns:
            with op.batch_alter_table('jobs', schema=None) as batch_op:
                batch_op.drop_column('risk_level')
    # If table doesn't exist, skip this migration (fresh database)

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    # Check if the table exists before trying to modify it
    conn = op.get_bind()
    inspector = sa.inspect(conn)
    
    if 'jobs' in inspector.get_table_names():
        with op.batch_alter_table('jobs', schema=None) as batch_op:
            batch_op.add_column(sa.Column('risk_level', sa.VARCHAR(length=20), autoincrement=False, nullable=True))
    # ### end Alembic commands ###
