"""Added RFP and QNA tables

Revision ID: 9b8000cad5e7
Revises: 04c9051208cd
Create Date: 2026-02-04 14:46:32.932514

"""
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 = '9b8000cad5e7'
down_revision: Union[str, Sequence[str], None] = '04c9051208cd'
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('rfp',
    sa.Column('uploaded_by_contact_id', sa.Integer(), nullable=True),
    sa.Column('profile_id', sa.Integer(), nullable=True),
    sa.Column('s3_url', sa.String(length=2048), nullable=True),
    sa.Column('enterprise_name', sa.String(length=255), nullable=True),
    sa.Column('additional_data', sa.JSON(), nullable=True),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
    sa.ForeignKeyConstraint(['profile_id'], ['profile.id'], name=op.f('rfp_profile_id_fkey'), ondelete='SET NULL'),
    sa.ForeignKeyConstraint(['uploaded_by_contact_id'], ['contact.id'], name=op.f('rfp_uploaded_by_contact_id_fkey'), ondelete='SET NULL'),
    sa.PrimaryKeyConstraint('id', name=op.f('rfp_pkey'))
    )
    op.create_index(op.f('rfp_id_idx'), 'rfp', ['id'], unique=False)
    op.create_index(op.f('rfp_profile_id_idx'), 'rfp', ['profile_id'], unique=False)
    op.create_index(op.f('rfp_uploaded_by_contact_id_idx'), 'rfp', ['uploaded_by_contact_id'], unique=False)
    op.create_table('rfpqna',
    sa.Column('rfp_id', sa.Integer(), nullable=False),
    sa.Column('question', sa.Text(), nullable=False),
    sa.Column('answer', sa.Text(), nullable=True),
    sa.Column('confidence', sa.String(length=50), nullable=True),
    sa.Column('citations', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('raw_llm_response', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
    sa.ForeignKeyConstraint(['rfp_id'], ['rfp.id'], name=op.f('rfpqna_rfp_id_fkey'), ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id', name=op.f('rfpqna_pkey'))
    )
    op.create_index(op.f('rfpqna_id_idx'), 'rfpqna', ['id'], unique=False)
    op.create_index(op.f('rfpqna_rfp_id_idx'), 'rfpqna', ['rfp_id'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('rfpqna_rfp_id_idx'), table_name='rfpqna')
    op.drop_index(op.f('rfpqna_id_idx'), table_name='rfpqna')
    op.drop_table('rfpqna')
    op.drop_index(op.f('rfp_uploaded_by_contact_id_idx'), table_name='rfp')
    op.drop_index(op.f('rfp_profile_id_idx'), table_name='rfp')
    op.drop_index(op.f('rfp_id_idx'), table_name='rfp')
    op.drop_table('rfp')
    # ### end Alembic commands ###
