"""Drop deprecated source_language column from translation_jobs

Revision ID: 8dd0a93af539
Revises: 543d43d752b8
Create Date: 2026-05-14 23:43:32.216941

"""
from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = '8dd0a93af539'
down_revision: str | Sequence[str] | None = '543d43d752b8'
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Upgrade schema."""
    # Use DROP COLUMN IF EXISTS for PostgreSQL safety (column may not exist on all environments)
    # SQLite does not support IF EXISTS, but op.drop_column works when column exists
    bind = op.get_bind()
    if bind.engine.name == "sqlite":
        # SQLite: drop only if column exists
        inspector = sa.inspect(bind)
        columns = [c["name"] for c in inspector.get_columns("translation_jobs")]
        if "source_language" in columns:
            op.drop_column("translation_jobs", "source_language")
    else:
        # PostgreSQL and others: use IF EXISTS
        op.execute("ALTER TABLE translation_jobs DROP COLUMN IF EXISTS source_language")


def downgrade() -> None:
    """Downgrade schema."""
    op.add_column("translation_jobs", sa.Column("source_language", sa.VARCHAR(), nullable=True))
