"""add_tags_to_extracted_records

Revision ID: 2a19eed6a4b4
Revises: 6302e01e470e
Create Date: 2026-01-20 13:29:08.649755

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '2a19eed6a4b4'
down_revision: Union[str, None] = '6302e01e470e'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # Add tags column to extracted_records table
    op.add_column(
        'extracted_records',
        sa.Column('tags', sa.ARRAY(sa.String()), nullable=True, server_default='{}')
    )

    # Create GIN index for efficient tag filtering
    op.create_index(
        'idx_extracted_records_tags',
        'extracted_records',
        ['tags'],
        unique=False,
        postgresql_using='gin'
    )


def downgrade() -> None:
    # Drop GIN index
    op.drop_index('idx_extracted_records_tags', table_name='extracted_records')

    # Drop tags column
    op.drop_column('extracted_records', 'tags')
