Open-source personal finance manager. Self-hosted, privacy-first.
fix: actionable error when upgrading without pgvector
Tássio Noronha01e28eddce4d
diff --git a/backend/alembic/versions/046_agents_foundation.py b/backend/alembic/versions/046_agents_foundation.pyindex a1728986..b5eaa7d8 100644--- a/backend/alembic/versions/046_agents_foundation.py+++ b/backend/alembic/versions/046_agents_foundation.py@@ -10,6 +10,7 @@ the AGENTS_ENABLED env var. Empty tables cost nothing.from alembic import opimport sqlalchemy as sa+from sqlalchemy import textfrom sqlalchemy.dialects import postgresqlfrom pgvector.sqlalchemy import Vector@@ -21,7 +22,30 @@ branch_labels = Nonedepends_on = None+_PGVECTOR_MISSING_MSG = (+ "\n\n"+ " pgvector is not installed in your Postgres server.\n"+ " Securo v0.11.0+ requires pgvector for the agents knowledge base.\n\n"+ " Fix: switch your `db` service image to a Postgres build that bundles\n"+ " pgvector, then re-run the upgrade:\n\n"+ " image: pgvector/pgvector:pg16 # was: postgres:16-alpine\n\n"+ " Your data volume is preserved (same on-disk format).\n"+ " See https://github.com/securo-finance/securo/releases/tag/v0.11.0\n"+)++def upgrade() -> None:+ # Pre-flight: refuse to start the migration unless pgvector is+ # physically available on the server. Without this guard the user+ # would see a 50-line asyncpg traceback for a one-line fix+ # (image swap), with the backend stuck in a crash loop in between.+ bind = op.get_bind()+ available = bind.execute(+ text("SELECT 1 FROM pg_available_extensions WHERE name = 'vector'")+ ).first()+ if available is None:+ raise RuntimeError(_PGVECTOR_MISSING_MSG)+op.execute("CREATE EXTENSION IF NOT EXISTS vector")embed_dim = get_agent_settings().embedding_dimdiff --git a/docker-compose.prod.yml b/docker-compose.prod.ymlindex b6e4082f..249fd6c4 100644--- a/docker-compose.prod.yml+++ b/docker-compose.prod.yml@@ -32,7 +32,10 @@ services:retries: 5db:- image: postgres:16-alpine+ # pgvector/pgvector:pg16 is a drop-in replacement for postgres:16+ # that bundles the pgvector extension, required by the agents+ # knowledge-base (RAG) migration introduced in v0.11.0.+ image: ${DB_IMAGE:-pgvector/pgvector:pg16}environment:POSTGRES_USER: postgresPOSTGRES_PASSWORD: postgres