Skip to content

fix(branching): ensure pgmq extension creation syntax is dumped on branch operations#4940

Open
dumko2001 wants to merge 1 commit intosupabase:developfrom
dumko2001:fix-dashboard-branch-schema
Open

fix(branching): ensure pgmq extension creation syntax is dumped on branch operations#4940
dumko2001 wants to merge 1 commit intosupabase:developfrom
dumko2001:fix-dashboard-branch-schema

Conversation

@dumko2001
Copy link

What kind of change does this PR introduce?

Bug fix #40666 #4492

What is the current behavior?

  1. Currently, pgmq queues fail to create during Supabase Branch Resets (producing schema pgmq does not exist or sequence already exists errors).
  2. This is because pg_dump --schema-only originally produced a segmentation fault with older versions of pgmq (fixed in tembo-io/pgmq 1.5.0), leading to it being deliberately excluded in dump.go via fix: exclude pgmq schema from db dump and pull #3043.
  3. To bypass the fact that CREATE SCHEMA pgmq is not emitted due to this exclusion, dump_schema.sh attempts to strip the schema requirement from CREATE EXTENSION IF NOT EXISTS pgmq WITH SCHEMA pgmq.
  4. Without the explict WITH SCHEMA definition, the pgmq extension inappropriately initializes into public on Branch copies instead of its own schema. This breaks downstream logic, leaving orphaned tables on the branch.
  5. Furthermore, pgmq is explicitly ignored in drop.go / drop.sql, resulting in queue tables never actually being wiped when a Branch is Reset.

What is the new behavior?

  1. Modified the sed replacement for pgmq inside dump_schema.sh. Instead of stripping the schema, it now prepends CREATE SCHEMA IF NOT EXISTS "pgmq"; and preserves WITH SCHEMA "pgmq". This ensures pgmq is consistently installed in its correct schema during branch creations.
  2. Removed pgmq from ManagedSchemas in drop.go and the exclusion array in drop.sql. This allows supabase db reset and Branch Reset operations to accurately drop and rebuild the pgmq schema, clearing the orphaned queue tables and sequences, preventing "already exists" failures during migrations.

@dumko2001 dumko2001 requested a review from a team as a code owner March 8, 2026 09:24
@coderabbitai
Copy link

coderabbitai bot commented Mar 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 6bc9fcbd-e565-4915-b3ac-8cb186f9c5a0

📥 Commits

Reviewing files that changed from the base of the PR and between db0bfe7 and 7abbfe3.

📒 Files selected for processing (3)
  • pkg/migration/drop.go
  • pkg/migration/queries/drop.sql
  • pkg/migration/scripts/dump_schema.sh
💤 Files with no reviewable changes (1)
  • pkg/migration/drop.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Refined pgmq schema management during migrations and dump operations to ensure proper schema creation and association.

Walkthrough

The changes modify how the pgmq schema is handled in the migration system. The pgmq entry was removed from the ManagedSchemas exclusion list in drop.go, and the corresponding SQL schema-dropping filter now omits pgmq from its exclusion clause. Additionally, the dump_schema.sh script was updated to change the pgmq extension handling during pg_dump—instead of appending a semicolon, it now creates the pgmq schema explicitly and applies a WITH SCHEMA clause to the CREATE EXTENSION command.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant