"""add missing vector columns Revision ID: 1f4d2a8c9b77 Revises: fb6810c36ffb Create Date: 2026-04-08 22:05:00 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision: str = "1f4d2a8c9b77" down_revision: Union[str, None] = "fb6810c36ffb" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def _table_exists(bind, table_name: str) -> bool: return sa.inspect(bind).has_table(table_name) def _column_exists(bind, table_name: str, column_name: str) -> bool: inspector = sa.inspect(bind) return column_name in {col["name"] for col in inspector.get_columns(table_name)} def upgrade() -> None: bind = op.get_bind() if _table_exists(bind, "vector_indices"): if not _column_exists(bind, "vector_indices", "index_name"): op.add_column( "vector_indices", sa.Column("index_name", sa.String(length=255), nullable=True) ) if not _column_exists(bind, "vector_indices", "checksum"): op.add_column( "vector_indices", sa.Column("checksum", sa.String(length=255), nullable=True) ) if not _column_exists(bind, "vector_indices", "metadata_info"): op.add_column( "vector_indices", sa.Column("metadata_info", sa.JSON(), nullable=True) ) if _table_exists(bind, "vector_chunks"): if not _column_exists(bind, "vector_chunks", "embedding_json"): op.add_column( "vector_chunks", sa.Column("embedding_json", sa.JSON(), nullable=True) ) def downgrade() -> None: bind = op.get_bind() if _table_exists(bind, "vector_chunks"): if _column_exists(bind, "vector_chunks", "embedding_json"): op.drop_column("vector_chunks", "embedding_json") if _table_exists(bind, "vector_indices"): if _column_exists(bind, "vector_indices", "metadata_info"): op.drop_column("vector_indices", "metadata_info") if _column_exists(bind, "vector_indices", "checksum"): op.drop_column("vector_indices", "checksum") if _column_exists(bind, "vector_indices", "index_name"): op.drop_column("vector_indices", "index_name")