fix: ensure pgvector installed before running alembic migrations (#109)

* fix: ensure pgvector installed before running alembic migrations

* fix: include extensions in search path
This commit is contained in:
doria 2025-05-15 10:45:14 -04:00 committed by GitHub
parent 1b54b4703b
commit 5a2fcfed7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View File

@ -107,8 +107,12 @@ def run_migrations_online() -> None:
connection.execute(
text(f"GRANT ALL ON SCHEMA {target_metadata.schema} TO current_user")
)
# Install pgvector extension if it doesn't exist
connection.execute(text("CREATE EXTENSION IF NOT EXISTS vector"))
# Set and verify search_path
connection.execute(text(f"SET search_path TO {target_metadata.schema}, public"))
connection.execute(
text(f"SET search_path TO {target_metadata.schema}, public, extensions")
)
connection.commit()
context.configure(

View File

@ -50,11 +50,12 @@ def init_db():
echo=os.getenv("SQL_DEBUG", "false").lower() == "true",
)
# Create schema if it doesn't exist
if table_schema:
with sync_engine.connect() as connection:
connection.execute(text(f'CREATE SCHEMA IF NOT EXISTS "{table_schema}"'))
connection.commit()
with sync_engine.connect() as connection:
# Create schema if it doesn't exist
connection.execute(text(f'CREATE SCHEMA IF NOT EXISTS "{table_schema}"'))
# Install pgvector extension if it doesn't exist
connection.execute(text("CREATE EXTENSION IF NOT EXISTS vector"))
connection.commit()
# Run Alembic migrations
alembic_cfg = Config("alembic.ini")