fix(migration): handle pipeline-incompatible statements in ExecBatch#5156
Closed
wucm667 wants to merge 4 commits into
Closed
fix(migration): handle pipeline-incompatible statements in ExecBatch#5156wucm667 wants to merge 4 commits into
wucm667 wants to merge 4 commits into
Conversation
CREATE INDEX CONCURRENTLY, REINDEX CONCURRENTLY, and VACUUM cannot run inside a pgx pipeline (extended query protocol). When db reset encounters these statements, the batch fails with SQLSTATE 25001. Fix: detect pipeline-incompatible statements and execute them individually via conn.Exec (simple query protocol) while batching the rest normally. Fixes supabase#5139 Signed-off-by: wucm667 <stevenwucongmin@gmail.com>
05e9dba to
1149dfc
Compare
Coly010
added a commit
that referenced
this pull request
Jun 24, 2026
…transaction (#5139) Migrations containing CREATE INDEX CONCURRENTLY (and VACUUM, REINDEX CONCURRENTLY, ALTER SYSTEM, CLUSTER) failed with SQLSTATE 25001 because the TS apply wraps every statement in a single BEGIN/COMMIT, and those statements cannot run inside a transaction block. Port the fix from the Go PR #5156 into the native TS apply: detect pipeline-incompatible statements (legacyIsPipelineIncompatible), flush the open batch, run the statement standalone, then resume batching. The history insert goes in the final batch, so the migration is recorded only after every statement succeeds. Migrations without such statements stay a single BEGIN/COMMIT — behaviour is unchanged for them. Shared by migration up/down and declarative sync.
Contributor
|
Thanks for this @wucm667, and for the thorough writeup — the pipeline / Heads up on where this lands: the CLI is mid-migration from Go to TypeScript, and the
I'm closing this in favour of that implementation, since these commands no longer run through the Go path. Really appreciate the contribution — the design carried over directly. 🙏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5139
What type of PR is this?
What this PR does / why it is needed:
When running
supabase db reset, migrations containingCREATE INDEX CONCURRENTLYfail with SQLSTATE 25001 ("cannot be executed within a pipeline"). This is becauseExecBatchinpkg/migration/file.gosends all statements throughconn.PgConn().ExecBatch(), which uses PostgreSQL's extended query protocol pipeline — incompatible with CONCURRENTLY, VACUUM, REINDEX CONCURRENTLY, ALTER SYSTEM, and CLUSTER statements.The fix:
isPipelineIncompatible()to detect statements that cannot run in a pipelineExecBatchto flush the batch before these statements and execute them individually viaconn.Exec(simple query protocol), then resume batching for subsequent statementsTesting
Manual testing with a migration file containing
CREATE INDEX CONCURRENTLYconfirms the fix — the statement now executes successfully via simple protocol while other statements continue to benefit from pipelining.