"""add_session_search_indexes

Revision ID: 11c8abf7ef5b
Revises: 023
Create Date: 2026-02-07 20:48:18.426932

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '11c8abf7ef5b'
down_revision: Union[str, None] = '023'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # Add indexes for session search performance
    # ticket_number and client_name for ILIKE searches
    op.create_index('ix_sessions_ticket_number', 'sessions', ['ticket_number'])
    op.create_index('ix_sessions_client_name', 'sessions', ['client_name'])

    # JSONB GIN index for tree_snapshot to speed up tree name searches
    op.execute("CREATE INDEX ix_sessions_tree_snapshot_gin ON sessions USING gin (tree_snapshot)")


def downgrade() -> None:
    # Drop indexes
    op.drop_index('ix_sessions_ticket_number', table_name='sessions')
    op.drop_index('ix_sessions_client_name', table_name='sessions')
    op.drop_index('ix_sessions_tree_snapshot_gin', table_name='sessions')
