"""add analysis model and investigation relationship

Revision ID: fa0ab51b2f64
Revises: 76f5436251e3
Create Date: 2025-06-04 11:15:03.736931

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'fa0ab51b2f64'
down_revision: Union[str, None] = '76f5436251e3'
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('analyses',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('title', sa.Text(), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('content', sa.JSON(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('last_updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('owner_id', sa.UUID(), nullable=True),
    sa.Column('investigation_id', sa.UUID(), nullable=True),
    sa.ForeignKeyConstraint(['investigation_id'], ['investigations.id'], onupdate='CASCADE', ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['owner_id'], ['profiles.id'], onupdate='CASCADE', ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_analyses_investigation_id', 'analyses', ['investigation_id'], unique=False)
    op.create_index('idx_analyses_owner_id', 'analyses', ['owner_id'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('idx_analyses_owner_id', table_name='analyses')
    op.drop_index('idx_analyses_investigation_id', table_name='analyses')
    op.drop_table('analyses')
    # ### end Alembic commands ###
