Skip to content

Commit 9609fa2

Browse files
bnjjjjgoux
andauthored
feat(cli): add warehouse tables list and get (#7689)
Generate `warehouse tables list` from `GET /v2/projects/{ref}/warehouse/tables`. It lists the tables selected for Warehouse replication with their freshness: - `status`: `syncing`, `live`, `error`, `stopped` or `unknown`; - the raw replication state; - when the state was observed; - `lag_ms`, the flush lag of the replication slot that carries the table. Text output shows one row per table. `-o json` and `-o yaml` also include the full replication feedback. That feedback includes `flush_lag_bytes`, which reads 0 for a caught-up slot whose lag time Postgres no longer reports. Also generate `warehouse tables get <table-id>` from `GET /v2/projects/{ref}/warehouse/tables/{table_id}`. It reads one of those tables by the source OID that `warehouse tables list` shows as its ID, with the same attributes. Its text output also shows the nested replication feedback, and a table that isn't replicated is an API error. This is the first generated command with a positional argument on a real operation, so the generic bindings test now supplies positional path parameters. Two generic changes to the text output of generated commands: - an empty collection prints `No results` instead of `Data -`; - a column that holds a nested object in any row is left out of the table. Before, rows with a nested object printed it as compact JSON while rows with `null` printed `-`. The tables contracts, and `flush_lag_bytes` in the status contract, come from OpenAPI overrides until they ship in the deployed Management API specification. Stacked on #7640. Depends on supabase/platform#42055 and supabase/platform#42108. Implements PIPE-1451 and PIPE-1453. --------- Co-authored-by: Julien Goux <hi@jgoux.dev>
1 parent d8edf25 commit 9609fa2

15 files changed

Lines changed: 1948 additions & 23 deletions

‎apps/cli/src/cli/command-surface/command-surface.integration.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ describe("command surface", () => {
5858
"warehouse disable",
5959
"warehouse enable",
6060
"warehouse status",
61+
"warehouse tables",
62+
"warehouse tables get",
63+
"warehouse tables list",
6164
"warehouse teardowns",
6265
"warehouse teardowns get",
6366
]);

‎apps/cli/src/commands/api/SIDE_EFFECTS.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,14 @@ Text rendering applies on a terminal by default, with `--output-format text` (al
145145
with `-o pretty`. Piped runs, agent runs, `--output-format json|stream-json` and `-o json` keep the
146146
API's JSON bytes. `-o` takes precedence over `--output-format`.
147147

148-
| Mode | stdout |
149-
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
150-
| text presentation | the response as labelled fields and tables, nested objects as indented blocks, `-` for null or empty values; with `--wait` the final read response; an empty response prints `Done.` |
151-
| JSON presentation | the API's JSON response bytes, unchanged, preserving unknown and null fields; with `--wait` the final read response |
152-
| `-o json` | the same bytes; no `target` key is added |
153-
| `-o yaml` | the same document as YAML; `-o pretty` selects text; other `-o` values are a usage error |
154-
| `--dry-run`, text presentation | `Dry run: <METHOD> <path>`, then `Query`, `Headers` and indented JSON `Body` blocks |
155-
| `--dry-run` otherwise | the request preview in the selected JSON or YAML presentation |
148+
| Mode | stdout |
149+
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
150+
| text presentation | the response as labelled fields and tables, nested objects as indented blocks (a collection table omits a column holding nested values; `-o json` shows them), `-` for null or empty values; with `--wait` the final read response; an empty response prints `Done.` and an empty collection `No results` |
151+
| JSON presentation | the API's JSON response bytes, unchanged, preserving unknown and null fields; with `--wait` the final read response |
152+
| `-o json` | the same bytes; no `target` key is added |
153+
| `-o yaml` | the same document as YAML; `-o pretty` selects text; other `-o` values are a usage error |
154+
| `--dry-run`, text presentation | `Dry run: <METHOD> <path>`, then `Query`, `Headers` and indented JSON `Body` blocks |
155+
| `--dry-run` otherwise | the request preview in the selected JSON or YAML presentation |
156156

157157
When the presentation is text and `--output-format` is `text`, each request, and with `--wait` the
158158
whole polling phase, runs under a task that shows the polled status after 200 ms. On a terminal it

‎apps/cli/src/commands/api/api-command-bindings.integration.test.ts‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const shapeOf = (schema: unknown): unknown => {
111111
const PATTERN_SAMPLES: Readonly<Record<string, string>> = {
112112
"^[a-f0-9]{64}$": "ab".repeat(32),
113113
"^[a-z]+$": "zyxwvutsrqponmlkjihg",
114+
"^[1-9]\\d*$": "16385",
114115
"^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$":
115116
"7579647f-2cdc-466c-982e-425958a2f985",
116117
};
@@ -198,6 +199,15 @@ const inputsOf = (
198199
return [...queries, ...fields];
199200
};
200201

202+
/** The path parameters besides `ref`, each supplied as a positional argument. */
203+
const positionalsOf = (operation: SpecOperation) =>
204+
operation.parameters
205+
.filter((parameter) => parameter["in"] === "path" && parameter["name"] !== "ref")
206+
.map((parameter) => ({
207+
name: String(parameter["name"]),
208+
sample: String(sampleOf(parameter["schema"])),
209+
}));
210+
201211
const argvOf = (inputs: ReadonlyArray<Input>): ReadonlyArray<string> =>
202212
inputs.flatMap((input) =>
203213
Array.isArray(input.sample)
@@ -330,13 +340,26 @@ describe("generated command bindings", () => {
330340
const { operationId } = row.api;
331341
const operation = operationOf(operationId);
332342
const inputs = inputsOf(operation, row.api.bindings);
333-
const expectedPath = operation.template.replace("{ref}", VALID_REF);
343+
const positionals = positionalsOf(operation);
344+
const expectedPath = positionals.reduce(
345+
(path, { name, sample }) => path.replace(`{${name}}`, sample),
346+
operation.template.replace("{ref}", VALID_REF),
347+
);
334348

335349
describe(row.path.join(" "), () => {
336350
it("binds the path reference and every other input to the spec's location", () => {
337-
expect(operation.template.match(/\{[^}]+\}/g)).toEqual(["{ref}"]);
351+
expect(operation.template.match(/\{[^}]+\}/g)).toEqual([
352+
"{ref}",
353+
...positionals.map(({ name }) => `{${name}}`),
354+
]);
338355
const expected = [
339356
{ location: "path", name: "ref", source: "target" },
357+
...positionals.map(({ name }) => ({
358+
location: "path",
359+
name,
360+
source: "argument",
361+
argument: generated.find((entry) => entry.operationId === operationId)?.argument?.name,
362+
})),
340363
...inputs.map((input) =>
341364
input.location === "query"
342365
? { location: "query", name: input.field, source: "flag", flag: input.flag }
@@ -356,7 +379,11 @@ describe("generated command bindings", () => {
356379

357380
it.effect("sends every input at its binding", () =>
358381
Effect.gen(function* () {
359-
const requests = yield* send(row.path, argvOf(inputs), operation.responseStatus);
382+
const requests = yield* send(
383+
row.path,
384+
[...positionals.map(({ sample }) => sample), ...argvOf(inputs)],
385+
operation.responseStatus,
386+
);
360387
expect(requests).toHaveLength(1);
361388
const [request] = requests;
362389
expect(request?.method).toBe(operation.method);
@@ -371,7 +398,11 @@ describe("generated command bindings", () => {
371398
it.effect("sends only the inputs the spec requires when no other flag is given", () =>
372399
Effect.gen(function* () {
373400
const required = inputs.filter((input) => input.required);
374-
const requests = yield* send(row.path, argvOf(required), operation.responseStatus);
401+
const requests = yield* send(
402+
row.path,
403+
[...positionals.map(({ sample }) => sample), ...argvOf(required)],
404+
operation.responseStatus,
405+
);
375406
expect(requests).toHaveLength(1);
376407
const [request] = requests;
377408
expect(Object.fromEntries(new URLSearchParams(request?.search))).toEqual(

‎apps/cli/src/commands/api/api-command-policy.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ export const generatedOperations: ReadonlyArray<OpenApiOperationId> = [
3636
"v2-enable-warehouse",
3737
"v2-disable-warehouse",
3838
"v2-get-warehouse-teardown",
39+
"v2-list-warehouse-tables",
40+
"v2-get-warehouse-table",
3941
];
4042

4143
export const nouns = {
4244
warehouse: {
4345
description: "Manage the data warehouse for a project",
4446
feature: "warehouse",
4547
groups: {
48+
tables: "Inspect tables replicated to Warehouse",
4649
teardowns: "Inspect Warehouse cleanup operations",
4750
},
4851
},

‎apps/cli/src/commands/api/api-command.format.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ const resourceLines = (document: JsonObject): ReadonlyArray<string> | undefined
132132
const keys = Object.keys(document);
133133
const data = document["data"];
134134
if (keys.length !== 1 || keys[0] !== "data") return undefined;
135+
if (Array.isArray(data) && data.length === 0) return ["No results"];
135136
if (isResource(data)) {
136137
return [humanize(String(data["type"])), ...blockLines(resourceEntries(data), INDENT)];
137138
}
138-
if (Array.isArray(data) && data.length > 0 && data.every(isResource)) {
139+
if (Array.isArray(data) && data.every(isResource)) {
139140
const rows = data.map((resource) => Object.fromEntries(resourceEntries(resource)));
140-
const columns = unionKeys(rows).filter((column) =>
141-
rows.some((row) => isScalar(row[column]) && row[column] !== undefined),
141+
const columns = unionKeys(rows).filter(
142+
(column) =>
143+
rows.every((row) => isScalar(row[column])) && rows.some((row) => row[column] !== undefined),
142144
);
143145
return [humanize(String(data[0]?.["type"])), ...objectTable(rows, columns, "")];
144146
}

‎apps/cli/src/commands/api/api-command.format.unit.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ describe("renderResponseText", () => {
3333
["Name n", "Limits", " Max 1", " Nested", " Deep yes", ""].join("\n"),
3434
);
3535
});
36+
37+
it("prints a clear line for an empty resource collection", () => {
38+
expect(renderResponseText({ data: [] })).toBe("No results\n");
39+
});
3640
});

‎apps/cli/src/commands/api/api-commands.integration.test.ts‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,117 @@ describe("generated warehouse commands", () => {
369369
});
370370
});
371371
});
372+
describe("warehouse tables list", () => {
373+
const tablesPath = `/v2/projects/${VALID_REF}/warehouse/tables`;
374+
const table = (attributes: Readonly<Record<string, unknown>>) => ({
375+
type: "warehouse_table",
376+
attributes: { schema: "public", ...attributes, observed_at: "2026-11-17T10:00:00Z" },
377+
});
378+
const body = {
379+
data: [
380+
{
381+
id: "16385",
382+
...table({
383+
name: "orders",
384+
warehouse_name: '"public"."orders"',
385+
status: "live",
386+
replication_state: "following_wal",
387+
lag_ms: 120,
388+
replication_feedback: {
389+
source: "pipeline_apply",
390+
active: true,
391+
wal_status: "reserved",
392+
write_lag_ms: 80,
393+
flush_lag_ms: 120,
394+
flush_lag_bytes: 2048,
395+
feedback_age_ms: 5,
396+
},
397+
}),
398+
},
399+
{
400+
id: "16402",
401+
...table({
402+
name: "events",
403+
warehouse_name: '"public"."events"',
404+
status: "syncing",
405+
replication_state: "copying_table",
406+
lag_ms: null,
407+
replication_feedback: null,
408+
}),
409+
},
410+
],
411+
};
412+
413+
it.effect("renders one row per table without the nested replication feedback", () => {
414+
const { out, sent, run } = setup(["warehouse", "tables", "list"], {
415+
route: ok(body),
416+
stdoutIsTty: true,
417+
});
418+
return Effect.gen(function* () {
419+
yield* run;
420+
expect(sent).toEqual([{ method: "GET", path: tablesPath, search: "", body: undefined }]);
421+
expect(out.stdoutText).toMatch(/16385\s.*orders.*live.*following_wal.*120/);
422+
expect(out.stdoutText).toMatch(/16402\s.*events.*syncing.*copying_table/);
423+
expect(out.stdoutText).not.toMatch(/pipeline_apply|feedback_age|FEEDBACK/i);
424+
});
425+
});
426+
427+
it.effect("passes the document, including replication feedback, through as JSON", () => {
428+
const { out, run } = setup(["warehouse", "tables", "list", "-o", "json"], {
429+
route: ok(body),
430+
});
431+
return Effect.gen(function* () {
432+
yield* run;
433+
expect(decodeJson(out.stdoutText)).toEqual(body);
434+
});
435+
});
436+
});
437+
describe("warehouse tables get", () => {
438+
const tablePath = `/v2/projects/${VALID_REF}/warehouse/tables/16385`;
439+
const body = {
440+
data: {
441+
id: "16385",
442+
type: "warehouse_table",
443+
attributes: {
444+
schema: "public",
445+
name: "orders",
446+
warehouse_name: '"public"."orders"',
447+
status: "live",
448+
replication_state: "following_wal",
449+
lag_ms: 120,
450+
observed_at: "2026-11-17T10:00:00Z",
451+
replication_feedback: {
452+
source: "pipeline_apply",
453+
active: true,
454+
wal_status: "reserved",
455+
write_lag_ms: 80,
456+
flush_lag_ms: 120,
457+
flush_lag_bytes: 2048,
458+
feedback_age_ms: 5,
459+
},
460+
},
461+
},
462+
};
463+
464+
it.effect(
465+
"requests the table by OID and renders its attributes and replication feedback",
466+
() => {
467+
const { out, sent, run } = setup(["warehouse", "tables", "get", "16385"], {
468+
route: ok(body),
469+
stdoutIsTty: true,
470+
});
471+
return Effect.gen(function* () {
472+
yield* run;
473+
expect(sent).toEqual([{ method: "GET", path: tablePath, search: "", body: undefined }]);
474+
expect(out.stdoutText).toMatch(/Warehouse table/);
475+
expect(out.stdoutText).toMatch(/Name\s+orders/);
476+
expect(out.stdoutText).toMatch(/Replication state\s+following_wal/);
477+
expect(out.stdoutText).toMatch(/Replication feedback\n\s+Source\s+pipeline_apply/);
478+
expect(out.stdoutText).toMatch(/Flush lag bytes\s+2048/);
479+
});
480+
},
481+
);
482+
});
372483
describe("warehouse connection", () => {
373484
const connectionPath = `/v2/projects/${VALID_REF}/warehouse/connection`;
374485
const host = `${VALID_REF}.warehouse.example.invalid`;

‎apps/cli/src/commands/api/generated.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,27 @@ Returns provisioning, configured compute, replication, cleanup lifecycle and sup
7777
- Feature: `warehouse`.
7878
- Request: `GET /v2/projects/{ref}/warehouse/status` (`v2-get-warehouse-status`), success 200 json.
7979

80+
## `supabase warehouse tables get`
81+
82+
Get a table replicated to Warehouse
83+
84+
Returns one source table selected for Warehouse replication by its source OID, from the same observations and with the same status and freshness attributes as the Warehouse tables list. Returns 404 when the table is not selected for replication, including when Warehouse is not set up, its publication is missing, or it is being disabled.
85+
86+
- Access: read-only, no consent.
87+
- Feature: `warehouse`.
88+
- Request: `GET /v2/projects/{ref}/warehouse/tables/{table_id}` (`v2-get-warehouse-table`), success 200 json.
89+
- Positional argument `<table-id>`, bound to path parameter `table_id`.
90+
91+
## `supabase warehouse tables list`
92+
93+
List tables replicated to Warehouse
94+
95+
Lists the source tables selected for Warehouse replication with their replication status and freshness, from the same observations as the Warehouse status. Freshness comes from the replication slot that carries each table: its own sync slot until it follows changes, then the pipeline apply slot; one slot never stands in for the other. lag_ms is that slot's flush lag. Postgres reports no lag time for a caught-up slot without new WAL, so lag_ms can be null while replication_feedback.flush_lag_bytes is 0; neither is ever filled with zero when unknown. observed_at is when the API read the replication state, not when data last synchronized. A stopped, failed or unreadable pipeline reports its tables as stopped or unknown rather than live, and keeps each table's last recorded state. Returns an empty list when Warehouse is not set up, its publication is missing, or it is being disabled or failed to clean up.
96+
97+
- Access: read-only, no consent.
98+
- Feature: `warehouse`.
99+
- Request: `GET /v2/projects/{ref}/warehouse/tables` (`v2-list-warehouse-tables`), success 200 json.
100+
80101
## `supabase warehouse teardowns get`
81102

82103
Get Warehouse cleanup status

0 commit comments

Comments
 (0)