Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ describe("command surface", () => {
"warehouse status",
"warehouse tables",
"warehouse tables get",
"warehouse tables layout",
"warehouse tables layout get",
"warehouse tables list",
"warehouse teardowns",
"warehouse teardowns get",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,19 @@ const operationOf = (operationId: string): SpecOperation => {
throw new Error(`${operationId} is not in openapi.json`);
};

/** The JSON Schema types of a node, with OpenAPI 3.0 `nullable` folded in as a `null` type. */
/**
* The JSON Schema types of a node, with OpenAPI 3.0 `nullable` and a `null` union branch folded in
* as a `null` type.
*/
const typesOf = (node: Json): ReadonlyArray<string> => {
const declared = node["type"];
const types = (Array.isArray(declared) ? declared : declared === undefined ? [] : [declared]).map(
String,
);
return (node["nullable"] === true ? [...types, "null"] : types)
const nullable =
node["nullable"] === true ||
asList(node["anyOf"]).some((branch) => asRecord(branch)["type"] === "null");
return (nullable ? [...types, "null"] : types)
.filter((type, index, all) => all.indexOf(type) === index)
.toSorted((a, b) => a.localeCompare(b));
};
Expand Down
2 changes: 2 additions & 0 deletions apps/cli/src/commands/api/api-command-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const generatedOperations: ReadonlyArray<OpenApiOperationId> = [
"v2-get-warehouse-teardown",
"v2-list-warehouse-tables",
"v2-get-warehouse-table",
"v2-get-warehouse-table-layout",
];

export const nouns = {
Expand All @@ -46,6 +47,7 @@ export const nouns = {
feature: "warehouse",
groups: {
tables: "Inspect tables replicated to Warehouse",
"tables.layout": "Inspect the layout of tables replicated to Warehouse",
teardowns: "Inspect Warehouse cleanup operations",
},
},
Expand Down
40 changes: 40 additions & 0 deletions apps/cli/src/commands/api/api-commands.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,46 @@ describe("generated warehouse commands", () => {
},
);
});
describe("warehouse tables layout get", () => {
const layoutPath = `/v2/projects/${VALID_REF}/warehouse/tables/16385/layout`;
const body = {
data: {
id: "16385",
type: "warehouse_table_layout",
attributes: {
schema: "public",
name: "events",
desired: {
sort_by: null,
partition_by: [{ column: "account_id", transform: { kind: "bucket", count: 16 } }],
},
observation_status: "observed",
observed: {
sort_by: [{ expression: '"created_at"', direction: "DESC", nulls: "NULLS_LAST" }],
partition_by: [{ column: "account_id", transform: "bucket(16)" }],
observed_at: "2026-11-18T09:30:00.123456Z",
},
},
},
};

it.effect("renders unmanaged desired sorting beside the observed catalog layout", () => {
const { out, sent, run } = setup(["warehouse", "tables", "layout", "get", "16385"], {
route: ok(body),
stdoutIsTty: true,
});
return Effect.gen(function* () {
yield* run;
expect(sent).toEqual([{ method: "GET", path: layoutPath, search: "", body: undefined }]);
expect(out.stdoutText).toMatch(/^Warehouse table layout\n/);
expect(out.stdoutText).toMatch(/Desired\n\s+Sort by\s+-\n/);
expect(out.stdoutText).toMatch(/account_id \| \{"kind":"bucket","count":16\}/);
expect(out.stdoutText).toMatch(/Observation status\s+observed/);
expect(out.stdoutText).toMatch(/account_id \| bucket\(16\)/);
expect(out.stdoutText).toMatch(/Observed at\s+2026-11-18T09:30:00\.123456Z/);
});
});
Comment on lines +506 to +521

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.

⚪ NIT · test-coverage · source: claude

The new integration test covers only a populated observed object. It does not verify that the CLI still displays the desired rules when the catalog layout is unavailable and observed is null.

Evidence: apps/cli/src/commands/api/api-commands.integration.test.ts:496 sets the status to observed and supplies a populated object. packages/api/src/generated/contracts.ts:15315 allows null, and packages/api/scripts/openapi-overrides.json:1771 documents when it occurs.

Suggested fix: Add a text-mode case with observation_status: "table_missing", observed: null, and desired: { sort_by: { kind: "none" }, partition_by: [] }. Assert that the output still shows the desired rules and renders Observed as -.

});
describe("warehouse connection", () => {
const connectionPath = `/v2/projects/${VALID_REF}/warehouse/connection`;
const host = `${VALID_REF}.warehouse.example.invalid`;
Expand Down
11 changes: 11 additions & 0 deletions apps/cli/src/commands/api/generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ Returns one source table selected for Warehouse replication by its source OID, f
- Request: `GET /v2/projects/{ref}/warehouse/tables/{table_id}` (`v2-get-warehouse-table`), success 200 json.
- Positional argument `<table-id>`, bound to path parameter `table_id`.

## `supabase warehouse tables layout get`

Get the layout of a table replicated to Warehouse

Returns the sorting and partitioning rules saved for one replicated table, by source OID, beside the layout the DuckLake catalog records for it. The two are reported separately and can differ: the replicator applies saved rules when it starts and then hourly, and a stopped pipeline applies them on its next start. observation_status reports whether the catalog was read; desired rules are returned even when it was not. A catalog layout governs files written after it changes and does not establish that existing files are sorted or partitioned. Returns 404 when the table is not replicated, including when Warehouse is not set up, is being disabled or failed to clean up.

- Access: read-only, no consent.
- Feature: `warehouse`.
- Request: `GET /v2/projects/{ref}/warehouse/tables/{table_id}/layout` (`v2-get-warehouse-table-layout`), success 200 json.
- Positional argument `<table-id>`, bound to path parameter `table_id`.

## `supabase warehouse tables list`

List tables replicated to Warehouse
Expand Down
258 changes: 258 additions & 0 deletions apps/cli/src/commands/api/generated.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,264 @@ export const apiCommandSchemas = {
type: "object",
},
},
"v2-get-warehouse-table-layout": {
result: {
$schema: "https://json-schema.org/draft/2020-12/schema",
properties: {
data: {
properties: {
attributes: {
properties: {
desired: {
description:
"Saved layout rules. The replicator applies them on start and hourly, so they can differ from the observed layout.",
properties: {
partition_by: {
description:
"Configured partition keys in order. An empty list explicitly clears partitioning; null leaves it unmanaged.",
items: {
properties: {
column: {
description: "Source column name.",
type: "string",
},
transform: {
oneOf: [
{
properties: {
kind: {
enum: ["identity"],
type: "string",
},
},
required: ["kind"],
type: "object",
},
{
properties: {
kind: {
enum: ["year"],
type: "string",
},
},
required: ["kind"],
type: "object",
},
{
properties: {
kind: {
enum: ["month"],
type: "string",
},
},
required: ["kind"],
type: "object",
},
{
properties: {
kind: {
enum: ["day"],
type: "string",
},
},
required: ["kind"],
type: "object",
},
{
properties: {
kind: {
enum: ["hour"],
type: "string",
},
},
required: ["kind"],
type: "object",
},
{
properties: {
count: {
description: "Number of hash buckets.",
maximum: 2147483647,
type: "integer",
exclusiveMinimum: 0,
},
kind: {
enum: ["bucket"],
type: "string",
},
},
required: ["count", "kind"],
type: "object",
},
],
},
},
required: ["column", "transform"],
type: "object",
},
type: ["array", "null"],
},
sort_by: {
anyOf: [
{
description:
"Configured sort order. none explicitly clears sorting, primary_key sorts by the source primary-key columns in key order, and columns lists them. Null leaves sorting unmanaged.",
oneOf: [
{
properties: {
kind: {
enum: ["none"],
type: "string",
},
},
required: ["kind"],
type: "object",
},
{
properties: {
kind: {
enum: ["primary_key"],
type: "string",
},
},
required: ["kind"],
type: "object",
},
{
properties: {
columns: {
items: {
properties: {
direction: {
enum: ["asc", "desc"],
type: "string",
},
name: {
description: "Source column name.",
type: "string",
},
nulls: {
description:
"Null placement. Null uses DuckLake's default placement.",
enum: ["first", "last", null],
type: ["string", "null"],
},
},
required: ["direction", "name", "nulls"],
type: "object",
},
type: "array",
},
kind: {
enum: ["columns"],
type: "string",
},
},
required: ["columns", "kind"],
type: "object",
},
],
},
{
type: "null",
},
],
},
},
required: ["partition_by", "sort_by"],
type: "object",
},
name: {
description: "Source PostgreSQL table name.",
type: "string",
},
observation_status: {
description:
"observed when the DuckLake catalog was read, table_missing when the catalog has no table for it yet, and unavailable when the catalog could not be read.",
enum: ["observed", "table_missing", "unavailable"],
type: "string",
},
observed: {
description:
"Layout recorded in the DuckLake catalog, null unless observation_status is observed. Catalog metadata governs files written after it changes and does not establish that existing files are sorted or partitioned.",
properties: {
observed_at: {
description: "Time the catalog metadata was read.",
format: "date-time",
pattern:
"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$",
type: "string",
},
partition_by: {
description:
"Active partition keys in key order, with transforms as the catalog reports them, for example bucket(16).",
items: {
properties: {
column: {
type: "string",
},
transform: {
type: "string",
},
},
required: ["column", "transform"],
type: "object",
},
type: "array",
},
sort_by: {
description:
"Active sort expressions in key order, as the catalog reports them.",
items: {
properties: {
direction: {
type: "string",
},
expression: {
type: "string",
},
nulls: {
type: "string",
},
},
required: ["direction", "expression", "nulls"],
type: "object",
},
type: "array",
},
},
required: ["observed_at", "partition_by", "sort_by"],
type: ["object", "null"],
},
schema: {
description: "Source PostgreSQL schema of the table.",
type: "string",
},
},
required: ["desired", "name", "observation_status", "observed", "schema"],
type: "object",
},
id: {
description: "Source PostgreSQL table OID, as returned by the Warehouse tables list.",
maxLength: 10,
pattern: "^[1-9]\\d*$",
type: "string",
examples: ["16385"],
},
type: {
description: "Resource type.",
enum: ["warehouse_table_layout"],
type: "string",
},
},
required: ["attributes", "id", "type"],
type: "object",
},
},
required: ["data"],
type: "object",
},
},
"v2-get-warehouse-teardown": {
result: {
$schema: "https://json-schema.org/draft/2020-12/schema",
Expand Down
Loading
Loading