"""Add partial index for active job timeouts

Revision ID: 8ffba9132ff0
Revises: 33eff537939b
Create Date: 2026-03-20 23:48:51.929664

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = "8ffba9132ff0"
down_revision: Union[str, Sequence[str], None] = "33eff537939b"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_index(
        "idx_job_active_updated_at",
        "jobs",
        ["status", "updated_at"],
        unique=False,
        postgresql_where=sa.text(
            "status IN ('waiting-file', 'pending', 'running', 'converting')"
        ),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(
        "idx_job_active_updated_at",
        table_name="jobs",
        postgresql_where=sa.text(
            "status IN ('waiting-file', 'pending', 'running', 'converting')"
        ),
    )
    # ### end Alembic commands ###
