{%- if cookiecutter.include_example_crud %}
"""create items table (example CRUD scaffold)

Revision ID: 0021_create_items
Revises: 0018_user_slash_commands
Create Date: 2026-05-10T00:00:00+00:00

Reference scaffold generated by --example-resource. Demonstrates the standard
layered pattern (model → repo → service → route). Replace or delete this
migration when you rename or remove the Item domain.
"""

import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import UUID as PG_UUID

from alembic import op

revision = "0021_create_items"
{%- if cookiecutter.use_external_user_id_in_conversations %}
down_revision = "0020_conv_external_user_id"
{%- elif cookiecutter.use_delegated_auth %}
down_revision = "0019_user_external_id"
{%- else %}
down_revision = "0018_user_slash_commands"
{%- endif %}
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        "items",
        sa.Column(
            "id",
            PG_UUID(as_uuid=True),
            primary_key=True,
            server_default=sa.text("gen_random_uuid()"),
        ),
        sa.Column(
            "owner_id",
            PG_UUID(as_uuid=True),
            sa.ForeignKey("users.id", ondelete="CASCADE"),
            nullable=False,
        ),
        sa.Column("name", sa.String(255), nullable=False),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("is_published", sa.Boolean(), nullable=False, server_default=sa.false()),
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.func.now(),
            nullable=False,
        ),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True),
    )
    op.create_index("ix_items_owner_id", "items", ["owner_id"])


def downgrade() -> None:
    op.drop_index("ix_items_owner_id", table_name="items")
    op.drop_table("items")
{%- endif %}
