From 41ffedb67085654a5eb906f99a76d1d68466ccc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Emre=20Kabakc=C4=B1?= Date: Mon, 4 May 2026 22:11:43 +0100 Subject: [PATCH] fix(db): guard chat_connections copy on table existence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The drop-chat_connections migration assumed the source table was always present, but on prod the table was never materialized (or already gone), so the INSERT...FROM public.chat_connections raised "relation does not exist" and the pre-upgrade hook failed BackoffLimitExceeded — Flux then stalled the HelmRelease after 3 retries. Wrap the data-copy in a DO block guarded by to_regclass so the migration is a no-op when chat_connections is absent. The trailing DROP TABLE IF EXISTS already handles both cases. --- .../20260502000000_drop_chat_connections.sql | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/db/migrations/20260502000000_drop_chat_connections.sql b/db/migrations/20260502000000_drop_chat_connections.sql index d237ecd38..e265c17b2 100644 --- a/db/migrations/20260502000000_drop_chat_connections.sql +++ b/db/migrations/20260502000000_drop_chat_connections.sql @@ -15,16 +15,24 @@ -- agent_connections.agent_id is NOT NULL, but chat_connections.template_agent_id -- was nullable. Skip orphaned rows (no parent agent) — they could not start -- in the current model anyway. -INSERT INTO public.agent_connections ( - id, agent_id, platform, config, settings, metadata, - status, error_message, created_at, updated_at -) -SELECT - id, template_agent_id, platform, config, settings, metadata, - status, error_message, created_at, updated_at -FROM public.chat_connections -WHERE template_agent_id IS NOT NULL -ON CONFLICT (id) DO NOTHING; +-- Guarded by to_regclass: deployments that never had chat_connections +-- (table created with IF NOT EXISTS in 20260429140000 and never used) skip +-- the copy entirely instead of erroring on the missing relation. +DO $$ +BEGIN + IF to_regclass('public.chat_connections') IS NOT NULL THEN + INSERT INTO public.agent_connections ( + id, agent_id, platform, config, settings, metadata, + status, error_message, created_at, updated_at + ) + SELECT + id, template_agent_id, platform, config, settings, metadata, + status, error_message, created_at, updated_at + FROM public.chat_connections + WHERE template_agent_id IS NOT NULL + ON CONFLICT (id) DO NOTHING; + END IF; +END $$; DROP TABLE IF EXISTS public.chat_connections;