"""Update Retriever type_version to 1.0.0

Revision ID: e58835fadd96
Revises: 6857672e8164
Create Date: 2025-02-10 12:20:22.748172

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

# revision identifiers, used by Alembic.
revision = 'e58835fadd96'
down_revision = '6857672e8164'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    connection = op.get_bind()
    table_name = 'retriever'
    try:
        result = connection.execute(
            text(f"""
                            UPDATE {table_name}
                            SET type_version = '1.0.0'
                            WHERE type_version IS NULL OR type_version = ''
                        """)
        )
        print(f"Updated {result.rowcount} rows for type_version in {table_name}")
    except SQLAlchemyError as e:
        print(f"Error updating type_version in {table_name}: {str(e)}")
        raise
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    pass
    # ### end Alembic commands ###
