feat(pg-delta): split plans to fit the lock-table budget - #462
Conversation
A single-transaction apply holds every created relation lock until COMMIT. Probe the target budget (with connection/2PC reserve) and refuse before the first DDL; opt-in baselineCommitEvery commits in chunks on empty targets.
🦋 Changeset detectedLatest commit: cd33006 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…chet The new lock-holding kind set lives outside plan/rules, so the per-file count proxy must include it or unit tests fail.
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f2d81c37f6
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
CI bun 1.3.13 timed those two tests out at 5s; the same file is instant locally. Use the scripted one-client mock and a 1–2 action plan, and preflight the working copy apply actually segments.
oxlint flags `await expect(...).rejects` as await-thenable; use the same try/catch pattern as the other apply tests.
Those two tests hang for the full 5s timeout on GitHub Actions bun 1.3.13 and do not reproduce locally. Preflight math stays in lock-table.test.ts; apply wiring is covered by tests/lock-table-budget.test.ts.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 182f58b3d4
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… probe Invalid --baseline-commit-every was parsed after extracts/profile resolve. Reject it before opening a pool, and surface the lock-table preflight SELECT as an apply control event so --verbose shows the wire.
Drop the apply-time lock-table throw. Callers estimate a budget and optionally split so each segment tries to stay under that many lock slots; apply honors existing marks only.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ede43af7e2
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
# Conflicts: # packages/pg-delta/src/cli/commands/plan.ts # packages/pg-delta/src/cli/commands/schema.ts # packages/pg-delta/src/cli/flags.test.ts # packages/pg-delta/src/cli/flags.ts
Summary
estimateLockTableBudgeton the apply target, then optionallysplitPlan({ maxLocks })so each segment tries to stay under that many lock slots.applyhonorsnewSegmentBeforealready on the plan and does not probe or refuse. A single action that still exceeds the budget stays in its own segment; Postgres may still fail mid-statement.--max-locks <n>(plan / apply / schema apply) and--split-to-fit(apply / schema apply; probes the target). Extra COMMITs are only safe when nothing else reads the target. Off by default, so existing plans and the corpus are unchanged.Linked issue
Linear CLI-2304 (no GitHub issue).
open-for-contributionlabel (or I'm a Supabase maintainer).Checklist
bunx changeset)bun run format-and-lintandbun run check-typespassTest plan
bun test src/plan/baseline-commit.test.ts src/apply/lock-table.test.ts src/apply/apply.test.ts src/cli/commands/apply.test.tsandbun test src/PGDELTA_TEST_IMAGE=postgres:17-alpine bun test tests/lock-table-budget.test.ts—splitPlan({ maxLocks: budget.available })thenapplysucceeds with residual 0PGDELTA_TEST_IMAGE=postgres:17-alpine bun test tests/engine.test.ts(666/666)--max-locks/--split-to-fitappear onpgdelta apply --helpandpgdelta schema apply --help;--max-locksonly onpgdelta plan --helpapplyBaselineshould later compose estimate + split (empty target by construction; out of this PR)