mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Fix pgvector migration to only run when explicitly configured (#1239)
The migration previously checked only if the pgvector extension was available on the PostgreSQL server. In production Docker environments (e.g., managed Postgres services), the extension may be present but the database user lacks superuser privileges to enable it, causing the migration to fail. Now the migration requires VECTOR_STORE_PROVIDER=pgvector to be set before attempting to enable the extension, matching the application's own configuration pattern in VectorStore::Registry. https://claude.ai/code/session_017YYBFXGwamXpGwwDZxe8Pv Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -28,11 +28,15 @@ class CreateVectorStoreChunks < ActiveRecord::Migration[7.2]
|
||||
|
||||
private
|
||||
|
||||
# Check if the pgvector extension is installed in the PostgreSQL server,
|
||||
# not just whether it is enabled in this database. This lets the migration
|
||||
# run harmlessly on plain Postgres (CI, dev without pgvector) while still
|
||||
# creating the table on pgvector-capable servers.
|
||||
# Only run this migration when pgvector is explicitly configured as the
|
||||
# vector store provider AND the extension is actually available on the
|
||||
# PostgreSQL server. Previously we only checked server availability,
|
||||
# which caused failures in production Docker environments where the
|
||||
# extension may be present but the DB user lacks superuser privileges
|
||||
# to enable it.
|
||||
def pgvector_available?
|
||||
return false unless ENV["VECTOR_STORE_PROVIDER"].to_s.downcase == "pgvector"
|
||||
|
||||
result = ActiveRecord::Base.connection.execute(
|
||||
"SELECT 1 FROM pg_available_extensions WHERE name = 'vector' LIMIT 1"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user