"""Add indexes on duties table for performance.

Revision ID: 008
Revises: 007
Create Date: 2025-02-25

Indexes for get_current_duty, get_next_shift_end, get_duties, get_duties_for_user.
"""

from typing import Sequence, Union

from alembic import op

revision: str = "008"
down_revision: Union[str, None] = "007"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_index(
        "ix_duties_event_type_start_at",
        "duties",
        ["event_type", "start_at"],
        unique=False,
    )
    op.create_index(
        "ix_duties_event_type_end_at",
        "duties",
        ["event_type", "end_at"],
        unique=False,
    )
    op.create_index(
        "ix_duties_user_id_start_at",
        "duties",
        ["user_id", "start_at"],
        unique=False,
    )


def downgrade() -> None:
    op.drop_index("ix_duties_user_id_start_at", table_name="duties")
    op.drop_index("ix_duties_event_type_end_at", table_name="duties")
    op.drop_index("ix_duties_event_type_start_at", table_name="duties")
