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:
parent
1b54b4703b
commit
5a2fcfed7d
|
|
@ -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(
|
||||
|
|
|
|||
11
src/db.py
11
src/db.py
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Reference in New Issue