Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions apps/cli-e2e/src/tests/live/db-reset-start.live.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import { testLive } from "./live-context.ts";
// Exercises `db start`'s native container-bootstrap sequence (network/volume/container
// bring-up, health wait, the fresh-volume SetupLocalDatabase-equivalent pipeline, and
// `_current_branch`) and `db reset --local`'s container-recreate flow end-to-end — the
// real-Docker boundary the in-process integration suites mock. `db reset --local` still
// delegates its container-recreate flow to the bundled Go binary's hidden
// `db __db-bootstrap --mode recreate` seam (CLI-1955, unclaimed as of CLI-1954); `db start`
// no longer does (see `commands/db/start/start.handler.ts`). The start → already-running →
// reset cycle runs in one test so it shares a single booted stack, and `finally` stops it
// (legacy proxies `stop` to Go) so the run never leaves containers behind.
// real-Docker boundary the in-process integration suites mock. Both are fully native TS
// now: `db reset --local`'s hidden Go `db __db-bootstrap` seam (`--mode recreate`/
// `--mode await-storage`) was removed in CLI-1955 (see
// `commands/db/reset/reset.handler.ts` / `shared/db-bootstrap/recreate-local-database.ts`),
// the same way `db start`'s own seam usage was removed in CLI-1954 (see
// `commands/db/start/start.handler.ts`). The start → already-running → reset cycle runs
// in one test so it shares a single booted stack, and `finally` stops it (legacy proxies
// `stop` to Go) so the run never leaves containers behind.
describe.skipIf(TARGET === "ts-next")("db start / db reset --local (live, local Docker)", () => {
testLive(
"db start boots, is idempotent, and db reset --local recreates",
Expand Down
67 changes: 0 additions & 67 deletions apps/cli-go/cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,66 +270,6 @@ var (
},
}

bootstrapMode string
bootstrapSqlPaths []string
bootstrapVersion string
bootstrapNoSeed bool

// dbBootstrapCmd is a hidden seam used by the native-TypeScript `db reset --local`
// command to drive the container-bootstrap primitives that are not yet ported to
// TypeScript: recreating the local Postgres container, applying the initial
// schema, and the storage health gate. The TS caller orchestrates everything else
// (version/last resolution, bucket seeding, the git-branch "Finished…" line,
// telemetry, and --output-format shaping); the seam stays in Go only for the
// Docker lifecycle. It mirrors the existing db __shadow seam: it carries no
// db-url/local/linked target flags, so it loads supabase/config.toml explicitly
// (the root PersistentPreRunE only loads it when a target flag is set). Progress
// goes to stderr; the only stdout output is a single machine-parseable marker
// for --mode await-storage ("ready" or "absent"). `db start`'s own container
// bootstrap (--mode start) was removed from this seam by CLI-1954 — it is now a
// fully native TypeScript implementation
// (apps/cli/src/legacy/commands/db/start/start.handler.ts), reusing
// legacy/shared/db-bootstrap/'s already-ported container-bootstrap primitives
// instead of shelling out to this binary. `start.StartDatabase` itself (called
// below by the real, customer-facing `db start` Go command) is untouched — it
// remains the parity oracle this TS port was checked against.
dbBootstrapCmd = &cobra.Command{
Use: "__db-bootstrap",
Hidden: true,
Short: "Internal: container bootstrap for the native db start / db reset commands",
RunE: func(cmd *cobra.Command, args []string) error {
fsys := afero.NewOsFs()
if err := flags.LoadConfig(fsys); err != nil {
return err
}
switch bootstrapMode {
case "recreate":
// The PG14/PG15 container-recreate half of local db reset. The TS
// caller has already printed "Resetting local database…" and validated
// the flags. Apply the same seed handling as `db reset` (dbResetCmd):
// `--no-seed` disables the seed, `--sql-paths` overrides the seed paths,
// before MigrateAndSeed runs inside the recreate.
if err := applyDbResetSeedFlags(bootstrapNoSeed, bootstrapSqlPaths); err != nil {
return err
}
return reset.RecreateLocalDatabase(cmd.Context(), bootstrapVersion, fsys)
case "await-storage":
ready, err := reset.AwaitStorageReady(cmd.Context())
if err != nil {
return err
}
if ready {
fmt.Println("ready")
} else {
fmt.Println("absent")
}
return nil
default:
return fmt.Errorf("unknown bootstrap mode: %s", bootstrapMode)
}
},
}

dbRemoteCmd = &cobra.Command{
Hidden: true,
Use: "remote",
Expand Down Expand Up @@ -680,13 +620,6 @@ func init() {
shadowFlags.StringSliceVarP(&shadowSchema, "schema", "s", []string{}, "Comma separated list of schema to include.")
shadowFlags.StringVar(&shadowProjectRef, "project-ref", "", "Linked project ref, so the shadow merges the matching [remotes.<ref>] config override.")
dbCmd.AddCommand(dbShadowCmd)
// Build hidden container-bootstrap seam command (native db start / db reset)
bootstrapFlags := dbBootstrapCmd.Flags()
bootstrapFlags.StringVar(&bootstrapMode, "mode", "recreate", "Bootstrap mode: recreate or await-storage.")
bootstrapFlags.StringVar(&bootstrapVersion, "version", "", "Reset up to the specified version (recreate mode).")
bootstrapFlags.BoolVar(&bootstrapNoSeed, "no-seed", false, "Skip the seed script after recreate (recreate mode).")
bootstrapFlags.StringArrayVar(&bootstrapSqlPaths, "sql-paths", nil, "Override [db.seed].sql_paths for the recreate (recreate mode).")
dbCmd.AddCommand(dbBootstrapCmd)
// Build remote command
remoteFlags := dbRemoteCmd.PersistentFlags()
remoteFlags.StringSliceVarP(&schema, "schema", "s", []string{}, "Comma separated list of schema to include.")
Expand Down
32 changes: 0 additions & 32 deletions apps/cli-go/internal/db/reset/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,38 +93,6 @@ func toLogMessage(version string) string {
return "..."
}

// RecreateLocalDatabase is the container-lifecycle half of a local `db reset`,
// exposed for the native-TypeScript `db reset --local` seam (cmd db __db-bootstrap).
// It performs the PG14/PG15 branch — recreate the db container/volume, init schema,
// migrate + seed, and restart the satellite containers — WITHOUT the leading
// "Resetting local database…" line, which the TS caller prints itself. Mirrors
// resetDatabase (above) minus that message.
func RecreateLocalDatabase(ctx context.Context, version string, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error {
if utils.Config.Db.MajorVersion <= 14 {
return resetDatabase14(ctx, version, fsys, options...)
}
return resetDatabase15(ctx, version, fsys, options...)
}

// AwaitStorageReady mirrors the storage-health gate that local `db reset` runs
// before seeding buckets (Run, above): if the storage container exists but is not
// healthy, wait up to 30s for it. It reports whether the storage container exists
// so the native-TypeScript caller knows whether to run the (already-ported) bucket
// seeding. Any inspect error is treated as "storage not running" → false, matching
// Go's `err == nil` gate, which silently skips buckets on any inspect failure.
func AwaitStorageReady(ctx context.Context) (bool, error) {
resp, err := utils.Docker.ContainerInspect(ctx, utils.StorageId)
if err != nil {
return false, nil
}
if resp.State.Health == nil || resp.State.Health.Status != types.Healthy {
if err := start.WaitForHealthyService(ctx, 30*time.Second, utils.StorageId); err != nil {
return false, err
}
}
return true, nil
}

func resetDatabase14(ctx context.Context, version string, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error {
if err := recreateDatabase(ctx, options...); err != nil {
return err
Expand Down
Loading
Loading