Skip to content

fix(db): guard chat_connections copy on table existence#525

Merged
buremba merged 1 commit into
mainfrom
fix/migration-drop-chat-connections-idempotent
May 4, 2026
Merged

fix(db): guard chat_connections copy on table existence#525
buremba merged 1 commit into
mainfrom
fix/migration-drop-chat-connections-idempotent

Conversation

@buremba
Copy link
Copy Markdown
Member

@buremba buremba commented May 4, 2026

Summary

  • Migration 20260502000000_drop_chat_connections.sql was failing the pre-upgrade Helm hook on summaries-prod (HelmRelease/summaries-app stalled, BackoffLimitExceeded on summaries-app-owletto-migrate).
  • Root cause: the migration ran INSERT INTO agent_connections ... FROM public.chat_connections unconditionally. Prod's DB never had chat_connections (the originating IF NOT EXISTS table from refactor: unify connection storage on agent_connections, drop chat_connections #506-era migration was no-op'd or already cleaned up), so Postgres errored with relation "public.chat_connections" does not exist before reaching DROP TABLE IF EXISTS.
  • Fix: wrap the data-copy in a DO block guarded by to_regclass('public.chat_connections') IS NOT NULL. Idempotent on both fresh deployments (no source table) and live deployments (rows copied as before).

Test plan

  • Dry-run executed against prod DB inside BEGIN...ROLLBACK — completed without error.
  • Merge → image build → Flux retries summaries-app-owletto-migrate → HelmRelease goes Ready.
  • Verify on a DB that DOES have chat_connections rows that the copy still occurs (not currently in any environment, but logic preserved).

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.
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@buremba buremba merged commit 7d95910 into main May 4, 2026
14 of 16 checks passed
@buremba buremba deleted the fix/migration-drop-chat-connections-idempotent branch May 4, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants