Skip to content

db schema declarative sync: overlap the two shadow provisions and take shadow teardown off the critical path #7563

Open

Description

@luizfneves404

Existing issues

  • 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

  1. When the two shadows use the sequential strategy, 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.
  2. 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. parallel is chosen only when both shadows are warm, baseline-handoff only when both are cold with the same key, and sequential otherwise. The runner is at lines 40–68.
  • The comment on the sequential path 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, runs docker rm -f -v. The cold cache-export path runs docker stop on the shadow container before it writes the baseline archive (apps/cli/src/command-internal/db-bootstrap/shadow-cache.ts, line 620).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions