"""add session_scores table

Revision ID: 1b151bbba793
Revises: 7ccbb500ad9c
Create Date: 2026-03-11 14:09:23.909242
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = '1b151bbba793'
down_revision: Union[str, None] = '7ccbb500ad9c'
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('session_scores',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('session_id', sa.String(length=255), nullable=False),
    sa.Column('project_id', sa.UUID(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('data_type', sa.Enum('NUMERIC', 'BOOLEAN', 'CATEGORICAL', name='score_data_type', native_enum=False, length=20), nullable=False),
    sa.Column('value', sa.String(length=255), nullable=True),
    sa.Column('source', sa.Enum('AUTOMATED', 'ANNOTATION', 'PROGRAMMATIC', name='score_source', native_enum=False, length=20), nullable=False),
    sa.Column('status', sa.Enum('SUCCESS', 'FAILED', 'PENDING', name='score_status', native_enum=False, length=20), nullable=False),
    sa.Column('eval_run_id', sa.UUID(), nullable=True),
    sa.Column('author_user_id', sa.String(length=255), nullable=True),
    sa.Column('reason', sa.Text(), nullable=True),
    sa.Column('environment', sa.String(length=255), nullable=True),
    sa.Column('config_id', sa.String(length=255), nullable=True),
    sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['eval_run_id'], ['eval_runs.id'], ondelete='SET NULL'),
    sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_session_scores_eval_run', 'session_scores', ['eval_run_id'], unique=False)
    op.create_index('ix_session_scores_project_name', 'session_scores', ['project_id', 'name', 'created_at'], unique=False)
    op.create_index('ix_session_scores_project_session', 'session_scores', ['project_id', 'session_id'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('ix_session_scores_project_session', table_name='session_scores')
    op.drop_index('ix_session_scores_project_name', table_name='session_scores')
    op.drop_index('ix_session_scores_eval_run', table_name='session_scores')
    op.drop_table('session_scores')
    # ### end Alembic commands ###
