"""0002_comments_attachments

Revision ID: ad70fae28d28
Revises: 84b35cbd8fbe
Create Date: 2026-07-19 01:58:50.117077
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


revision: str = 'ad70fae28d28'
down_revision: Union[str, None] = '84b35cbd8fbe'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('comments',
    sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
    sa.Column('parent_type', sa.String(), nullable=False),
    sa.Column('parent_id', sa.UUID(), nullable=False),
    sa.Column('author_id', sa.UUID(), nullable=True),
    sa.Column('acting_node_id', sa.UUID(), nullable=True),
    sa.Column('body', sa.Text(), server_default=sa.text("''"), nullable=False),
    sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('edited_at', sa.TIMESTAMP(timezone=True), nullable=True),
    sa.ForeignKeyConstraint(['acting_node_id'], ['team_nodes.id'], ondelete='SET NULL'),
    sa.ForeignKeyConstraint(['author_id'], ['players.id'], ondelete='SET NULL'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_comments_parent_type_parent_id_created_at', 'comments', ['parent_type', 'parent_id', 'created_at'], unique=False)
    op.create_table('attachments',
    sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
    sa.Column('comment_id', sa.UUID(), nullable=False),
    sa.Column('file_path', sa.String(), nullable=False),
    sa.Column('mime', sa.String(), nullable=False),
    sa.Column('bytes', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.ForeignKeyConstraint(['comment_id'], ['comments.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_attachments_comment_id', 'attachments', ['comment_id'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('ix_attachments_comment_id', table_name='attachments')
    op.drop_table('attachments')
    op.drop_index('ix_comments_parent_type_parent_id_created_at', table_name='comments')
    op.drop_table('comments')
    # ### end Alembic commands ###
