cli
cli copied to clipboard
db schema declarative sync: overlap the two shadow provisions and take shadow teardown off the critical path
Existing issues
- [x] I have searched the existing issues.
Affected area
Migrations
Problem to solve
On a declarative tree of about 750 SQL files, supabase db schema declarative sync spends most of its wall time outside the diff. We measured these phases from the CLI's trace output (SUPABASE_TRACE_FILE) on CLI 3.1.0, on Linux with Docker, across repeated runs:
| Phase | Measured range |
|---|---|
| First shadow start | 2.4–3.5 s |
| Migration replay in the shadow | 3.8–5.2 s |
| Second shadow start and load | 4.1–5.1 s |
| pg-delta plan | 16.8–17.3 s |
| Shutdown of both shadows, after the diff result is known | 3.8–25 s |
We did not attribute the shutdown range to a specific teardown path.
Proposed solution
- When the two shadows use the
sequentialstrategy, start the second shadow while the first one replays. Keep each shadow's output buffered, as the code already does, so the output stays readable. - Tear the shadows down concurrently, or after the migration file has been written, so teardown does not delay the command's result.
Alternatives considered
--no-cache skips the shadow baseline cache but keeps the sequential provisioning and the teardown, so it does not address the wall time.
Additional context
Source at tag v3.1.0 (commit d4fc0e5):
- Strategy selection:
apps/cli/src/commands/db/shared/pgdelta-next-shadow.plan.ts, lines 19–32.parallelis chosen only when both shadows are warm,baseline-handoffonly when both are cold with the same key, andsequentialotherwise. The runner is at lines 40–68. - The comment on the
sequentialpath says the mode keeps the cold side's baseline output off the live stream. The same file contains the output buffering (bufferedShadowOutput). - Release:
apps/cli/src/command-internal/db-bootstrap/shadow-database.ts, lines 255–275, runsdocker rm -f -v. The cold cache-export path runsdocker stopon the shadow container before it writes the baseline archive (apps/cli/src/command-internal/db-bootstrap/shadow-cache.ts, line 620).