"""interaction layer + item sections

Revision ID: 83f3bcc8f106
Revises: 0002_trigger_jsonb
Create Date: 2026-08-20 16:00:48.658896

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '83f3bcc8f106'
down_revision: Union[str, Sequence[str], None] = '0002_trigger_jsonb'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('notifications',
    sa.Column('id', sa.String(length=32), nullable=False),
    sa.Column('recipient', sa.String(length=120), nullable=False),
    sa.Column('actor', sa.String(length=120), nullable=False),
    sa.Column('kind', sa.String(length=16), nullable=False),
    sa.Column('context_label', sa.String(length=220), nullable=False),
    sa.Column('body', sa.String(length=200), nullable=False),
    sa.Column('path', sa.String(length=300), nullable=False),
    sa.Column('punchlist_id', sa.String(length=80), nullable=False),
    sa.Column('item_id', sa.String(length=32), nullable=True),
    sa.Column('dedupe_key', sa.String(length=160), nullable=False),
    sa.Column('read', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('dedupe_key', name='uq_notification_dedupe')
    )
    op.create_index(op.f('ix_notifications_recipient'), 'notifications', ['recipient'], unique=False)
    op.create_table('threads',
    sa.Column('id', sa.String(length=32), nullable=False),
    sa.Column('punchlist_id', sa.String(length=80), nullable=False),
    sa.Column('subject_type', sa.String(length=24), nullable=False),
    sa.Column('subject_id', sa.String(length=32), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('subject_type', 'subject_id', name='uq_thread_subject')
    )
    op.create_index(op.f('ix_threads_punchlist_id'), 'threads', ['punchlist_id'], unique=False)
    op.create_table('comments',
    sa.Column('id', sa.String(length=32), nullable=False),
    sa.Column('thread_id', sa.String(length=32), nullable=False),
    sa.Column('author', sa.String(length=120), nullable=False),
    sa.Column('author_kind', sa.String(length=12), nullable=False),
    sa.Column('body', sa.Text(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['thread_id'], ['threads.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_comments_thread_id'), 'comments', ['thread_id'], unique=False)
    op.add_column('items', sa.Column('section', sa.String(length=80), nullable=True))
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('items', 'section')
    op.drop_index(op.f('ix_comments_thread_id'), table_name='comments')
    op.drop_table('comments')
    op.drop_index(op.f('ix_threads_punchlist_id'), table_name='threads')
    op.drop_table('threads')
    op.drop_index(op.f('ix_notifications_recipient'), table_name='notifications')
    op.drop_table('notifications')
    # ### end Alembic commands ###
