Skip to content

feat(cli): port supabase inspect db to native TypeScript#5554

Merged
Coly010 merged 4 commits into
developfrom
cli/port-inspect-db
Jun 12, 2026
Merged

feat(cli): port supabase inspect db to native TypeScript#5554
Coly010 merged 4 commits into
developfrom
cli/port-inspect-db

Conversation

@Coly010

@Coly010 Coly010 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

What changed

Ports all of supabase inspect db (CLI-1316) from Phase 0 Go proxies to native TypeScript in the legacy shell. The 13 active subcommands (db-stats, replication-slots, locks, blocking, outliers, calls, index-stats, long-running-queries, bloat, role-stats, vacuum-stats, table-stats, traffic-profile) and their 12 deprecated aliases now connect to Postgres directly via the already-ported LegacyDbConnection, run the embedded query, and render Go-parity Glamour tables — no more shelling out to the Go binary.

Highlights

  • LegacyDbSession.query added to the connection service + @effect/sql-pg layer (positional client.unsafe(sql, params) binding); the one other object-literal consumer (test db mock) updated.
  • Shared infra at inspect/db/: LegacyInspectQuerySpec + the legacyRunInspectQuery runner, pure cell formatters (%s/%t/%d/%.1f/whitespace-collapsed stmt), the 29-entry internal-schema list + legacyLikeEscapeSchema, legacyInspectDbRuntimeLayer, command boilerplate (LEGACY_INSPECT_DB_FLAGS + handler pipe), and the deprecation-notice builder.
  • One verbatim <name>.query.ts spec per active subcommand; deprecated aliases route to the active spec — including preserving Go's quirk where table-record-counts warns "table-stats" but runs the index-stats query.

Go parity preserved

  • --db-url / --linked / --local selector flags (mutually exclusive; --linked default-true derived from absence), no --project-ref. One deliberate divergence — see below.
  • "Connecting to local/remote database..." diagnostic on stderr (matching ConnectByConfig).
  • Statement cells collapse whitespace using Go's RE2 \s set ([\t\n\f\r ] + individual \v), not JS \s.
  • vacuum-stats renders 9 of 11 columns with the one-shot -1No stats; bloat uses the clean 4-column header.
  • Deprecated aliases print Command "<name>" is deprecated, use "<target>" instead. to stderr.
  • json / stream-json modes emit { rows } (additive — Go has no machine output for inspect).

Behavioral change vs Go ⚠️ (release note)

Explicit --linked=false no longer triggers the mutual-exclusion error. Go uses cobra's MarkFlagsMutuallyExclusive, which keys off whether a flag was explicitly provided (cobra's Changed), counting even --linked=false as set. So in the Go CLI, supabase inspect db locks --linked=false --local fails flag validation. This port checks the parsed boolean value instead, so an explicit --linked=false is indistinguishable from the default and the command proceeds to connect using --local (or --db-url).

We're keeping the TS behavior intentionally — treating --linked=false as "not selecting linked" rather than as a hard conflict is the more sensible interpretation, and the realistic conflict cases (two positive selectors set, e.g. --linked --local or --db-url … --local) are still rejected exactly as in Go. Calling it out here so it lands in the release notes as a deliberate, user-observable difference.

Docs / tracking

  • 25 per-subcommand proxy SIDE_EFFECTS.md consolidated into one shared family doc.
  • All 25 inspect db rows in go-cli-porting-status.md flipped wrappedported.

Closes CLI-1316

Replace the Phase 0 Go proxies for all 13 active `inspect db` subcommands
and their 12 deprecated aliases with native TypeScript handlers that connect
to Postgres directly via LegacyDbConnection and render Go-parity Glamour
tables.

- Add a `query` method to LegacyDbSession (sql-pg impl via client.unsafe).
- Add shared infra at inspect/db/: LegacyInspectQuerySpec + runner, cell
  formatters, internal-schema LIKE-escape, runtime layer, command boilerplate
  (LEGACY_INSPECT_DB_FLAGS + handler pipe), and the deprecation-notice builder.
- One verbatim <name>.query.ts spec per active subcommand; deprecated aliases
  route to the active spec (preserving Go's table-record-counts inconsistency).
- Preserve Go parity: stderr connection diagnostic, whitespace-collapsed stmt
  cells (matching RE2 `\s`, not JS `\s`), vacuum -1 -> No stats, bloat header.
- Consolidate 25 proxy SIDE_EFFECTS.md into one shared family doc.
- Flip the 25 porting-status rows to `ported`.
@Coly010 Coly010 requested a review from a team as a code owner June 11, 2026 15:45
@Coly010 Coly010 self-assigned this Jun 11, 2026
@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

Supabase CLI preview

npx --yes https://pkg.pr.new/supabase@5554

Preview package for commit 967356b.

…e2e shard 3/3)

Go wraps almost every `inspect db` table cell in a `…` code-span (e.g.
`role_stats.go:43`). Glamour's AsciiStyle strips the backticks from a
non-empty span but leaves an empty span (``) as the two literal backtick
characters, so an empty cell renders as `` and contributes width 2. The
TS port stripped backticks at projection time and rendered an empty value
as nothing, diverging from Go on the role-stats `custom_config` cell for
the `postgres` row (e2e parity: inspect db role-stats).

`legacyInspectText` now models Go's backtick-wrapped `%s` (empty -> ``).
The few columns Go leaves unwrapped get explicit formatters:
- `legacyInspectPlainText` for the vacuum_stats timestamp columns (bare
  `%s|`, empty stays empty).
- `legacyInspectBacktickStmt` for the calls/outliers query columns, which
  Go wraps unlike the bare locks/blocking statements.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c17b4e335f

ℹ️ 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".

Comment thread apps/cli/src/legacy/commands/inspect/db/db.layers.ts Outdated
….layers)

The shared inspect-db runtime layer hardcoded the command-runtime path as
["inspect","db"] and provided it to all 25 leaf subcommands, so
withLegacyCommandInstrumentation recorded every subcommand as `inspect db`
in the PostHog `cli_command_executed` event. Go records each leaf's full
`cmd.CommandPath()` (root_analytics.go:32-38) — its inspect tree is a real
3-level hierarchy (cmd/inspect.go:26-248) — so each of the 25 leaves emits
a distinct command name. The shared path collapsed them into one event,
diverging from Go and destroying per-command usage/error attribution.

`legacyInspectDbRuntimeLayer` is now a factory taking the leaf name and
appending it to ["inspect","db"]; each command file passes its own cobra
`Use` name. Deprecated aliases record the alias the user typed (e.g.
`inspect db cache-hit`), not the backend command they delegate to, matching
Go's CommandPath() (cmd/inspect.go:139-247). Mirrors the sibling convention
in legacy-management-api-runtime.layer.ts:80.

@jgoux jgoux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one inline review finding.

Comment thread apps/cli/src/legacy/commands/inspect/db/legacy-inspect-query.ts
@Coly010 Coly010 added this pull request to the merge queue Jun 12, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 12, 2026
@Coly010 Coly010 added this pull request to the merge queue Jun 12, 2026
Merged via the queue into develop with commit 9b3cb17 Jun 12, 2026
12 checks passed
@Coly010 Coly010 deleted the cli/port-inspect-db branch June 12, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants