From da23497b4c975a8c0238482c1843f1125eb4ccd0 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 5 Jul 2026 19:26:12 +0000 Subject: [PATCH 1/2] fix(db): drop match_document_chunks_text before retrieval owner sentinel rewrite Supabase Preview branches fail with SQLSTATE 42P13 when this migration attempts CREATE OR REPLACE on a function whose OUT signature differs from the live database. Drop first, matching the phase-7 migration pattern. Co-authored-by: BigSimmo --- .../20260705210000_retrieval_owner_filter_sentinel.sql | 5 +++++ supabase/schema.sql | 2 ++ tests/supabase-schema.test.ts | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/supabase/migrations/20260705210000_retrieval_owner_filter_sentinel.sql b/supabase/migrations/20260705210000_retrieval_owner_filter_sentinel.sql index 9a973f440..7cdaf6ccf 100644 --- a/supabase/migrations/20260705210000_retrieval_owner_filter_sentinel.sql +++ b/supabase/migrations/20260705210000_retrieval_owner_filter_sentinel.sql @@ -528,6 +528,11 @@ as $$ limit match_count; $$; +-- The live/preview database may carry a match_document_chunks_text OUT signature +-- that differs from this batching rewrite (see 20260702170000 no-op note). +-- PostgreSQL rejects CREATE OR REPLACE when OUT columns change. +drop function if exists public.match_document_chunks_text(text, integer, uuid[], uuid); + create or replace function public.match_document_chunks_text( query_text text, match_count integer default 12, diff --git a/supabase/schema.sql b/supabase/schema.sql index 357ed9180..08b98df4c 100644 --- a/supabase/schema.sql +++ b/supabase/schema.sql @@ -2663,6 +2663,8 @@ as $$ limit match_count; $$; +drop function if exists public.match_document_chunks_text(text, integer, uuid[], uuid); + create or replace function public.match_document_chunks_text( query_text text, match_count integer default 12, diff --git a/tests/supabase-schema.test.ts b/tests/supabase-schema.test.ts index 5aeb3ce89..a721f4454 100644 --- a/tests/supabase-schema.test.ts +++ b/tests/supabase-schema.test.ts @@ -38,6 +38,10 @@ const phase7RetrievalPerformanceMigration = readFileSync( new URL("../supabase/migrations/20260626020000_phase7_retrieval_rpc_performance.sql", import.meta.url), "utf8", ).replace(/\s+/g, " "); +const retrievalOwnerFilterSentinelMigration = readFileSync( + new URL("../supabase/migrations/20260705210000_retrieval_owner_filter_sentinel.sql", import.meta.url), + "utf8", +).replace(/\s+/g, " "); const atomicReindexMigration = readFileSync( new URL("../supabase/migrations/20260628000000_atomic_reindex_generation_commit.sql", import.meta.url), "utf8", @@ -797,6 +801,12 @@ describe("Supabase Preview replay guards", () => { ); }); + it("drops match_document_chunks_text before retrieval owner sentinel rewrites it", () => { + expect(retrievalOwnerFilterSentinelMigration).toContain( + "drop function if exists public.match_document_chunks_text(text, integer, uuid[], uuid)", + ); + }); + it("guards pg_cron retention schedules for preview branches without cron.job", () => { for (const sql of [ragQueriesRetentionMigration, ragRetrievalLogsRetentionMigration]) { expect(sql).toContain("to_regnamespace('cron')"); From d9fd821d5ccd8a378302a23c4d0271c7abf514f6 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 5 Jul 2026 19:58:43 +0000 Subject: [PATCH 2/2] fix(db): omit updated_at from promote migration for tables without column Co-authored-by: BigSimmo --- ...60706120000_promote_remaining_indexed_documents_public.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/supabase/migrations/20260706120000_promote_remaining_indexed_documents_public.sql b/supabase/migrations/20260706120000_promote_remaining_indexed_documents_public.sql index 36edb7343..dfe343cea 100644 --- a/supabase/migrations/20260706120000_promote_remaining_indexed_documents_public.sql +++ b/supabase/migrations/20260706120000_promote_remaining_indexed_documents_public.sql @@ -42,12 +42,12 @@ from promoted_public_documents pd where dmc.document_id = pd.id; update public.document_table_facts dtf -set owner_id = null, updated_at = now() +set owner_id = null from promoted_public_documents pd where dtf.document_id = pd.id; update public.document_embedding_fields def -set owner_id = null, updated_at = now() +set owner_id = null from promoted_public_documents pd where def.document_id = pd.id;