Skip to content

fix(cli): make migration batches transactional (CLI-2261) - #6354

Draft
7ttp wants to merge 12 commits into
developfrom
7ttp/cli-2261-db-reset-pipelined-migration-batch-is-not-a-transaction
Draft

fix(cli): make migration batches transactional (CLI-2261)#6354
7ttp wants to merge 12 commits into
developfrom
7ttp/cli-2261-db-reset-pipelined-migration-batch-is-not-a-transaction

Conversation

@7ttp

@7ttp7ttp commented Aug 27, 2026

Copy link
Copy Markdown
Member

TL;DR

fixes supabase db reset failing with SQLSTATE 25P01 on migrations that use LOCK TABLE

what's biting?

  • Since fix(cli): batch migration statements (CLI-2182) #6224 the TS apply pipelines a migration file over the extended protocol. PostgreSQL treats that pipeline as neither in nor out of a transaction block,
  • so RequireTransactionBlock statements like LOCK TABLE, SET LOCAL and DECLARE ... WITH HOLD fail with 25P01, db reset stops at that migration, and the database is left half migrated and unseeded.
    The Go CLI ran these batches inside a real transaction block, so the same migrations applied through 2.114.0...

now fixed by:

LegacyPgBatchQuery brackets each batch in BEGIN and COMMIT inside the same frame run with one Sync,
so the batch is a genuine transaction block....

the wrapper statements never count toward statementIndex, so At statement numbering is unchanged.
a failed batch rolls its transaction back on the release path, bounded to one second, and the pooled client is discarded when the rollback fails or times out.
Pipeline incompatible statements still run standalone via the existing classifier, and files with authored transaction control still run sequentially...

ref:

@7ttp7ttp self-assigned this Aug 27, 2026
@7ttp
7ttp marked this pull request as ready for review August 27, 2026 09:43
@7ttp
7ttp requested a review from a team as a code ownerAugust 27, 2026 09:43

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:30ba92cbd5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment threadapps/cli/src/legacy/shared/legacy-db-connection.service.ts
Comment threadapps/cli/src/legacy/shared/legacy-db-connection.sql-pg.unit.test.ts Outdated
@github-actions

github-actionsBot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Supabase CLI preview

npx --yes https://pkg.pr.new/supabase/cli/supabase@ce99a402b3090bf543fbdd6935370784369590a6

Preview package for commit ce99a40.

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:ce99a402b3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment threadapps/cli/src/legacy/shared/legacy-db-connection.sql-pg.layer.ts Outdated
Comment threadapps/cli/src/legacy/shared/legacy-migration-apply.ts Outdated
@7ttp
7ttp marked this pull request as draft August 27, 2026 10:13

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:32335b4539

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment threadapps/cli/src/legacy/shared/legacy-migration-apply.ts Outdated

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:8335bfffb9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment threadapps/cli/src/legacy/shared/legacy-migration-apply.ts Outdated

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:7f55c997c2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment threadapps/cli/src/legacy/shared/legacy-migration-apply.ts
Comment threadapps/cli/src/legacy/shared/legacy-migration-apply.ts

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:605f369e0f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

const TABLESPACE_DDL_PATTERN = /^(?:CREATE|DROP)\s+TABLESPACE(?:\s|$)/u;
const REINDEX_DATABASE_PATTERN = /^REINDEX(?:\s+\([^)]*\))?\s+(?:DATABASE|SYSTEM|SCHEMA)(?:\s|$)/u;
const SUBSCRIPTION_DDL_PATTERN = /^(?:CREATE|DROP)\s+SUBSCRIPTION(?:\s|$)/u;
const DISCARD_ALL_PATTERN = /^DISCARD\s+ALL(?:\s|$)/u;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Route CHECKPOINT outside transactional batches

When a migration contains top-level CHECKPOINT, this predicate leaves it in the new BEGIN/COMMIT wrapper, so PostgreSQL rejects the migration with SQLSTATE 25001 even though the previous unwrapped pipeline could execute it. Fresh evidence after the earlier classifier fixes is that both the final predicate and the updated SIDE_EFFECTS.md list still omit CHECKPOINT; add it to the standalone classification and documentation.

AGENTS.md reference: apps/cli/AGENTS.md:L267-L279

Useful? React with 👍 / 👎.

Comment threadapps/cli/src/legacy/shared/legacy-migration-apply.ts
@7ttp

7ttp commented Aug 27, 2026

Copy link
Copy Markdown
MemberAuthor

@codex review

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:a6bd7327e7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment threadapps/cli/src/legacy/shared/legacy-migration-apply.ts
Comment threadapps/cli/src/legacy/shared/legacy-migration-apply.ts
Comment threadapps/cli/src/legacy/shared/legacy-db-connection.sql-pg.layer.ts Outdated
Sign up for freeto 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.

db reset: pipelined migration batch is not a transaction block, so LOCK TABLE fails with 25P01 (regression in 2.115.0)

1 participant

@7ttp