"""Add template_id column to glossaries table

Revision ID: e1f2a3b4c5d6
Revises: d0e1f2a3b4c5
Create Date: 2026-06-01

Tracks which preset template a glossary was imported from,
enabling duplicate prevention on the import endpoint.
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

# revision identifiers
revision = "e1f2a3b4c5d6"
down_revision = "d0e1f2a3b4c5"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column(
        "glossaries",
        sa.Column("template_id", sa.String(50), nullable=True),
    )
    op.create_index(
        "ix_glossaries_template_id",
        "glossaries",
        ["template_id"],
    )


def downgrade() -> None:
    op.drop_index("ix_glossaries_template_id", table_name="glossaries")
    op.drop_column("glossaries", "template_id")
