"""add full-text search GIN index on trees

Revision ID: 027
Revises: 026
Create Date: 2026-02-08

Adds a GIN index for full-text search on the trees table,
indexing the name and description columns using English text search.
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


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


def upgrade() -> None:
    op.execute(
        "CREATE INDEX idx_trees_fts ON trees USING GIN ("
        "to_tsvector('english', COALESCE(name, '') || ' ' || COALESCE(description, ''))"
        ")"
    )


def downgrade() -> None:
    op.execute("DROP INDEX IF EXISTS idx_trees_fts")
