"""initial_notes_and_tickets

Revision ID: 485d40e86e4b
Revises: 
Create Date: 2026-04-15 20:01:04.225959

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '485d40e86e4b'
down_revision: Union[str, None] = None
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('entries',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('type', sa.String(length=10), nullable=False),
    sa.Column('title', sa.String(length=500), nullable=False),
    sa.Column('body', sa.Text(), nullable=True),
    sa.Column('status', sa.String(length=20), nullable=True),
    sa.Column('severity', sa.String(length=10), nullable=True),
    sa.Column('author_id', sa.String(length=128), nullable=False),
    sa.Column('author_name', sa.String(length=255), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('entry_links',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('entry_id', sa.UUID(), nullable=False),
    sa.Column('entity_type', sa.String(length=20), nullable=False),
    sa.Column('entity_id', sa.String(length=128), nullable=False),
    sa.ForeignKeyConstraint(['entry_id'], ['entries.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('entry_id', 'entity_type', 'entity_id')
    )
    op.create_table('support_tickets',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('customer_id', sa.String(length=128), nullable=False),
    sa.Column('customer_name', sa.String(length=255), nullable=True),
    sa.Column('device_id', sa.String(length=128), nullable=True),
    sa.Column('device_serial', sa.String(length=64), nullable=True),
    sa.Column('subject', sa.String(length=500), nullable=False),
    sa.Column('status', sa.String(length=30), nullable=False),
    sa.Column('priority', sa.String(length=10), nullable=True),
    sa.Column('opened_via', sa.String(length=20), nullable=True),
    sa.Column('linked_entry_id', sa.UUID(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['linked_entry_id'], ['entries.id'], ondelete='SET NULL'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('ticket_messages',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('ticket_id', sa.UUID(), nullable=False),
    sa.Column('sender_type', sa.String(length=10), nullable=False),
    sa.Column('sender_id', sa.String(length=128), nullable=False),
    sa.Column('sender_name', sa.String(length=255), nullable=True),
    sa.Column('body', sa.Text(), nullable=False),
    sa.Column('is_internal', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['ticket_id'], ['support_tickets.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('ticket_messages')
    op.drop_table('support_tickets')
    op.drop_table('entry_links')
    op.drop_table('entries')
    # ### end Alembic commands ###
