fix(cli): make migration batches transactional (CLI-2261) - #6354
Conversation
There was a problem hiding this comment.
💡 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".
Supabase CLI previewnpx --yes https://pkg.pr.new/supabase/cli/supabase@3224cb51b24b6ae279d430079dae961222f48c26Preview package for commit |
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
|
@codex review |
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
Superseded by a newer AI review
🤖 AI Review
Both independent reviews completed (8 Claude findings, 4 Codex findings). After merging overlapping SQL-classifier findings, all 10 resulting findings are confirmed. The major issues are unsafe/incomplete classification of statements that must run outside the new explicit transaction and broken CALL/DO transaction-control workflows. The remaining findings concern localized error handling, documentation, redundant role restoration, cleanup robustness, maintainability, and regression-test coverage.
Findings
| Severity | Location | Category | Sources | Claim |
|---|---|---|---|---|
| 🟠 MAJOR | apps/cli/src/legacy/shared/legacy-migration-apply.ts:67 |
sql-parsing |
claude+codex | The new regex-based SQL classifiers are not token-aware: they can match action keywords inside literals and miss incompatible commands split by newlines or internal comments, causing unexpected commits or SQLSTATE 25001 failures. |
| 🟠 MAJOR | apps/cli/src/legacy/shared/legacy-migration-apply.ts:134 |
sql-compatibility |
claude | The incompatible-statement classifier omits ALTER TABLE … DETACH PARTITION … CONCURRENTLY, so PostgreSQL rejects that valid migration command inside the new explicit transaction. |
| 🟠 MAJOR | apps/cli/src/legacy/shared/legacy-migration-apply.ts:134 |
sql-compatibility |
codex | The incompatible-statement classifier omits CHECKPOINT, causing migrations containing it to fail inside the new explicit transaction. |
| 🟠 MAJOR | apps/cli/src/legacy/shared/legacy-db-connection.sql-pg.layer.ts:322 |
behavior-regression |
codex | The unconditional explicit transaction breaks top-level CALL and DO statements whose procedure or block performs transaction control. |
| 🟡 MINOR | apps/cli/src/legacy/shared/legacy-db-connection.sql-pg.layer.ts:249 |
error-handling |
claude | BEGIN-failure labeling depends on the localized PostgreSQL severity string, so non-English servers omit the new explanatory prefix. |
| 🟡 MINOR | apps/cli/src/legacy/commands/db/push/SIDE_EFFECTS.md:32 |
documentation |
claude | The affected SIDE_EFFECTS.md files document BEGIN and COMMIT but omit the new failure-path ROLLBACK database mutation. |
| 🟡 MINOR | apps/cli/src/legacy/shared/legacy-db-connection.sql-pg.integration.test.ts:568 |
test-coverage |
claude | No test verifies the user-visible transaction-block behavior that motivated the change against PostgreSQL; current batch tests only verify protocol framing through a fake server. |
| ⚪ NIT | apps/cli/src/legacy/shared/legacy-migration-apply.ts:799 |
correctness |
claude | When the last statement is both standalone-incompatible and role-reverting, the stepped-down role restore is sent twice with no intervening user statement. |
| ⚪ NIT | apps/cli/src/legacy/shared/legacy-db-connection.sql-pg.layer.ts:266 |
maintainability |
claude | legacyShouldDiscardBatchClient is documented as deciding the discard policy, but the rollback-dependent part of that policy is implemented separately at its call site and cannot be covered by its unit tests. |
| ⚪ NIT | apps/cli/src/legacy/shared/legacy-db-connection.sql-pg.layer.ts:1179 |
robustness |
claude | If activeClient.release throws, the checked-out client's error listener is not removed because listener cleanup is not protected by finally. |
Stats
Claude findings: 8 · Codex findings: 4 · Confirmed: 10 · Refuted: 0 · Uncertain: 0
Models: claude-opus-5 + gpt-5.6-sol · Trigger: manual · Workflow run
This review runs once per PR. A maintainer can request another with a /ai-review comment.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9cea8df10d
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0a7172a050
ℹ️ 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".
|
/ai-review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b85ecc626
ℹ️ 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".
There was a problem hiding this comment.
Superseded by a newer AI review
🤖 AI Review
Seven findings are confirmed and one is refuted. The main correctness issue is that CHECKPOINT is absent from the transaction-incompatibility classifier, so ordinary migrations containing it will fail inside the new explicit transaction. The classifier also misses valid comment-separated and REINDEX option spellings. Both independent reviews were available.
Findings
| Severity | Location | Category | Sources | Claim |
|---|---|---|---|---|
| 🟠 MAJOR | apps/cli/src/legacy/shared/legacy-migration-apply.ts:148 |
correctness |
codex | CHECKPOINT is not classified as pipeline-incompatible, so an ordinary migration containing it is sent inside the new explicit transaction and rejected by PostgreSQL. |
| 🟡 MINOR | apps/cli/src/legacy/shared/legacy-migration-apply.ts:69 |
correctness |
claude+codex | The raw-whitespace regexes miss valid transaction-incompatible spellings such as REINDEX(VERBOSE) DATABASE postgres and statements with comments between keywords. |
| 🟡 MINOR | apps/cli/src/legacy/shared/legacy-migration-apply.ts:70 |
correctness |
claude | Subscription patterns conservatively classify transaction-safe connect=false and refresh=false variants as incompatible, introducing unnecessary flush boundaries while the documentation says all matched forms fail in a transaction. |
| 🟡 MINOR | apps/cli/src/legacy/shared/legacy-db-connection.sql-pg.layer.ts:1180 |
error-handling |
claude | A synchronous throw from activeClient.query("ROLLBACK") becomes an Effect defect and can replace the original typed batch error. |
| ⚪ NIT | apps/cli/src/legacy/shared/legacy-db-connection.service.ts:113 |
documentation |
claude | The execBatch contract promises unconditionally that failed batches are rolled back, although rollback is best-effort and bounded. |
| ⚪ NIT | apps/cli/src/legacy/shared/legacy-db-connection.sql-pg.integration.test.ts:707 |
testing |
claude | The socket-death test inaccurately calls the rollback a 'release-path rollback' even though rollback occurs before resource release. |
| ⚪ NIT | apps/cli/src/legacy/commands/migration/up/SIDE_EFFECTS.md:71 |
documentation |
claude | The expanded pipeline-incompatible list contains repeated mid-list conjunctions, making the sentence grammatically awkward. |
Refuted findings (kept for transparency, not posted as review comments)
apps/cli/src/legacy/shared/legacy-db-connection.sql-pg.layer.ts:114(error-handling): SQLSTATE 57P04 is omitted from the session-ending SQLSTATE set and is consequently mislabeled as a transaction-start or commit failure.
Refuted: The checked-out PR already includes 57P04 in the set and has a focused test asserting the intended unprefixed rendering.
Stats
Claude findings: 7 · Codex findings: 3 · Confirmed: 7 · Refuted: 1 · Uncertain: 0
Models: claude-opus-5 + gpt-5.6-sol · Trigger: manual · Workflow run
This review runs once per PR. A maintainer can request another with a /ai-review comment.
There was a problem hiding this comment.
💡 Codex Review
cli/apps/cli/src/legacy/shared/legacy-migration-apply.ts
Lines 795 to 800 in 79cf215
When a deferred constraint fails during the injected COMMIT, statementIndex equals operations.length, so raw is past the operations array and this fallback reports the history insert (with an index beyond the migration's statements) as the failing SQL. The resulting error contradictorily says failed to commit the batch transaction and then blames an already successful statement. Fresh evidence after the claimed fix is that legacy-migration-apply.unit.test.ts:287-298 still expects At statement: 2 plus the history insert for a one-statement migration; handle the commit phase separately instead of passing it through the statement formatter.
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
When a migration uses PostgreSQL's option-list spelling such as REINDEX (CONCURRENTLY) INDEX idx, this regexp returns false because it requires whitespace immediately before CONCURRENTLY, whereas here the preceding character is (. PostgreSQL documents CONCURRENTLY as a REINDEX option and prohibits concurrent reindexing inside a transaction block, so the new explicit BEGIN makes this valid migration fail instead of routing it standalone; recognize enabled CONCURRENTLY options while avoiding the transaction-safe CONCURRENTLY false form.
AGENTS.md reference: apps/cli/AGENTS.md:L267-L279
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c838da3fae
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7ddeddc198
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f83f6723ec
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d3beb8dfc8
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b0f6cba496
ℹ️ 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".
TL;DR
fixes
supabase db resetfailing with SQLSTATE 25P01 on migrations that useLOCK TABLEwhat's biting?
RequireTransactionBlockstatements 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:
LegacyPgBatchQuerybrackets 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: