"""Add composite index (run_id, source_hash) for NOT EXISTS dedup

Adds ix_translation_records_run_source_hash on translation_records(run_id, source_hash)
to accelerate the correlated NOT EXISTS subquery in orchestrator_query.get_run_records
when deduplicate=true.

Revision ID: c7d8e9f0a1b2
Revises: a1b2c3d4e5f6
Create Date: 2026-06-04 13:30:00.000000

"""
from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "c7d8e9f0a1b2"
down_revision: str | Sequence[str] | None = "a1b2c3d4e5f6"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Create composite index."""
    op.create_index(
        "ix_translation_records_run_source_hash",
        "translation_records",
        ["run_id", "source_hash"],
        postgresql_using="btree",
    )


def downgrade() -> None:
    """Drop composite index."""
    op.drop_index("ix_translation_records_run_source_hash",
                  table_name="translation_records")
