"""T_B0 chapter_injection override table

Revision ID: ad2c4c663daf
Revises: 1f011c42bd4d
Create Date: 2026-06-20 11:51:00.494169
"""

from __future__ import annotations

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

revision: str = "ad2c4c663daf"
down_revision: str | None = "1f011c42bd4d"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "chapter_injection",
        sa.Column("project_id", sa.Uuid(), nullable=False),
        sa.Column("chapter_no", sa.Integer(), nullable=False),
        sa.Column(
            "pinned",
            postgresql.JSONB(astext_type=sa.Text()),
            server_default=sa.text("'[]'"),
            nullable=False,
        ),
        sa.Column(
            "excluded",
            postgresql.JSONB(astext_type=sa.Text()),
            server_default=sa.text("'[]'"),
            nullable=False,
        ),
        sa.Column("recent_n", sa.Integer(), nullable=True),
        sa.Column("id", sa.Uuid(), server_default=sa.text("gen_random_uuid()"), nullable=False),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False),
        sa.ForeignKeyConstraint(["project_id"], ["projects.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("project_id", "chapter_no"),
    )
    op.create_index(
        op.f("ix_chapter_injection_project_id"), "chapter_injection", ["project_id"], unique=False
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_chapter_injection_project_id"), table_name="chapter_injection")
    op.drop_table("chapter_injection")
    # ### end Alembic commands ###
