"""Add Retriever Model

Revision ID: 3717364e6429
Revises: 7b7b566e667f
Create Date: 2024-10-21 14:22:30.258679

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

# revision identifiers, used by Alembic.
revision = '3717364e6429'
down_revision = '7b7b566e667f'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('retriever',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=50), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('catalog_id', sa.Integer(), nullable=True),
    sa.Column('type', sa.String(length=50), nullable=False),
    sa.Column('user_metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('system_metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('configuration', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
    sa.Column('created_by', sa.Integer(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_by', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['catalog_id'], ['catalog.id'], ),
    sa.ForeignKeyConstraint(['created_by'], ['public.user.id'], ),
    sa.ForeignKeyConstraint(['updated_by'], ['public.user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.drop_column('catalog', 'es_similarity_threshold')
    op.drop_column('catalog', 'es_k')
    op.drop_column('catalog', 'rag_tuning')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('catalog', sa.Column('rag_tuning', sa.BOOLEAN(), autoincrement=False, nullable=True))
    op.add_column('catalog', sa.Column('es_k', sa.INTEGER(), autoincrement=False, nullable=True))
    op.add_column('catalog', sa.Column('es_similarity_threshold', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'catalog', type_='foreignkey')
    op.drop_constraint(None, 'catalog', type_='foreignkey')
    op.create_foreign_key('catalog_updated_by_fkey', 'catalog', 'user', ['updated_by'], ['id'])
    op.create_foreign_key('catalog_created_by_fkey', 'catalog', 'user', ['created_by'], ['id'])
    op.drop_table('retriever')
    # ### end Alembic commands ###
