"""
Alembic migration script template
add_glossaries_tables

Revision ID: cb71a958ad92
Revises: 003_add_revoked_at
Create Date: 2026-02-22 15:13:10.685242

Story 3.9: Glossaires - Endpoint CRUD
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


revision: str = "cb71a958ad92"
down_revision: Union[str, None] = "003_add_revoked_at"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        "glossaries",
        sa.Column("id", sa.String(length=36), nullable=False),
        sa.Column("user_id", sa.String(length=36), nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index("ix_glossaries_user_id", "glossaries", ["user_id"], unique=False)

    op.create_table(
        "glossary_terms",
        sa.Column("id", sa.String(length=36), nullable=False),
        sa.Column("glossary_id", sa.String(length=36), nullable=False),
        sa.Column("source", sa.String(length=500), nullable=False),
        sa.Column("target", sa.String(length=500), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(["glossary_id"], ["glossaries.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        "ix_glossary_terms_glossary_id", "glossary_terms", ["glossary_id"], unique=False
    )


def downgrade() -> None:
    op.drop_index("ix_glossary_terms_glossary_id", table_name="glossary_terms")
    op.drop_table("glossary_terms")
    op.drop_index("ix_glossaries_user_id", table_name="glossaries")
    op.drop_table("glossaries")
