"""Embeddings according to pgvector decision

Revision ID: f5bbaed3a9ee
Revises: 83b4a2aedbf1
Create Date: 2024-04-30 10:57:48.310528

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

# revision identifiers, used by Alembic.
revision = 'f5bbaed3a9ee'
down_revision = '83b4a2aedbf1'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('embedding_mistral',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('doc_vers_id', sa.Integer(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('embedding', pgvector.sqlalchemy.Vector(dim=1024), nullable=False),
    sa.ForeignKeyConstraint(['doc_vers_id'], ['document_version.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('document_language', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
    op.add_column('document_language', sa.Column('updated_by', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'document_language', 'user', ['updated_by'], ['id'], referent_schema='public')
    op.add_column('document_version', sa.Column('file_location', sa.String(length=255), nullable=True))
    op.add_column('document_version', sa.Column('file_name', sa.String(length=200), nullable=True))
    op.add_column('document_version', sa.Column('file_type', sa.String(length=20), nullable=True))
    op.add_column('document_version', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False))
    op.add_column('document_version', sa.Column('updated_by', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'document_version', 'user', ['updated_by'], ['id'], referent_schema='public')
    op.drop_column('document_version', 'embeddings')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('document_version', sa.Column('embeddings', postgresql.BYTEA(), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'document_version', type_='foreignkey')
    op.drop_column('document_version', 'updated_by')
    op.drop_column('document_version', 'updated_at')
    op.drop_column('document_version', 'file_type')
    op.drop_column('document_version', 'file_name')
    op.drop_column('document_version', 'file_location')
    op.drop_constraint(None, 'document_language', type_='foreignkey')
    op.drop_column('document_language', 'updated_by')
    op.drop_column('document_language', 'updated_at')
    op.drop_table('embedding_mistral')
    # ### end Alembic commands ###
