From a8e4d194e883b941a5875ec94adef959edd06c22 Mon Sep 17 00:00:00 2001 From: Hongming Wang Date: Fri, 17 Apr 2026 12:36:42 -0700 Subject: [PATCH] fix(migrations): wrap entire pgvector migration in DO block guard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ALTER TABLE and CREATE INDEX referenced vector(1536) outside the exception-handling DO block, so when pgvector wasn't installed they crashed the migration runner — blocking ALL E2E runs on main. Fix: move all DDL inside the single DO block so the EXCEPTION handler catches any pgvector-related failure and skips the entire migration. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../migrations/031_memories_pgvector.up.sql | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/platform/migrations/031_memories_pgvector.up.sql b/platform/migrations/031_memories_pgvector.up.sql index ed596e8e..631959bc 100644 --- a/platform/migrations/031_memories_pgvector.up.sql +++ b/platform/migrations/031_memories_pgvector.up.sql @@ -3,28 +3,29 @@ -- Adds a dense-vector embedding column to agent_memories to power semantic -- (cosine-similarity) memory recall alongside the existing FTS path. -- --- Requires the pgvector Postgres extension. The DO block is a no-op guard: --- if the extension is unavailable this migration exits early so a boot --- without pgvector installed does not break the migration sweep. +-- Requires the pgvector Postgres extension. The entire migration is wrapped +-- in a single DO block so if pgvector is unavailable, ALL statements are +-- skipped (not just CREATE EXTENSION). This prevents "type vector does not +-- exist" errors on the ALTER TABLE / CREATE INDEX that follow. -- -- Issue: #576 DO $migrate$ BEGIN CREATE EXTENSION IF NOT EXISTS vector; + + -- Nullable: rows written before pgvector is active have NULL embedding and + -- are excluded from cosine-similarity queries automatically. + ALTER TABLE agent_memories ADD COLUMN IF NOT EXISTS embedding vector(1536); + + -- ivfflat approximate nearest-neighbour index for cosine similarity. + -- lists=100 is a reasonable default for tables up to ~1M rows. + -- Partial index (WHERE embedding IS NOT NULL) keeps it lean — unembedded + -- rows are skipped entirely. + CREATE INDEX IF NOT EXISTS agent_memories_embedding_idx + ON agent_memories USING ivfflat (embedding vector_cosine_ops) + WHERE embedding IS NOT NULL; + EXCEPTION WHEN OTHERS THEN - RAISE NOTICE 'pgvector not available on this Postgres instance — 031_memories_pgvector skipped'; - RETURN; + RAISE NOTICE 'pgvector not available — 031_memories_pgvector skipped (%%)', SQLERRM; END $migrate$; - --- Nullable: rows written before pgvector is active have NULL embedding and --- are excluded from cosine-similarity queries automatically. -ALTER TABLE agent_memories ADD COLUMN IF NOT EXISTS embedding vector(1536); - --- ivfflat approximate nearest-neighbour index for cosine similarity. --- lists=100 is a reasonable default for tables up to ~1M rows. --- Partial index (WHERE embedding IS NOT NULL) keeps it lean — unembedded --- rows are skipped entirely. -CREATE INDEX IF NOT EXISTS agent_memories_embedding_idx - ON agent_memories USING ivfflat (embedding vector_cosine_ops) - WHERE embedding IS NOT NULL;