From bdcabcb617cefacb1ebf3560731fa756facac92b Mon Sep 17 00:00:00 2001 From: Benjamin <5719034+bnjjj@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:13:28 +0100 Subject: [PATCH 1/5] feat(cli): add warehouse tables list Add the generated `warehouse tables list` command for the Management API tables listing, and the matching `flush_lag_bytes` replication feedback in the Warehouse status contract. Both contracts come from spec overrides until the deployed specification includes them. Render an empty resource collection as `No results` and leave out columns that hold nested objects in any row, so nullable nested values no longer print as compact JSON in the table. --- .../command-surface.integration.test.ts | 2 + .../src/commands/api/api-command-policy.ts | 2 + .../src/commands/api/api-command.format.ts | 6 +- .../api/api-command.format.unit.test.ts | 4 + .../api/api-commands.integration.test.ts | 65 +++++ apps/cli/src/commands/api/generated.md | 10 + .../cli/src/commands/api/generated.schemas.ts | 154 +++++++++- apps/cli/src/commands/api/generated.ts | 24 ++ packages/api/scripts/openapi-overrides.json | 271 +++++++++++++++++- packages/api/src/generated/contracts.ts | 190 +++++++++++- packages/api/src/generated/effect-client.ts | 16 ++ packages/api/src/generated/openapi.json | 261 ++++++++++++++++- packages/api/src/generated/permissions.ts | 1 + 13 files changed, 996 insertions(+), 10 deletions(-) diff --git a/apps/cli/src/cli/command-surface/command-surface.integration.test.ts b/apps/cli/src/cli/command-surface/command-surface.integration.test.ts index 332a77030b..98fef115c9 100644 --- a/apps/cli/src/cli/command-surface/command-surface.integration.test.ts +++ b/apps/cli/src/cli/command-surface/command-surface.integration.test.ts @@ -58,6 +58,8 @@ describe("command surface", () => { "warehouse disable", "warehouse enable", "warehouse status", + "warehouse tables", + "warehouse tables list", "warehouse teardowns", "warehouse teardowns get", ]); diff --git a/apps/cli/src/commands/api/api-command-policy.ts b/apps/cli/src/commands/api/api-command-policy.ts index 84ac2640a1..0c7bb94bac 100644 --- a/apps/cli/src/commands/api/api-command-policy.ts +++ b/apps/cli/src/commands/api/api-command-policy.ts @@ -32,6 +32,7 @@ export const generatedOperations: ReadonlyArray = [ "v2-enable-warehouse", "v2-disable-warehouse", "v2-get-warehouse-teardown", + "v2-list-warehouse-tables", ]; export const nouns = { @@ -39,6 +40,7 @@ export const nouns = { description: "Manage the data warehouse for a project", feature: "warehouse", groups: { + tables: "List tables replicated to Warehouse", teardowns: "Inspect Warehouse cleanup operations", }, }, diff --git a/apps/cli/src/commands/api/api-command.format.ts b/apps/cli/src/commands/api/api-command.format.ts index b4d08c4c41..42ae26f95d 100644 --- a/apps/cli/src/commands/api/api-command.format.ts +++ b/apps/cli/src/commands/api/api-command.format.ts @@ -132,13 +132,15 @@ const resourceLines = (document: JsonObject): ReadonlyArray | undefined const keys = Object.keys(document); const data = document["data"]; if (keys.length !== 1 || keys[0] !== "data") return undefined; + if (Array.isArray(data) && data.length === 0) return ["No results"]; if (isResource(data)) { return [humanize(String(data["type"])), ...blockLines(resourceEntries(data), INDENT)]; } if (Array.isArray(data) && data.length > 0 && data.every(isResource)) { const rows = data.map((resource) => Object.fromEntries(resourceEntries(resource))); - const columns = unionKeys(rows).filter((column) => - rows.some((row) => isScalar(row[column]) && row[column] !== undefined), + const columns = unionKeys(rows).filter( + (column) => + rows.every((row) => isScalar(row[column])) && rows.some((row) => row[column] !== undefined), ); return [humanize(String(data[0]?.["type"])), ...objectTable(rows, columns, "")]; } diff --git a/apps/cli/src/commands/api/api-command.format.unit.test.ts b/apps/cli/src/commands/api/api-command.format.unit.test.ts index 60621a4a4e..c8fb7997b5 100644 --- a/apps/cli/src/commands/api/api-command.format.unit.test.ts +++ b/apps/cli/src/commands/api/api-command.format.unit.test.ts @@ -33,4 +33,8 @@ describe("renderResponseText", () => { ["Name n", "Limits", " Max 1", " Nested", " Deep yes", ""].join("\n"), ); }); + + it("prints a clear line for an empty resource collection", () => { + expect(renderResponseText({ data: [] })).toBe("No results\n"); + }); }); diff --git a/apps/cli/src/commands/api/api-commands.integration.test.ts b/apps/cli/src/commands/api/api-commands.integration.test.ts index 43ee32e503..76f4ef4117 100644 --- a/apps/cli/src/commands/api/api-commands.integration.test.ts +++ b/apps/cli/src/commands/api/api-commands.integration.test.ts @@ -369,6 +369,71 @@ describe("generated warehouse commands", () => { }); }); }); + describe("warehouse tables list", () => { + const tablesPath = `/v2/projects/${VALID_REF}/warehouse/tables`; + const table = (attributes: Readonly>) => ({ + type: "warehouse_table", + attributes: { schema: "public", ...attributes, observed_at: "2026-11-17T10:00:00Z" }, + }); + const body = { + data: [ + { + id: "16385", + ...table({ + name: "orders", + warehouse_name: '"public"."orders"', + status: "live", + replication_state: "following_wal", + lag_ms: 120, + replication_feedback: { + source: "pipeline_apply", + active: true, + wal_status: "reserved", + write_lag_ms: 80, + flush_lag_ms: 120, + flush_lag_bytes: 2048, + feedback_age_ms: 5, + }, + }), + }, + { + id: "16402", + ...table({ + name: "events", + warehouse_name: '"public"."events"', + status: "syncing", + replication_state: "copying_table", + lag_ms: null, + replication_feedback: null, + }), + }, + ], + }; + + it.effect("renders one row per table without the nested replication feedback", () => { + const { out, sent, run } = setup(["warehouse", "tables", "list"], { + route: ok(body), + stdoutIsTty: true, + }); + return Effect.gen(function* () { + yield* run; + expect(sent).toEqual([{ method: "GET", path: tablesPath, search: "", body: undefined }]); + expect(out.stdoutText).toMatch(/16385\s.*orders.*live.*following_wal.*120/); + expect(out.stdoutText).toMatch(/16402\s.*events.*syncing.*copying_table/); + expect(out.stdoutText).not.toMatch(/pipeline_apply|feedback_age|FEEDBACK/i); + }); + }); + + it.effect("passes the document, including replication feedback, through as JSON", () => { + const { out, run } = setup(["warehouse", "tables", "list", "-o", "json"], { + route: ok(body), + }); + return Effect.gen(function* () { + yield* run; + expect(decodeJson(out.stdoutText)).toEqual(body); + }); + }); + }); describe("warehouse connection", () => { const connectionPath = `/v2/projects/${VALID_REF}/warehouse/connection`; const host = `${VALID_REF}.warehouse.example.invalid`; diff --git a/apps/cli/src/commands/api/generated.md b/apps/cli/src/commands/api/generated.md index c125f91a7f..a029234184 100644 --- a/apps/cli/src/commands/api/generated.md +++ b/apps/cli/src/commands/api/generated.md @@ -77,6 +77,16 @@ Returns provisioning, configured compute, replication, cleanup lifecycle and sup - Feature: `warehouse`. - Request: `GET /v2/projects/{ref}/warehouse/status` (`v2-get-warehouse-status`), success 200 json. +## `supabase warehouse tables list` + +List tables replicated to Warehouse + +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. + +- Access: read-only, no consent. +- Feature: `warehouse`. +- Request: `GET /v2/projects/{ref}/warehouse/tables` (`v2-list-warehouse-tables`), success 200 json. + ## `supabase warehouse teardowns get` Get Warehouse cleanup status diff --git a/apps/cli/src/commands/api/generated.schemas.ts b/apps/cli/src/commands/api/generated.schemas.ts index 2da968df4a..b0c10c0bbc 100644 --- a/apps/cli/src/commands/api/generated.schemas.ts +++ b/apps/cli/src/commands/api/generated.schemas.ts @@ -843,7 +843,7 @@ export const apiCommandSchemas = { properties: { apply_lag: { description: - "Postgres replication feedback. Null means unknown. Feedback age measures time since the last response and does not establish how current query results are.", + "Postgres replication feedback. Null means Postgres reported no value; lag times also become null shortly after a caught-up slot sees no new WAL, while flush_lag_bytes, the WAL not yet confirmed flushed, reads 0. Feedback age measures time since the last response and does not establish how current query results are.", properties: { active: { type: "boolean", @@ -852,6 +852,11 @@ export const apiCommandSchemas = { minimum: 0, type: ["number", "null"], }, + flush_lag_bytes: { + maximum: 9007199254740991, + minimum: 0, + type: ["integer", "null"], + }, flush_lag_ms: { minimum: 0, type: ["number", "null"], @@ -868,6 +873,7 @@ export const apiCommandSchemas = { required: [ "active", "feedback_age_ms", + "flush_lag_bytes", "flush_lag_ms", "wal_status", "write_lag_ms", @@ -952,7 +958,7 @@ export const apiCommandSchemas = { }, sync_lag: { description: - "Postgres replication feedback. Null means unknown. Feedback age measures time since the last response and does not establish how current query results are.", + "Postgres replication feedback. Null means Postgres reported no value; lag times also become null shortly after a caught-up slot sees no new WAL, while flush_lag_bytes, the WAL not yet confirmed flushed, reads 0. Feedback age measures time since the last response and does not establish how current query results are.", properties: { active: { type: "boolean", @@ -961,6 +967,11 @@ export const apiCommandSchemas = { minimum: 0, type: ["number", "null"], }, + flush_lag_bytes: { + maximum: 9007199254740991, + minimum: 0, + type: ["integer", "null"], + }, flush_lag_ms: { minimum: 0, type: ["number", "null"], @@ -984,6 +995,7 @@ export const apiCommandSchemas = { required: [ "active", "feedback_age_ms", + "flush_lag_bytes", "flush_lag_ms", "wal_status", "write_lag_ms", @@ -1114,4 +1126,142 @@ export const apiCommandSchemas = { required: ["data"], }, }, + "v2-list-warehouse-tables": { + result: { + $schema: "https://json-schema.org/draft/2020-12/schema", + properties: { + data: { + items: { + properties: { + attributes: { + properties: { + lag_ms: { + description: + "Flush lag in milliseconds that Postgres reports for the slot in replication_feedback. Null when there is no feedback or Postgres reports no recent measurement, which includes a caught-up slot without new WAL; replication_feedback.flush_lag_bytes reads 0 in that case.", + minimum: 0, + type: ["number", "null"], + }, + name: { + description: "Source PostgreSQL table name.", + type: "string", + }, + observed_at: { + description: + "Time the API retrieved the replication state of the table. It does not indicate when data was last synchronized.", + 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", "null"], + }, + replication_feedback: { + description: + "Postgres feedback from the replication slot named in source. Null when no feedback is available, including while the pipeline is stopped. Feedback age measures time since the slot last responded and does not establish how current query results are.", + properties: { + active: { + type: "boolean", + }, + feedback_age_ms: { + minimum: 0, + type: ["number", "null"], + }, + flush_lag_bytes: { + maximum: 9007199254740991, + minimum: 0, + type: ["integer", "null"], + }, + flush_lag_ms: { + minimum: 0, + type: ["number", "null"], + }, + source: { + description: + "Replication slot that reported the feedback: the table's own sync slot until it follows changes, or the pipeline apply slot once it does.", + enum: ["pipeline_apply", "table_sync"], + type: "string", + }, + wal_status: { + enum: ["extended", "lost", null, "reserved", "unknown", "unreserved"], + type: ["string", "null"], + }, + write_lag_ms: { + minimum: 0, + type: ["number", "null"], + }, + }, + required: [ + "active", + "feedback_age_ms", + "flush_lag_bytes", + "flush_lag_ms", + "source", + "wal_status", + "write_lag_ms", + ], + type: ["object", "null"], + }, + replication_state: { + description: + "Last replication state the pipeline recorded for the table, also while the pipeline is stopped. Null when none was observed.", + enum: [ + "copied_table", + "copying_table", + "error", + "following_wal", + null, + "queued", + ], + type: ["string", "null"], + }, + schema: { + description: "Source PostgreSQL schema of the table.", + type: "string", + }, + status: { + description: + "Replication status. error means the table failed to replicate; stopped means the pipeline is stopped, stopping or failed, so the table receives no changes; live means the table follows changes; syncing means it is queued, copying or catching up; unknown means the pipeline status or the table state was not observed, for example before replication starts.", + enum: ["error", "live", "stopped", "syncing", "unknown"], + type: "string", + }, + warehouse_name: { + description: + "Quoted, fully qualified name of the replicated table in the Warehouse.", + type: "string", + }, + }, + required: [ + "lag_ms", + "name", + "observed_at", + "replication_feedback", + "replication_state", + "schema", + "status", + "warehouse_name", + ], + 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"], + type: "string", + }, + }, + required: ["attributes", "id", "type"], + type: "object", + }, + type: "array", + }, + }, + required: ["data"], + type: "object", + }, + }, } as const satisfies Readonly>; diff --git a/apps/cli/src/commands/api/generated.ts b/apps/cli/src/commands/api/generated.ts index dd7c0ea679..12d5c4ac30 100644 --- a/apps/cli/src/commands/api/generated.ts +++ b/apps/cli/src/commands/api/generated.ts @@ -214,6 +214,30 @@ export const apiCommands = [ }, ], }, + { + command: ["warehouse", "tables", "list"], + operationId: "v2-list-warehouse-tables", + definition: "v2ListWarehouseTables", + method: "GET", + apiPath: "/v2/projects/{ref}/warehouse/tables", + summary: "List tables replicated to Warehouse", + description: + "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.", + readOnly: true, + feature: "warehouse", + response: { + status: 200, + kind: "json", + }, + flags: [], + bindings: [ + { + location: "path", + name: "ref", + source: "target", + }, + ], + }, { command: ["warehouse", "teardowns", "get"], operationId: "v2-get-warehouse-teardown", diff --git a/packages/api/scripts/openapi-overrides.json b/packages/api/scripts/openapi-overrides.json index af1f8546bb..6082674da0 100644 --- a/packages/api/scripts/openapi-overrides.json +++ b/packages/api/scripts/openapi-overrides.json @@ -441,7 +441,7 @@ "replication": { "properties": { "apply_lag": { - "description": "Postgres replication feedback. Null means unknown. Feedback age measures time since the last response and does not establish how current query results are.", + "description": "Postgres replication feedback. Null means Postgres reported no value; lag times also become null shortly after a caught-up slot sees no new WAL, while flush_lag_bytes, the WAL not yet confirmed flushed, reads 0. Feedback age measures time since the last response and does not establish how current query results are.", "nullable": true, "properties": { "active": { @@ -452,6 +452,12 @@ "nullable": true, "type": "number" }, + "flush_lag_bytes": { + "maximum": 9007199254740991, + "minimum": 0, + "nullable": true, + "type": "integer" + }, "flush_lag_ms": { "minimum": 0, "nullable": true, @@ -471,6 +477,7 @@ "required": [ "active", "feedback_age_ms", + "flush_lag_bytes", "flush_lag_ms", "wal_status", "write_lag_ms" @@ -555,7 +562,7 @@ "type": "string" }, "sync_lag": { - "description": "Postgres replication feedback. Null means unknown. Feedback age measures time since the last response and does not establish how current query results are.", + "description": "Postgres replication feedback. Null means Postgres reported no value; lag times also become null shortly after a caught-up slot sees no new WAL, while flush_lag_bytes, the WAL not yet confirmed flushed, reads 0. Feedback age measures time since the last response and does not establish how current query results are.", "nullable": true, "properties": { "active": { @@ -566,6 +573,12 @@ "nullable": true, "type": "number" }, + "flush_lag_bytes": { + "maximum": 9007199254740991, + "minimum": 0, + "nullable": true, + "type": "integer" + }, "flush_lag_ms": { "minimum": 0, "nullable": true, @@ -592,6 +605,7 @@ "required": [ "active", "feedback_age_ms", + "flush_lag_bytes", "flush_lag_ms", "wal_status", "write_lag_ms" @@ -943,6 +957,259 @@ }, "$comment": "The Warehouse Flight SQL connection contract is not yet in the deployed Management API specification." }, + { + "op": "add", + "path": "/paths/~1v2~1projects~1{ref}~1warehouse~1tables", + "value": { + "get": { + "description": "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.\n\nThis endpoint is currently in its **Alpha** stage.", + "operationId": "v2-list-warehouse-tables", + "parameters": [ + { + "description": "Project ref", + "in": "path", + "name": "ref", + "required": true, + "schema": { + "example": "abcdefghijklmnopqrst", + "maxLength": 20, + "minLength": 20, + "pattern": "^[a-z]+$", + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/V2WarehouseTablesResponse_Output" + } + } + }, + "description": "" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Unauthorized" + }, + "403": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Forbidden action" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Warehouse DuckLake destination not found" + }, + "429": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Rate limit exceeded" + }, + "503": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Warehouse feature, project metadata or table selection unavailable" + } + }, + "security": [ + { + "bearer": [] + } + ], + "summary": "List tables replicated to Warehouse", + "tags": ["Projects Warehouse"], + "x-badges": [ + { + "name": "OAuth scope: database:read", + "position": "after" + }, + { + "name": "Alpha", + "position": "before" + } + ], + "x-endpoint-owners": ["pipelines"], + "x-fga-permissions": [["database_read"]], + "x-oauth-scope": "database:read", + "x-operation": { + "group": "warehouse.tables", + "method": "list" + }, + "x-scalar-stability": "experimental" + } + }, + "$comment": "The Warehouse tables listing contract is not yet in the deployed Management API specification." + }, + { + "op": "add", + "path": "/components/schemas/V2WarehouseTablesResponse_Output", + "value": { + "properties": { + "data": { + "items": { + "properties": { + "attributes": { + "properties": { + "lag_ms": { + "description": "Flush lag in milliseconds that Postgres reports for the slot in replication_feedback. Null when there is no feedback or Postgres reports no recent measurement, which includes a caught-up slot without new WAL; replication_feedback.flush_lag_bytes reads 0 in that case.", + "minimum": 0, + "nullable": true, + "type": "number" + }, + "name": { + "description": "Source PostgreSQL table name.", + "type": "string" + }, + "observed_at": { + "description": "Time the API retrieved the replication state of the table. It does not indicate when data was last synchronized.", + "format": "date-time", + "nullable": true, + "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" + }, + "replication_feedback": { + "description": "Postgres feedback from the replication slot named in source. Null when no feedback is available, including while the pipeline is stopped. Feedback age measures time since the slot last responded and does not establish how current query results are.", + "nullable": true, + "properties": { + "active": { + "type": "boolean" + }, + "feedback_age_ms": { + "minimum": 0, + "nullable": true, + "type": "number" + }, + "flush_lag_bytes": { + "maximum": 9007199254740991, + "minimum": 0, + "nullable": true, + "type": "integer" + }, + "flush_lag_ms": { + "minimum": 0, + "nullable": true, + "type": "number" + }, + "source": { + "description": "Replication slot that reported the feedback: the table's own sync slot until it follows changes, or the pipeline apply slot once it does.", + "enum": ["pipeline_apply", "table_sync"], + "type": "string" + }, + "wal_status": { + "enum": ["extended", "lost", null, "reserved", "unknown", "unreserved"], + "nullable": true, + "type": "string" + }, + "write_lag_ms": { + "minimum": 0, + "nullable": true, + "type": "number" + } + }, + "required": [ + "active", + "feedback_age_ms", + "flush_lag_bytes", + "flush_lag_ms", + "source", + "wal_status", + "write_lag_ms" + ], + "type": "object" + }, + "replication_state": { + "description": "Last replication state the pipeline recorded for the table, also while the pipeline is stopped. Null when none was observed.", + "enum": [ + "copied_table", + "copying_table", + "error", + "following_wal", + null, + "queued" + ], + "nullable": true, + "type": "string" + }, + "schema": { + "description": "Source PostgreSQL schema of the table.", + "type": "string" + }, + "status": { + "description": "Replication status. error means the table failed to replicate; stopped means the pipeline is stopped, stopping or failed, so the table receives no changes; live means the table follows changes; syncing means it is queued, copying or catching up; unknown means the pipeline status or the table state was not observed, for example before replication starts.", + "enum": ["error", "live", "stopped", "syncing", "unknown"], + "type": "string" + }, + "warehouse_name": { + "description": "Quoted, fully qualified name of the replicated table in the Warehouse.", + "type": "string" + } + }, + "required": [ + "lag_ms", + "name", + "observed_at", + "replication_feedback", + "replication_state", + "schema", + "status", + "warehouse_name" + ], + "type": "object" + }, + "id": { + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + }, + "type": { + "description": "Resource type.", + "enum": ["warehouse_table"], + "type": "string" + } + }, + "required": ["attributes", "id", "type"], + "type": "object" + }, + "type": "array" + } + }, + "required": ["data"], + "type": "object" + }, + "$comment": "The Warehouse tables listing contract is not yet in the deployed Management API specification." + }, { "op": "test", "path": "/paths/~1v2~1projects~1{ref}~1warehouse~1setups~1current/get/x-operation", diff --git a/packages/api/src/generated/contracts.ts b/packages/api/src/generated/contracts.ts index d010fc3ebf..1d8e94b757 100644 --- a/packages/api/src/generated/contracts.ts +++ b/packages/api/src/generated/contracts.ts @@ -14824,6 +14824,20 @@ export const V2GetWarehouseStatusOutput = Schema.Struct({ ), Schema.Null, ]), + flush_lag_bytes: Schema.Union([ + Schema.Number.check(Schema.isInt().annotate({ expected: "an integer" })) + .check( + Schema.isGreaterThanOrEqualTo(0).annotate({ + expected: "a value greater than or equal to 0", + }), + ) + .check( + Schema.isLessThanOrEqualTo(9007199254740991).annotate({ + expected: "a value less than or equal to 9007199254740991", + }), + ), + Schema.Null, + ]), flush_lag_ms: Schema.Union([ Schema.Number.check( Schema.isFinite().annotate({ expected: "a finite number" }), @@ -14853,7 +14867,7 @@ export const V2GetWarehouseStatusOutput = Schema.Struct({ ]), }).annotate({ description: - "Postgres replication feedback. Null means unknown. Feedback age measures time since the last response and does not establish how current query results are.", + "Postgres replication feedback. Null means Postgres reported no value; lag times also become null shortly after a caught-up slot sees no new WAL, while flush_lag_bytes, the WAL not yet confirmed flushed, reads 0. Feedback age measures time since the last response and does not establish how current query results are.", }), Schema.Null, ]), @@ -14944,6 +14958,20 @@ export const V2GetWarehouseStatusOutput = Schema.Struct({ ), Schema.Null, ]), + flush_lag_bytes: Schema.Union([ + Schema.Number.check(Schema.isInt().annotate({ expected: "an integer" })) + .check( + Schema.isGreaterThanOrEqualTo(0).annotate({ + expected: "a value greater than or equal to 0", + }), + ) + .check( + Schema.isLessThanOrEqualTo(9007199254740991).annotate({ + expected: "a value less than or equal to 9007199254740991", + }), + ), + Schema.Null, + ]), flush_lag_ms: Schema.Union([ Schema.Number.check( Schema.isFinite().annotate({ expected: "a finite number" }), @@ -14973,7 +15001,7 @@ export const V2GetWarehouseStatusOutput = Schema.Struct({ ]), }).annotate({ description: - "Postgres replication feedback. Null means unknown. Feedback age measures time since the last response and does not establish how current query results are.", + "Postgres replication feedback. Null means Postgres reported no value; lag times also become null shortly after a caught-up slot sees no new WAL, while flush_lag_bytes, the WAL not yet confirmed flushed, reads 0. Feedback age measures time since the last response and does not establish how current query results are.", }), Schema.Null, ]), @@ -16072,6 +16100,149 @@ export const V2ListPrivateLinkAssociationsOutput = Schema.Struct({ }), ), }); +export const V2ListWarehouseTablesInput = Schema.Struct({ + ref: Schema.String.check( + Schema.isMinCodePoints(20).annotate({ expected: "a string with at least 20 code points" }), + ) + .check( + Schema.isMaxCodePoints(20).annotate({ expected: "a string with at most 20 code points" }), + ) + .check( + Schema.isPattern(new RegExp("^[a-z]+$", "u")).annotate({ + expected: "a string matching the RegExp ^[a-z]+$", + }), + ), +}); +export const V2ListWarehouseTablesOutput = Schema.Struct({ + data: Schema.Array( + Schema.Struct({ + attributes: Schema.Struct({ + lag_ms: Schema.Union([ + Schema.Number.annotate({ + description: + "Flush lag in milliseconds that Postgres reports for the slot in replication_feedback. Null when there is no feedback or Postgres reports no recent measurement, which includes a caught-up slot without new WAL; replication_feedback.flush_lag_bytes reads 0 in that case.", + }) + .check(Schema.isFinite().annotate({ expected: "a finite number" })) + .check( + Schema.isGreaterThanOrEqualTo(0).annotate({ + expected: "a value greater than or equal to 0", + }), + ), + Schema.Null, + ]), + name: Schema.String.annotate({ description: "Source PostgreSQL table name." }), + observed_at: Schema.Union([ + Schema.String.annotate({ + description: + "Time the API retrieved the replication state of the table. It does not indicate when data was last synchronized.", + format: "date-time", + }), + Schema.Null, + ]), + replication_feedback: Schema.Union([ + Schema.Struct({ + active: Schema.Boolean, + feedback_age_ms: Schema.Union([ + Schema.Number.check( + Schema.isFinite().annotate({ expected: "a finite number" }), + ).check( + Schema.isGreaterThanOrEqualTo(0).annotate({ + expected: "a value greater than or equal to 0", + }), + ), + Schema.Null, + ]), + flush_lag_bytes: Schema.Union([ + Schema.Number.check(Schema.isInt().annotate({ expected: "an integer" })) + .check( + Schema.isGreaterThanOrEqualTo(0).annotate({ + expected: "a value greater than or equal to 0", + }), + ) + .check( + Schema.isLessThanOrEqualTo(9007199254740991).annotate({ + expected: "a value less than or equal to 9007199254740991", + }), + ), + Schema.Null, + ]), + flush_lag_ms: Schema.Union([ + Schema.Number.check( + Schema.isFinite().annotate({ expected: "a finite number" }), + ).check( + Schema.isGreaterThanOrEqualTo(0).annotate({ + expected: "a value greater than or equal to 0", + }), + ), + Schema.Null, + ]), + source: Schema.Union([ + Schema.Literals(["pipeline_apply", "table_sync"]).annotate({ + description: + "Replication slot that reported the feedback: the table's own sync slot until it follows changes, or the pipeline apply slot once it does.", + }), + OpenString, + ]), + wal_status: Schema.Union([ + Schema.Union([ + Schema.Literals(["extended", "lost", "reserved", "unknown", "unreserved"]), + Schema.Null, + ]), + OpenString, + ]), + write_lag_ms: Schema.Union([ + Schema.Number.check( + Schema.isFinite().annotate({ expected: "a finite number" }), + ).check( + Schema.isGreaterThanOrEqualTo(0).annotate({ + expected: "a value greater than or equal to 0", + }), + ), + Schema.Null, + ]), + }).annotate({ + description: + "Postgres feedback from the replication slot named in source. Null when no feedback is available, including while the pipeline is stopped. Feedback age measures time since the slot last responded and does not establish how current query results are.", + }), + Schema.Null, + ]), + replication_state: Schema.Union([ + Schema.Union([ + Schema.Literals(["copied_table", "copying_table", "error", "following_wal", "queued"]), + Schema.Null, + ]).annotate({ + description: + "Last replication state the pipeline recorded for the table, also while the pipeline is stopped. Null when none was observed.", + }), + OpenString, + ]), + schema: Schema.String.annotate({ description: "Source PostgreSQL schema of the table." }), + status: Schema.Union([ + Schema.Literals(["error", "live", "stopped", "syncing", "unknown"]).annotate({ + description: + "Replication status. error means the table failed to replicate; stopped means the pipeline is stopped, stopping or failed, so the table receives no changes; live means the table follows changes; syncing means it is queued, copying or catching up; unknown means the pipeline status or the table state was not observed, for example before replication starts.", + }), + OpenString, + ]), + warehouse_name: Schema.String.annotate({ + description: "Quoted, fully qualified name of the replicated table in the Warehouse.", + }), + }), + id: Schema.String.annotate({ + description: "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + }) + .check( + Schema.isMaxCodePoints(10).annotate({ expected: "a string with at most 10 code points" }), + ) + .check( + Schema.isPattern(new RegExp("^[1-9]\\d*$", "u")).annotate({ + expected: "a string matching the RegExp ^[1-9]\\d*$", + }), + ), + type: Schema.Literal("warehouse_table").annotate({ description: "Resource type." }), + }), + ), +}); export const V2OrganizationsSlugWebhooksDeliveriesIdGetInput = Schema.Struct({ slug: Schema.String.check( Schema.isPattern(new RegExp("^[\\w-]+$", "u")).annotate({ @@ -20094,6 +20265,7 @@ export const openApiOperationIdMap = { "v2-list-organization-projects": "v2ListOrganizationProjects", "v2-list-organization-roles": "v2ListOrganizationRoles", "v2-list-private-link-associations": "v2ListPrivateLinkAssociations", + "v2-list-warehouse-tables": "v2ListWarehouseTables", "v2-organizations-slug-webhooks-deliveries-id-get": "v2OrganizationsSlugWebhooksDeliveriesIdGet", "v2-organizations-slug-webhooks-deliveries-id-retry-post": "v2OrganizationsSlugWebhooksDeliveriesIdRetryPost", @@ -23436,6 +23608,20 @@ export const operationDefinitions = { inputSchema: V2ListPrivateLinkAssociationsInput, outputSchema: V2ListPrivateLinkAssociationsOutput, }, + v2ListWarehouseTables: { + id: "v2ListWarehouseTables", + description: + "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.\n\nThis endpoint is currently in its **Alpha** stage.", + method: "GET", + path: "/v2/projects/{ref}/warehouse/tables", + pathParams: ["ref"], + queryParams: [], + headerParams: [], + requestBody: { kind: "none" }, + response: { kind: "json" }, + inputSchema: V2ListWarehouseTablesInput, + outputSchema: V2ListWarehouseTablesOutput, + }, v2OrganizationsSlugWebhooksDeliveriesIdGet: { id: "v2OrganizationsSlugWebhooksDeliveriesIdGet", description: "Get details of a specific delivery attempt.", diff --git a/packages/api/src/generated/effect-client.ts b/packages/api/src/generated/effect-client.ts index a50f091773..fc5b55dc1b 100644 --- a/packages/api/src/generated/effect-client.ts +++ b/packages/api/src/generated/effect-client.ts @@ -3300,6 +3300,22 @@ export const versionedEffectOperations = { options, ); }), + listWarehouseTables: ( + input: typeof operationDefinitions.v2ListWarehouseTables.inputSchema.Type, + options?: SupabaseApiRequestOptions, + ): Effect.Effect< + typeof operationDefinitions.v2ListWarehouseTables.outputSchema.Type, + SupabaseApiError, + SupabaseApiClient + > => + Effect.gen(function* () { + const client = yield* SupabaseApiClient; + return yield* client.execute<"v2ListWarehouseTables">( + operationDefinitions.v2ListWarehouseTables, + input, + options, + ); + }), organizationsSlugWebhooksDeliveriesIdGet: ( input: typeof operationDefinitions.v2OrganizationsSlugWebhooksDeliveriesIdGet.inputSchema.Type, options?: SupabaseApiRequestOptions, diff --git a/packages/api/src/generated/openapi.json b/packages/api/src/generated/openapi.json index a3bdb0aece..f1456670b2 100644 --- a/packages/api/src/generated/openapi.json +++ b/packages/api/src/generated/openapi.json @@ -32856,6 +32856,114 @@ }, "x-scalar-stability": "experimental" } + }, + "/v2/projects/{ref}/warehouse/tables": { + "get": { + "description": "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.\n\nThis endpoint is currently in its **Alpha** stage.", + "operationId": "v2-list-warehouse-tables", + "parameters": [ + { + "description": "Project ref", + "in": "path", + "name": "ref", + "required": true, + "schema": { + "example": "abcdefghijklmnopqrst", + "maxLength": 20, + "minLength": 20, + "pattern": "^[a-z]+$", + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/V2WarehouseTablesResponse_Output" + } + } + }, + "description": "" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Unauthorized" + }, + "403": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Forbidden action" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Warehouse DuckLake destination not found" + }, + "429": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Rate limit exceeded" + }, + "503": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Warehouse feature, project metadata or table selection unavailable" + } + }, + "security": [ + { + "bearer": [] + } + ], + "summary": "List tables replicated to Warehouse", + "tags": ["Projects Warehouse"], + "x-badges": [ + { + "name": "OAuth scope: database:read", + "position": "after" + }, + { + "name": "Alpha", + "position": "before" + } + ], + "x-endpoint-owners": ["pipelines"], + "x-fga-permissions": [["database_read"]], + "x-oauth-scope": "database:read", + "x-operation": { + "group": "warehouse.tables", + "method": "list" + }, + "x-scalar-stability": "experimental" + } } }, "components": { @@ -48388,7 +48496,7 @@ "replication": { "properties": { "apply_lag": { - "description": "Postgres replication feedback. Null means unknown. Feedback age measures time since the last response and does not establish how current query results are.", + "description": "Postgres replication feedback. Null means Postgres reported no value; lag times also become null shortly after a caught-up slot sees no new WAL, while flush_lag_bytes, the WAL not yet confirmed flushed, reads 0. Feedback age measures time since the last response and does not establish how current query results are.", "nullable": true, "properties": { "active": { @@ -48399,6 +48507,12 @@ "nullable": true, "type": "number" }, + "flush_lag_bytes": { + "maximum": 9007199254740991, + "minimum": 0, + "nullable": true, + "type": "integer" + }, "flush_lag_ms": { "minimum": 0, "nullable": true, @@ -48418,6 +48532,7 @@ "required": [ "active", "feedback_age_ms", + "flush_lag_bytes", "flush_lag_ms", "wal_status", "write_lag_ms" @@ -48502,7 +48617,7 @@ "type": "string" }, "sync_lag": { - "description": "Postgres replication feedback. Null means unknown. Feedback age measures time since the last response and does not establish how current query results are.", + "description": "Postgres replication feedback. Null means Postgres reported no value; lag times also become null shortly after a caught-up slot sees no new WAL, while flush_lag_bytes, the WAL not yet confirmed flushed, reads 0. Feedback age measures time since the last response and does not establish how current query results are.", "nullable": true, "properties": { "active": { @@ -48513,6 +48628,12 @@ "nullable": true, "type": "number" }, + "flush_lag_bytes": { + "maximum": 9007199254740991, + "minimum": 0, + "nullable": true, + "type": "integer" + }, "flush_lag_ms": { "minimum": 0, "nullable": true, @@ -48539,6 +48660,7 @@ "required": [ "active", "feedback_age_ms", + "flush_lag_bytes", "flush_lag_ms", "wal_status", "write_lag_ms" @@ -48779,6 +48901,141 @@ }, "required": ["data"], "type": "object" + }, + "V2WarehouseTablesResponse_Output": { + "properties": { + "data": { + "items": { + "properties": { + "attributes": { + "properties": { + "lag_ms": { + "description": "Flush lag in milliseconds that Postgres reports for the slot in replication_feedback. Null when there is no feedback or Postgres reports no recent measurement, which includes a caught-up slot without new WAL; replication_feedback.flush_lag_bytes reads 0 in that case.", + "minimum": 0, + "nullable": true, + "type": "number" + }, + "name": { + "description": "Source PostgreSQL table name.", + "type": "string" + }, + "observed_at": { + "description": "Time the API retrieved the replication state of the table. It does not indicate when data was last synchronized.", + "format": "date-time", + "nullable": true, + "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" + }, + "replication_feedback": { + "description": "Postgres feedback from the replication slot named in source. Null when no feedback is available, including while the pipeline is stopped. Feedback age measures time since the slot last responded and does not establish how current query results are.", + "nullable": true, + "properties": { + "active": { + "type": "boolean" + }, + "feedback_age_ms": { + "minimum": 0, + "nullable": true, + "type": "number" + }, + "flush_lag_bytes": { + "maximum": 9007199254740991, + "minimum": 0, + "nullable": true, + "type": "integer" + }, + "flush_lag_ms": { + "minimum": 0, + "nullable": true, + "type": "number" + }, + "source": { + "description": "Replication slot that reported the feedback: the table's own sync slot until it follows changes, or the pipeline apply slot once it does.", + "enum": ["pipeline_apply", "table_sync"], + "type": "string" + }, + "wal_status": { + "enum": ["extended", "lost", null, "reserved", "unknown", "unreserved"], + "nullable": true, + "type": "string" + }, + "write_lag_ms": { + "minimum": 0, + "nullable": true, + "type": "number" + } + }, + "required": [ + "active", + "feedback_age_ms", + "flush_lag_bytes", + "flush_lag_ms", + "source", + "wal_status", + "write_lag_ms" + ], + "type": "object" + }, + "replication_state": { + "description": "Last replication state the pipeline recorded for the table, also while the pipeline is stopped. Null when none was observed.", + "enum": [ + "copied_table", + "copying_table", + "error", + "following_wal", + null, + "queued" + ], + "nullable": true, + "type": "string" + }, + "schema": { + "description": "Source PostgreSQL schema of the table.", + "type": "string" + }, + "status": { + "description": "Replication status. error means the table failed to replicate; stopped means the pipeline is stopped, stopping or failed, so the table receives no changes; live means the table follows changes; syncing means it is queued, copying or catching up; unknown means the pipeline status or the table state was not observed, for example before replication starts.", + "enum": ["error", "live", "stopped", "syncing", "unknown"], + "type": "string" + }, + "warehouse_name": { + "description": "Quoted, fully qualified name of the replicated table in the Warehouse.", + "type": "string" + } + }, + "required": [ + "lag_ms", + "name", + "observed_at", + "replication_feedback", + "replication_state", + "schema", + "status", + "warehouse_name" + ], + "type": "object" + }, + "id": { + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + }, + "type": { + "description": "Resource type.", + "enum": ["warehouse_table"], + "type": "string" + } + }, + "required": ["attributes", "id", "type"], + "type": "object" + }, + "type": "array" + } + }, + "required": ["data"], + "type": "object" } } } diff --git a/packages/api/src/generated/permissions.ts b/packages/api/src/generated/permissions.ts index 413ac5c910..d7cd2f6f41 100644 --- a/packages/api/src/generated/permissions.ts +++ b/packages/api/src/generated/permissions.ts @@ -450,4 +450,5 @@ export const operationPermissions: Readonly "v2-organizations-slug-webhooks-deliveries-id-retry-post": { fga: [] }, "v2-get-warehouse-status": { fga: [["database_read"]], oauthScope: "database:read" }, "v2-get-warehouse-connection": { fga: [["database_read"]], oauthScope: "database:read" }, + "v2-list-warehouse-tables": { fga: [["database_read"]], oauthScope: "database:read" }, }; From 03897a941936b5ea177ec385d28347613b79e8b9 Mon Sep 17 00:00:00 2001 From: Benjamin <5719034+bnjjj@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:14:41 +0100 Subject: [PATCH 2/5] feat(cli): add warehouse tables get Add the generated `warehouse tables get ` command for reading one replicated table by its source OID. The contract comes from a spec override until the deployed specification includes it. The bindings coverage test now supplies positional path parameters. --- .../command-surface.integration.test.ts | 1 + .../api-command-bindings.integration.test.ts | 39 ++- .../src/commands/api/api-command-policy.ts | 3 +- .../api/api-commands.integration.test.ts | 46 +++ apps/cli/src/commands/api/generated.md | 11 + .../cli/src/commands/api/generated.schemas.ts | 127 +++++++++ apps/cli/src/commands/api/generated.ts | 34 +++ packages/api/scripts/openapi-overrides.json | 262 ++++++++++++++++++ packages/api/src/generated/contracts.ts | 157 +++++++++++ packages/api/src/generated/effect-client.ts | 16 ++ packages/api/src/generated/openapi.json | 252 +++++++++++++++++ packages/api/src/generated/permissions.ts | 1 + 12 files changed, 944 insertions(+), 5 deletions(-) diff --git a/apps/cli/src/cli/command-surface/command-surface.integration.test.ts b/apps/cli/src/cli/command-surface/command-surface.integration.test.ts index 98fef115c9..052b2a00c3 100644 --- a/apps/cli/src/cli/command-surface/command-surface.integration.test.ts +++ b/apps/cli/src/cli/command-surface/command-surface.integration.test.ts @@ -59,6 +59,7 @@ describe("command surface", () => { "warehouse enable", "warehouse status", "warehouse tables", + "warehouse tables get", "warehouse tables list", "warehouse teardowns", "warehouse teardowns get", diff --git a/apps/cli/src/commands/api/api-command-bindings.integration.test.ts b/apps/cli/src/commands/api/api-command-bindings.integration.test.ts index 0436c50641..b7abd2dc3c 100644 --- a/apps/cli/src/commands/api/api-command-bindings.integration.test.ts +++ b/apps/cli/src/commands/api/api-command-bindings.integration.test.ts @@ -111,6 +111,7 @@ const shapeOf = (schema: unknown): unknown => { const PATTERN_SAMPLES: Readonly> = { "^[a-f0-9]{64}$": "ab".repeat(32), "^[a-z]+$": "zyxwvutsrqponmlkjihg", + "^[1-9]\\d*$": "16385", "^([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)$": "7579647f-2cdc-466c-982e-425958a2f985", }; @@ -198,6 +199,15 @@ const inputsOf = ( return [...queries, ...fields]; }; +/** The path parameters besides `ref`, each supplied as a positional argument. */ +const positionalsOf = (operation: SpecOperation) => + operation.parameters + .filter((parameter) => parameter["in"] === "path" && parameter["name"] !== "ref") + .map((parameter) => ({ + name: String(parameter["name"]), + sample: String(sampleOf(parameter["schema"])), + })); + const argvOf = (inputs: ReadonlyArray): ReadonlyArray => inputs.flatMap((input) => Array.isArray(input.sample) @@ -330,13 +340,26 @@ describe("generated command bindings", () => { const { operationId } = row.api; const operation = operationOf(operationId); const inputs = inputsOf(operation, row.api.bindings); - const expectedPath = operation.template.replace("{ref}", VALID_REF); + const positionals = positionalsOf(operation); + const expectedPath = positionals.reduce( + (path, { name, sample }) => path.replace(`{${name}}`, sample), + operation.template.replace("{ref}", VALID_REF), + ); describe(row.path.join(" "), () => { it("binds the path reference and every other input to the spec's location", () => { - expect(operation.template.match(/\{[^}]+\}/g)).toEqual(["{ref}"]); + expect(operation.template.match(/\{[^}]+\}/g)).toEqual([ + "{ref}", + ...positionals.map(({ name }) => `{${name}}`), + ]); const expected = [ { location: "path", name: "ref", source: "target" }, + ...positionals.map(({ name }) => ({ + location: "path", + name, + source: "argument", + argument: generated.find((entry) => entry.operationId === operationId)?.argument?.name, + })), ...inputs.map((input) => input.location === "query" ? { location: "query", name: input.field, source: "flag", flag: input.flag } @@ -356,7 +379,11 @@ describe("generated command bindings", () => { it.effect("sends every input at its binding", () => Effect.gen(function* () { - const requests = yield* send(row.path, argvOf(inputs), operation.responseStatus); + const requests = yield* send( + row.path, + [...positionals.map(({ sample }) => sample), ...argvOf(inputs)], + operation.responseStatus, + ); expect(requests).toHaveLength(1); const [request] = requests; expect(request?.method).toBe(operation.method); @@ -371,7 +398,11 @@ describe("generated command bindings", () => { it.effect("sends only the inputs the spec requires when no other flag is given", () => Effect.gen(function* () { const required = inputs.filter((input) => input.required); - const requests = yield* send(row.path, argvOf(required), operation.responseStatus); + const requests = yield* send( + row.path, + [...positionals.map(({ sample }) => sample), ...argvOf(required)], + operation.responseStatus, + ); expect(requests).toHaveLength(1); const [request] = requests; expect(Object.fromEntries(new URLSearchParams(request?.search))).toEqual( diff --git a/apps/cli/src/commands/api/api-command-policy.ts b/apps/cli/src/commands/api/api-command-policy.ts index 0c7bb94bac..99494326ad 100644 --- a/apps/cli/src/commands/api/api-command-policy.ts +++ b/apps/cli/src/commands/api/api-command-policy.ts @@ -33,6 +33,7 @@ export const generatedOperations: ReadonlyArray = [ "v2-disable-warehouse", "v2-get-warehouse-teardown", "v2-list-warehouse-tables", + "v2-get-warehouse-table", ]; export const nouns = { @@ -40,7 +41,7 @@ export const nouns = { description: "Manage the data warehouse for a project", feature: "warehouse", groups: { - tables: "List tables replicated to Warehouse", + tables: "Inspect tables replicated to Warehouse", teardowns: "Inspect Warehouse cleanup operations", }, }, diff --git a/apps/cli/src/commands/api/api-commands.integration.test.ts b/apps/cli/src/commands/api/api-commands.integration.test.ts index 76f4ef4117..83c89b6616 100644 --- a/apps/cli/src/commands/api/api-commands.integration.test.ts +++ b/apps/cli/src/commands/api/api-commands.integration.test.ts @@ -434,6 +434,52 @@ describe("generated warehouse commands", () => { }); }); }); + describe("warehouse tables get", () => { + const tablePath = `/v2/projects/${VALID_REF}/warehouse/tables/16385`; + const body = { + data: { + id: "16385", + type: "warehouse_table", + attributes: { + schema: "public", + name: "orders", + warehouse_name: '"public"."orders"', + status: "live", + replication_state: "following_wal", + lag_ms: 120, + observed_at: "2026-11-17T10:00:00Z", + replication_feedback: { + source: "pipeline_apply", + active: true, + wal_status: "reserved", + write_lag_ms: 80, + flush_lag_ms: 120, + flush_lag_bytes: 2048, + feedback_age_ms: 5, + }, + }, + }, + }; + + it.effect( + "requests the table by OID and renders its attributes and replication feedback", + () => { + const { out, sent, run } = setup(["warehouse", "tables", "get", "16385"], { + route: ok(body), + stdoutIsTty: true, + }); + return Effect.gen(function* () { + yield* run; + expect(sent).toEqual([{ method: "GET", path: tablePath, search: "", body: undefined }]); + expect(out.stdoutText).toMatch(/Warehouse table/); + expect(out.stdoutText).toMatch(/Name\s+orders/); + expect(out.stdoutText).toMatch(/Replication state\s+following_wal/); + expect(out.stdoutText).toMatch(/Replication feedback\n\s+Source\s+pipeline_apply/); + expect(out.stdoutText).toMatch(/Flush lag bytes\s+2048/); + }); + }, + ); + }); describe("warehouse connection", () => { const connectionPath = `/v2/projects/${VALID_REF}/warehouse/connection`; const host = `${VALID_REF}.warehouse.example.invalid`; diff --git a/apps/cli/src/commands/api/generated.md b/apps/cli/src/commands/api/generated.md index a029234184..4f649c9d43 100644 --- a/apps/cli/src/commands/api/generated.md +++ b/apps/cli/src/commands/api/generated.md @@ -77,6 +77,17 @@ Returns provisioning, configured compute, replication, cleanup lifecycle and sup - Feature: `warehouse`. - Request: `GET /v2/projects/{ref}/warehouse/status` (`v2-get-warehouse-status`), success 200 json. +## `supabase warehouse tables get` + +Get a table replicated to Warehouse + +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. + +- Access: read-only, no consent. +- Feature: `warehouse`. +- Request: `GET /v2/projects/{ref}/warehouse/tables/{table_id}` (`v2-get-warehouse-table`), success 200 json. +- Positional argument ``, bound to path parameter `table_id`. + ## `supabase warehouse tables list` List tables replicated to Warehouse diff --git a/apps/cli/src/commands/api/generated.schemas.ts b/apps/cli/src/commands/api/generated.schemas.ts index b0c10c0bbc..4cbcade337 100644 --- a/apps/cli/src/commands/api/generated.schemas.ts +++ b/apps/cli/src/commands/api/generated.schemas.ts @@ -1074,6 +1074,133 @@ export const apiCommandSchemas = { type: "object", }, }, + "v2-get-warehouse-table": { + result: { + $schema: "https://json-schema.org/draft/2020-12/schema", + properties: { + data: { + properties: { + attributes: { + properties: { + lag_ms: { + description: + "Flush lag in milliseconds that Postgres reports for the slot in replication_feedback. Null when there is no feedback or Postgres reports no recent measurement, which includes a caught-up slot without new WAL; replication_feedback.flush_lag_bytes reads 0 in that case.", + minimum: 0, + type: ["number", "null"], + }, + name: { + description: "Source PostgreSQL table name.", + type: "string", + }, + observed_at: { + description: + "Time the API retrieved the replication state of the table. It does not indicate when data was last synchronized.", + 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", "null"], + }, + replication_feedback: { + description: + "Postgres feedback from the replication slot named in source. Null when no feedback is available, including while the pipeline is stopped. Feedback age measures time since the slot last responded and does not establish how current query results are.", + properties: { + active: { + type: "boolean", + }, + feedback_age_ms: { + minimum: 0, + type: ["number", "null"], + }, + flush_lag_bytes: { + maximum: 9007199254740991, + minimum: 0, + type: ["integer", "null"], + }, + flush_lag_ms: { + minimum: 0, + type: ["number", "null"], + }, + source: { + description: + "Replication slot that reported the feedback: the table's own sync slot until it follows changes, or the pipeline apply slot once it does.", + enum: ["pipeline_apply", "table_sync"], + type: "string", + }, + wal_status: { + enum: ["extended", "lost", null, "reserved", "unknown", "unreserved"], + type: ["string", "null"], + }, + write_lag_ms: { + minimum: 0, + type: ["number", "null"], + }, + }, + required: [ + "active", + "feedback_age_ms", + "flush_lag_bytes", + "flush_lag_ms", + "source", + "wal_status", + "write_lag_ms", + ], + type: ["object", "null"], + }, + replication_state: { + description: + "Last replication state the pipeline recorded for the table, also while the pipeline is stopped. Null when none was observed.", + enum: ["copied_table", "copying_table", "error", "following_wal", null, "queued"], + type: ["string", "null"], + }, + schema: { + description: "Source PostgreSQL schema of the table.", + type: "string", + }, + status: { + description: + "Replication status. error means the table failed to replicate; stopped means the pipeline is stopped, stopping or failed, so the table receives no changes; live means the table follows changes; syncing means it is queued, copying or catching up; unknown means the pipeline status or the table state was not observed, for example before replication starts.", + enum: ["error", "live", "stopped", "syncing", "unknown"], + type: "string", + }, + warehouse_name: { + description: + "Quoted, fully qualified name of the replicated table in the Warehouse.", + type: "string", + }, + }, + required: [ + "lag_ms", + "name", + "observed_at", + "replication_feedback", + "replication_state", + "schema", + "status", + "warehouse_name", + ], + 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"], + 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", diff --git a/apps/cli/src/commands/api/generated.ts b/apps/cli/src/commands/api/generated.ts index 12d5c4ac30..d6b37b1b13 100644 --- a/apps/cli/src/commands/api/generated.ts +++ b/apps/cli/src/commands/api/generated.ts @@ -214,6 +214,40 @@ export const apiCommands = [ }, ], }, + { + command: ["warehouse", "tables", "get"], + operationId: "v2-get-warehouse-table", + definition: "v2GetWarehouseTable", + method: "GET", + apiPath: "/v2/projects/{ref}/warehouse/tables/{table_id}", + summary: "Get a table replicated to Warehouse", + description: + "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.", + readOnly: true, + feature: "warehouse", + response: { + status: 200, + kind: "json", + }, + argument: { + name: "table-id", + description: "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + }, + flags: [], + bindings: [ + { + location: "path", + name: "ref", + source: "target", + }, + { + location: "path", + name: "table_id", + source: "argument", + argument: "table-id", + }, + ], + }, { command: ["warehouse", "tables", "list"], operationId: "v2-list-warehouse-tables", diff --git a/packages/api/scripts/openapi-overrides.json b/packages/api/scripts/openapi-overrides.json index 6082674da0..0a967f8b04 100644 --- a/packages/api/scripts/openapi-overrides.json +++ b/packages/api/scripts/openapi-overrides.json @@ -1210,6 +1210,268 @@ }, "$comment": "The Warehouse tables listing contract is not yet in the deployed Management API specification." }, + { + "op": "add", + "path": "/paths/~1v2~1projects~1{ref}~1warehouse~1tables~1{table_id}", + "value": { + "get": { + "description": "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.\n\nThis endpoint is currently in its **Alpha** stage.", + "operationId": "v2-get-warehouse-table", + "parameters": [ + { + "description": "Project ref", + "in": "path", + "name": "ref", + "required": true, + "schema": { + "example": "abcdefghijklmnopqrst", + "maxLength": 20, + "minLength": 20, + "pattern": "^[a-z]+$", + "type": "string" + } + }, + { + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + "in": "path", + "name": "table_id", + "required": true, + "schema": { + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/V2WarehouseTableResponse_Output" + } + } + }, + "description": "" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Unauthorized" + }, + "403": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Forbidden action" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Table not replicated to Warehouse, or Warehouse DuckLake destination not found" + }, + "429": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Rate limit exceeded" + }, + "503": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Warehouse feature, project metadata or table selection unavailable" + } + }, + "security": [ + { + "bearer": [] + } + ], + "summary": "Get a table replicated to Warehouse", + "tags": ["Projects Warehouse"], + "x-badges": [ + { + "name": "OAuth scope: database:read", + "position": "after" + }, + { + "name": "Alpha", + "position": "before" + } + ], + "x-endpoint-owners": ["pipelines"], + "x-fga-permissions": [["database_read"]], + "x-oauth-scope": "database:read", + "x-operation": { + "group": "warehouse.tables", + "method": "get" + }, + "x-scalar-stability": "experimental" + } + }, + "$comment": "The Warehouse table inspection contract is not yet in the deployed Management API specification." + }, + { + "op": "add", + "path": "/components/schemas/V2WarehouseTableResponse_Output", + "value": { + "properties": { + "data": { + "properties": { + "attributes": { + "properties": { + "lag_ms": { + "description": "Flush lag in milliseconds that Postgres reports for the slot in replication_feedback. Null when there is no feedback or Postgres reports no recent measurement, which includes a caught-up slot without new WAL; replication_feedback.flush_lag_bytes reads 0 in that case.", + "minimum": 0, + "nullable": true, + "type": "number" + }, + "name": { + "description": "Source PostgreSQL table name.", + "type": "string" + }, + "observed_at": { + "description": "Time the API retrieved the replication state of the table. It does not indicate when data was last synchronized.", + "format": "date-time", + "nullable": true, + "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" + }, + "replication_feedback": { + "description": "Postgres feedback from the replication slot named in source. Null when no feedback is available, including while the pipeline is stopped. Feedback age measures time since the slot last responded and does not establish how current query results are.", + "nullable": true, + "properties": { + "active": { + "type": "boolean" + }, + "feedback_age_ms": { + "minimum": 0, + "nullable": true, + "type": "number" + }, + "flush_lag_bytes": { + "maximum": 9007199254740991, + "minimum": 0, + "nullable": true, + "type": "integer" + }, + "flush_lag_ms": { + "minimum": 0, + "nullable": true, + "type": "number" + }, + "source": { + "description": "Replication slot that reported the feedback: the table's own sync slot until it follows changes, or the pipeline apply slot once it does.", + "enum": ["pipeline_apply", "table_sync"], + "type": "string" + }, + "wal_status": { + "enum": ["extended", "lost", null, "reserved", "unknown", "unreserved"], + "nullable": true, + "type": "string" + }, + "write_lag_ms": { + "minimum": 0, + "nullable": true, + "type": "number" + } + }, + "required": [ + "active", + "feedback_age_ms", + "flush_lag_bytes", + "flush_lag_ms", + "source", + "wal_status", + "write_lag_ms" + ], + "type": "object" + }, + "replication_state": { + "description": "Last replication state the pipeline recorded for the table, also while the pipeline is stopped. Null when none was observed.", + "enum": [ + "copied_table", + "copying_table", + "error", + "following_wal", + null, + "queued" + ], + "nullable": true, + "type": "string" + }, + "schema": { + "description": "Source PostgreSQL schema of the table.", + "type": "string" + }, + "status": { + "description": "Replication status. error means the table failed to replicate; stopped means the pipeline is stopped, stopping or failed, so the table receives no changes; live means the table follows changes; syncing means it is queued, copying or catching up; unknown means the pipeline status or the table state was not observed, for example before replication starts.", + "enum": ["error", "live", "stopped", "syncing", "unknown"], + "type": "string" + }, + "warehouse_name": { + "description": "Quoted, fully qualified name of the replicated table in the Warehouse.", + "type": "string" + } + }, + "required": [ + "lag_ms", + "name", + "observed_at", + "replication_feedback", + "replication_state", + "schema", + "status", + "warehouse_name" + ], + "type": "object" + }, + "id": { + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + }, + "type": { + "description": "Resource type.", + "enum": ["warehouse_table"], + "type": "string" + } + }, + "required": ["attributes", "id", "type"], + "type": "object" + } + }, + "required": ["data"], + "type": "object" + }, + "$comment": "The Warehouse table inspection contract is not yet in the deployed Management API specification." + }, { "op": "test", "path": "/paths/~1v2~1projects~1{ref}~1warehouse~1setups~1current/get/x-operation", diff --git a/packages/api/src/generated/contracts.ts b/packages/api/src/generated/contracts.ts index 1d8e94b757..b5a6a4c5c8 100644 --- a/packages/api/src/generated/contracts.ts +++ b/packages/api/src/generated/contracts.ts @@ -15049,6 +15049,148 @@ export const V2GetWarehouseStatusOutput = Schema.Struct({ type: Schema.Literal("warehouse_context").annotate({ description: "Resource type." }), }), }); +export const V2GetWarehouseTableInput = Schema.Struct({ + ref: Schema.String.check( + Schema.isMinCodePoints(20).annotate({ expected: "a string with at least 20 code points" }), + ) + .check( + Schema.isMaxCodePoints(20).annotate({ expected: "a string with at most 20 code points" }), + ) + .check( + Schema.isPattern(new RegExp("^[a-z]+$", "u")).annotate({ + expected: "a string matching the RegExp ^[a-z]+$", + }), + ), + table_id: Schema.String.check( + Schema.isMaxCodePoints(10).annotate({ expected: "a string with at most 10 code points" }), + ).check( + Schema.isPattern(new RegExp("^[1-9]\\d*$", "u")).annotate({ + expected: "a string matching the RegExp ^[1-9]\\d*$", + }), + ), +}); +export const V2GetWarehouseTableOutput = Schema.Struct({ + data: Schema.Struct({ + attributes: Schema.Struct({ + lag_ms: Schema.Union([ + Schema.Number.annotate({ + description: + "Flush lag in milliseconds that Postgres reports for the slot in replication_feedback. Null when there is no feedback or Postgres reports no recent measurement, which includes a caught-up slot without new WAL; replication_feedback.flush_lag_bytes reads 0 in that case.", + }) + .check(Schema.isFinite().annotate({ expected: "a finite number" })) + .check( + Schema.isGreaterThanOrEqualTo(0).annotate({ + expected: "a value greater than or equal to 0", + }), + ), + Schema.Null, + ]), + name: Schema.String.annotate({ description: "Source PostgreSQL table name." }), + observed_at: Schema.Union([ + Schema.String.annotate({ + description: + "Time the API retrieved the replication state of the table. It does not indicate when data was last synchronized.", + format: "date-time", + }), + Schema.Null, + ]), + replication_feedback: Schema.Union([ + Schema.Struct({ + active: Schema.Boolean, + feedback_age_ms: Schema.Union([ + Schema.Number.check(Schema.isFinite().annotate({ expected: "a finite number" })).check( + Schema.isGreaterThanOrEqualTo(0).annotate({ + expected: "a value greater than or equal to 0", + }), + ), + Schema.Null, + ]), + flush_lag_bytes: Schema.Union([ + Schema.Number.check(Schema.isInt().annotate({ expected: "an integer" })) + .check( + Schema.isGreaterThanOrEqualTo(0).annotate({ + expected: "a value greater than or equal to 0", + }), + ) + .check( + Schema.isLessThanOrEqualTo(9007199254740991).annotate({ + expected: "a value less than or equal to 9007199254740991", + }), + ), + Schema.Null, + ]), + flush_lag_ms: Schema.Union([ + Schema.Number.check(Schema.isFinite().annotate({ expected: "a finite number" })).check( + Schema.isGreaterThanOrEqualTo(0).annotate({ + expected: "a value greater than or equal to 0", + }), + ), + Schema.Null, + ]), + source: Schema.Union([ + Schema.Literals(["pipeline_apply", "table_sync"]).annotate({ + description: + "Replication slot that reported the feedback: the table's own sync slot until it follows changes, or the pipeline apply slot once it does.", + }), + OpenString, + ]), + wal_status: Schema.Union([ + Schema.Union([ + Schema.Literals(["extended", "lost", "reserved", "unknown", "unreserved"]), + Schema.Null, + ]), + OpenString, + ]), + write_lag_ms: Schema.Union([ + Schema.Number.check(Schema.isFinite().annotate({ expected: "a finite number" })).check( + Schema.isGreaterThanOrEqualTo(0).annotate({ + expected: "a value greater than or equal to 0", + }), + ), + Schema.Null, + ]), + }).annotate({ + description: + "Postgres feedback from the replication slot named in source. Null when no feedback is available, including while the pipeline is stopped. Feedback age measures time since the slot last responded and does not establish how current query results are.", + }), + Schema.Null, + ]), + replication_state: Schema.Union([ + Schema.Union([ + Schema.Literals(["copied_table", "copying_table", "error", "following_wal", "queued"]), + Schema.Null, + ]).annotate({ + description: + "Last replication state the pipeline recorded for the table, also while the pipeline is stopped. Null when none was observed.", + }), + OpenString, + ]), + schema: Schema.String.annotate({ description: "Source PostgreSQL schema of the table." }), + status: Schema.Union([ + Schema.Literals(["error", "live", "stopped", "syncing", "unknown"]).annotate({ + description: + "Replication status. error means the table failed to replicate; stopped means the pipeline is stopped, stopping or failed, so the table receives no changes; live means the table follows changes; syncing means it is queued, copying or catching up; unknown means the pipeline status or the table state was not observed, for example before replication starts.", + }), + OpenString, + ]), + warehouse_name: Schema.String.annotate({ + description: "Quoted, fully qualified name of the replicated table in the Warehouse.", + }), + }), + id: Schema.String.annotate({ + description: "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + }) + .check( + Schema.isMaxCodePoints(10).annotate({ expected: "a string with at most 10 code points" }), + ) + .check( + Schema.isPattern(new RegExp("^[1-9]\\d*$", "u")).annotate({ + expected: "a string matching the RegExp ^[1-9]\\d*$", + }), + ), + type: Schema.Literal("warehouse_table").annotate({ description: "Resource type." }), + }), +}); export const V2GetWarehouseTeardownInput = Schema.Struct({ ref: Schema.String.check( Schema.isMinCodePoints(20).annotate({ expected: "a string with at least 20 code points" }), @@ -20255,6 +20397,7 @@ export const openApiOperationIdMap = { "v2-get-warehouse-connection": "v2GetWarehouseConnection", "v2-get-warehouse-setup": "v2GetWarehouseSetup", "v2-get-warehouse-status": "v2GetWarehouseStatus", + "v2-get-warehouse-table": "v2GetWarehouseTable", "v2-get-warehouse-teardown": "v2GetWarehouseTeardown", "v2-list-all-compute-instances": "v2ListAllComputeInstances", "v2-list-log-drains": "v2ListLogDrains", @@ -23471,6 +23614,20 @@ export const operationDefinitions = { inputSchema: V2GetWarehouseStatusInput, outputSchema: V2GetWarehouseStatusOutput, }, + v2GetWarehouseTable: { + id: "v2GetWarehouseTable", + description: + "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.\n\nThis endpoint is currently in its **Alpha** stage.", + method: "GET", + path: "/v2/projects/{ref}/warehouse/tables/{table_id}", + pathParams: ["ref", "table_id"], + queryParams: [], + headerParams: [], + requestBody: { kind: "none" }, + response: { kind: "json" }, + inputSchema: V2GetWarehouseTableInput, + outputSchema: V2GetWarehouseTableOutput, + }, v2GetWarehouseTeardown: { id: "v2GetWarehouseTeardown", description: diff --git a/packages/api/src/generated/effect-client.ts b/packages/api/src/generated/effect-client.ts index fc5b55dc1b..dfcad4c47e 100644 --- a/packages/api/src/generated/effect-client.ts +++ b/packages/api/src/generated/effect-client.ts @@ -3140,6 +3140,22 @@ export const versionedEffectOperations = { options, ); }), + getWarehouseTable: ( + input: typeof operationDefinitions.v2GetWarehouseTable.inputSchema.Type, + options?: SupabaseApiRequestOptions, + ): Effect.Effect< + typeof operationDefinitions.v2GetWarehouseTable.outputSchema.Type, + SupabaseApiError, + SupabaseApiClient + > => + Effect.gen(function* () { + const client = yield* SupabaseApiClient; + return yield* client.execute<"v2GetWarehouseTable">( + operationDefinitions.v2GetWarehouseTable, + input, + options, + ); + }), getWarehouseTeardown: ( input: typeof operationDefinitions.v2GetWarehouseTeardown.inputSchema.Type, options?: SupabaseApiRequestOptions, diff --git a/packages/api/src/generated/openapi.json b/packages/api/src/generated/openapi.json index f1456670b2..253bef208c 100644 --- a/packages/api/src/generated/openapi.json +++ b/packages/api/src/generated/openapi.json @@ -32964,6 +32964,126 @@ }, "x-scalar-stability": "experimental" } + }, + "/v2/projects/{ref}/warehouse/tables/{table_id}": { + "get": { + "description": "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.\n\nThis endpoint is currently in its **Alpha** stage.", + "operationId": "v2-get-warehouse-table", + "parameters": [ + { + "description": "Project ref", + "in": "path", + "name": "ref", + "required": true, + "schema": { + "example": "abcdefghijklmnopqrst", + "maxLength": 20, + "minLength": 20, + "pattern": "^[a-z]+$", + "type": "string" + } + }, + { + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + "in": "path", + "name": "table_id", + "required": true, + "schema": { + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/V2WarehouseTableResponse_Output" + } + } + }, + "description": "" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Unauthorized" + }, + "403": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Forbidden action" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Table not replicated to Warehouse, or Warehouse DuckLake destination not found" + }, + "429": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Rate limit exceeded" + }, + "503": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Warehouse feature, project metadata or table selection unavailable" + } + }, + "security": [ + { + "bearer": [] + } + ], + "summary": "Get a table replicated to Warehouse", + "tags": ["Projects Warehouse"], + "x-badges": [ + { + "name": "OAuth scope: database:read", + "position": "after" + }, + { + "name": "Alpha", + "position": "before" + } + ], + "x-endpoint-owners": ["pipelines"], + "x-fga-permissions": [["database_read"]], + "x-oauth-scope": "database:read", + "x-operation": { + "group": "warehouse.tables", + "method": "get" + }, + "x-scalar-stability": "experimental" + } } }, "components": { @@ -49036,6 +49156,138 @@ }, "required": ["data"], "type": "object" + }, + "V2WarehouseTableResponse_Output": { + "properties": { + "data": { + "properties": { + "attributes": { + "properties": { + "lag_ms": { + "description": "Flush lag in milliseconds that Postgres reports for the slot in replication_feedback. Null when there is no feedback or Postgres reports no recent measurement, which includes a caught-up slot without new WAL; replication_feedback.flush_lag_bytes reads 0 in that case.", + "minimum": 0, + "nullable": true, + "type": "number" + }, + "name": { + "description": "Source PostgreSQL table name.", + "type": "string" + }, + "observed_at": { + "description": "Time the API retrieved the replication state of the table. It does not indicate when data was last synchronized.", + "format": "date-time", + "nullable": true, + "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" + }, + "replication_feedback": { + "description": "Postgres feedback from the replication slot named in source. Null when no feedback is available, including while the pipeline is stopped. Feedback age measures time since the slot last responded and does not establish how current query results are.", + "nullable": true, + "properties": { + "active": { + "type": "boolean" + }, + "feedback_age_ms": { + "minimum": 0, + "nullable": true, + "type": "number" + }, + "flush_lag_bytes": { + "maximum": 9007199254740991, + "minimum": 0, + "nullable": true, + "type": "integer" + }, + "flush_lag_ms": { + "minimum": 0, + "nullable": true, + "type": "number" + }, + "source": { + "description": "Replication slot that reported the feedback: the table's own sync slot until it follows changes, or the pipeline apply slot once it does.", + "enum": ["pipeline_apply", "table_sync"], + "type": "string" + }, + "wal_status": { + "enum": ["extended", "lost", null, "reserved", "unknown", "unreserved"], + "nullable": true, + "type": "string" + }, + "write_lag_ms": { + "minimum": 0, + "nullable": true, + "type": "number" + } + }, + "required": [ + "active", + "feedback_age_ms", + "flush_lag_bytes", + "flush_lag_ms", + "source", + "wal_status", + "write_lag_ms" + ], + "type": "object" + }, + "replication_state": { + "description": "Last replication state the pipeline recorded for the table, also while the pipeline is stopped. Null when none was observed.", + "enum": [ + "copied_table", + "copying_table", + "error", + "following_wal", + null, + "queued" + ], + "nullable": true, + "type": "string" + }, + "schema": { + "description": "Source PostgreSQL schema of the table.", + "type": "string" + }, + "status": { + "description": "Replication status. error means the table failed to replicate; stopped means the pipeline is stopped, stopping or failed, so the table receives no changes; live means the table follows changes; syncing means it is queued, copying or catching up; unknown means the pipeline status or the table state was not observed, for example before replication starts.", + "enum": ["error", "live", "stopped", "syncing", "unknown"], + "type": "string" + }, + "warehouse_name": { + "description": "Quoted, fully qualified name of the replicated table in the Warehouse.", + "type": "string" + } + }, + "required": [ + "lag_ms", + "name", + "observed_at", + "replication_feedback", + "replication_state", + "schema", + "status", + "warehouse_name" + ], + "type": "object" + }, + "id": { + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + }, + "type": { + "description": "Resource type.", + "enum": ["warehouse_table"], + "type": "string" + } + }, + "required": ["attributes", "id", "type"], + "type": "object" + } + }, + "required": ["data"], + "type": "object" } } } diff --git a/packages/api/src/generated/permissions.ts b/packages/api/src/generated/permissions.ts index d7cd2f6f41..d074d62edf 100644 --- a/packages/api/src/generated/permissions.ts +++ b/packages/api/src/generated/permissions.ts @@ -451,4 +451,5 @@ export const operationPermissions: Readonly "v2-get-warehouse-status": { fga: [["database_read"]], oauthScope: "database:read" }, "v2-get-warehouse-connection": { fga: [["database_read"]], oauthScope: "database:read" }, "v2-list-warehouse-tables": { fga: [["database_read"]], oauthScope: "database:read" }, + "v2-get-warehouse-table": { fga: [["database_read"]], oauthScope: "database:read" }, }; From 3a8aef3a30fa6b76280501db32e359c769ebd1e5 Mon Sep 17 00:00:00 2001 From: Benjamin <5719034+bnjjj@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:51:15 +0100 Subject: [PATCH 3/5] chore(api): keep null in nullable oneOf response schemas --- packages/api/scripts/generate.ts | 13 +++++++------ packages/api/scripts/generate.unit.test.ts | 9 +++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/api/scripts/generate.ts b/packages/api/scripts/generate.ts index db22bc75ba..8678ee9534 100644 --- a/packages/api/scripts/generate.ts +++ b/packages/api/scripts/generate.ts @@ -332,14 +332,15 @@ export function sanitizeOpenApiSchema( delete sanitized.pattern; } - if ( - sanitized.nullable === true && - sanitized.type === undefined && - Array.isArray(sanitized.anyOf) - ) { + const union = Array.isArray(sanitized.anyOf) + ? "anyOf" + : Array.isArray(sanitized.oneOf) + ? "oneOf" + : undefined; + if (sanitized.nullable === true && sanitized.type === undefined && union !== undefined) { const normalized = { ...sanitized, - anyOf: [...sanitized.anyOf, { type: "null" }], + [union]: [...(sanitized[union] ?? []), { type: "null" }], }; delete normalized.nullable; return normalized; diff --git a/packages/api/scripts/generate.unit.test.ts b/packages/api/scripts/generate.unit.test.ts index 278fd316a5..6e361ec65f 100644 --- a/packages/api/scripts/generate.unit.test.ts +++ b/packages/api/scripts/generate.unit.test.ts @@ -275,6 +275,15 @@ describe("generate", () => { ).toBe("Schema.Union([Schema.String, Schema.Finite, Schema.Boolean, Schema.Null])"); }); + test("preserves null in nullable oneOf variants without an explicit type", () => { + expect( + renderOpenApiSchema({ + oneOf: [{ type: "string", enum: ["none"] }, { type: "integer" }], + nullable: true, + }), + ).toBe('Schema.Union([Schema.Literal("none"), Schema.Int, Schema.Null], { mode: "oneOf" })'); + }); + test("accepts booleans for string-encoded boolean query parameters", () => { expect( normalizeQueryParameterSchema( From 664bb6840c0371b95e022bbcc25ff491232a91d2 Mon Sep 17 00:00:00 2001 From: Benjamin <5719034+bnjjj@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:51:17 +0100 Subject: [PATCH 4/5] feat(cli): add warehouse tables layout get --- .../command-surface.integration.test.ts | 2 + .../api-command-bindings.integration.test.ts | 10 +- .../src/commands/api/api-command-policy.ts | 2 + .../api/api-commands.integration.test.ts | 40 ++ apps/cli/src/commands/api/generated.md | 11 + .../cli/src/commands/api/generated.schemas.ts | 258 ++++++++++++ apps/cli/src/commands/api/generated.ts | 34 ++ packages/api/scripts/openapi-overrides.json | 374 ++++++++++++++++++ packages/api/src/generated/contracts.ts | 154 ++++++++ packages/api/src/generated/effect-client.ts | 16 + packages/api/src/generated/openapi.json | 364 +++++++++++++++++ packages/api/src/generated/permissions.ts | 1 + 12 files changed, 1264 insertions(+), 2 deletions(-) diff --git a/apps/cli/src/cli/command-surface/command-surface.integration.test.ts b/apps/cli/src/cli/command-surface/command-surface.integration.test.ts index 052b2a00c3..394a10f8d8 100644 --- a/apps/cli/src/cli/command-surface/command-surface.integration.test.ts +++ b/apps/cli/src/cli/command-surface/command-surface.integration.test.ts @@ -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", diff --git a/apps/cli/src/commands/api/api-command-bindings.integration.test.ts b/apps/cli/src/commands/api/api-command-bindings.integration.test.ts index b7abd2dc3c..69acf80630 100644 --- a/apps/cli/src/commands/api/api-command-bindings.integration.test.ts +++ b/apps/cli/src/commands/api/api-command-bindings.integration.test.ts @@ -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 => { 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)); }; diff --git a/apps/cli/src/commands/api/api-command-policy.ts b/apps/cli/src/commands/api/api-command-policy.ts index 99494326ad..e15c31a4b4 100644 --- a/apps/cli/src/commands/api/api-command-policy.ts +++ b/apps/cli/src/commands/api/api-command-policy.ts @@ -34,6 +34,7 @@ export const generatedOperations: ReadonlyArray = [ "v2-get-warehouse-teardown", "v2-list-warehouse-tables", "v2-get-warehouse-table", + "v2-get-warehouse-table-layout", ]; export const nouns = { @@ -42,6 +43,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", }, }, diff --git a/apps/cli/src/commands/api/api-commands.integration.test.ts b/apps/cli/src/commands/api/api-commands.integration.test.ts index 83c89b6616..3a008fa720 100644 --- a/apps/cli/src/commands/api/api-commands.integration.test.ts +++ b/apps/cli/src/commands/api/api-commands.integration.test.ts @@ -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/); + }); + }); + }); describe("warehouse connection", () => { const connectionPath = `/v2/projects/${VALID_REF}/warehouse/connection`; const host = `${VALID_REF}.warehouse.example.invalid`; diff --git a/apps/cli/src/commands/api/generated.md b/apps/cli/src/commands/api/generated.md index 4f649c9d43..eec6fe6d20 100644 --- a/apps/cli/src/commands/api/generated.md +++ b/apps/cli/src/commands/api/generated.md @@ -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 ``, 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 ``, bound to path parameter `table_id`. + ## `supabase warehouse tables list` List tables replicated to Warehouse diff --git a/apps/cli/src/commands/api/generated.schemas.ts b/apps/cli/src/commands/api/generated.schemas.ts index 4cbcade337..c4a5e8b820 100644 --- a/apps/cli/src/commands/api/generated.schemas.ts +++ b/apps/cli/src/commands/api/generated.schemas.ts @@ -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 of a table replicated to Warehouse.", + 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", diff --git a/apps/cli/src/commands/api/generated.ts b/apps/cli/src/commands/api/generated.ts index d6b37b1b13..3b22b9cb0c 100644 --- a/apps/cli/src/commands/api/generated.ts +++ b/apps/cli/src/commands/api/generated.ts @@ -248,6 +248,40 @@ export const apiCommands = [ }, ], }, + { + command: ["warehouse", "tables", "layout", "get"], + operationId: "v2-get-warehouse-table-layout", + definition: "v2GetWarehouseTableLayout", + method: "GET", + apiPath: "/v2/projects/{ref}/warehouse/tables/{table_id}/layout", + summary: "Get the layout of a table replicated to Warehouse", + description: + "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.", + readOnly: true, + feature: "warehouse", + response: { + status: 200, + kind: "json", + }, + argument: { + name: "table-id", + description: "Source PostgreSQL table OID of a table replicated to Warehouse.", + }, + flags: [], + bindings: [ + { + location: "path", + name: "ref", + source: "target", + }, + { + location: "path", + name: "table_id", + source: "argument", + argument: "table-id", + }, + ], + }, { command: ["warehouse", "tables", "list"], operationId: "v2-list-warehouse-tables", diff --git a/packages/api/scripts/openapi-overrides.json b/packages/api/scripts/openapi-overrides.json index 0a967f8b04..b30eff636c 100644 --- a/packages/api/scripts/openapi-overrides.json +++ b/packages/api/scripts/openapi-overrides.json @@ -1472,6 +1472,380 @@ }, "$comment": "The Warehouse table inspection contract is not yet in the deployed Management API specification." }, + { + "op": "add", + "path": "/paths/~1v2~1projects~1{ref}~1warehouse~1tables~1{table_id}~1layout", + "value": { + "get": { + "description": "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.\n\nThis endpoint is currently in its **Alpha** stage.", + "operationId": "v2-get-warehouse-table-layout", + "parameters": [ + { + "description": "Project ref", + "in": "path", + "name": "ref", + "required": true, + "schema": { + "example": "abcdefghijklmnopqrst", + "maxLength": 20, + "minLength": 20, + "pattern": "^[a-z]+$", + "type": "string" + } + }, + { + "description": "Source PostgreSQL table OID of a table replicated to Warehouse.", + "in": "path", + "name": "table_id", + "required": true, + "schema": { + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/V2WarehouseTableLayoutResponse_Output" + } + } + }, + "description": "" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Unauthorized" + }, + "403": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Forbidden action" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Table not replicated to Warehouse" + }, + "429": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Rate limit exceeded" + }, + "503": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Warehouse feature, project metadata or table layout unavailable" + } + }, + "security": [ + { + "bearer": [] + } + ], + "summary": "Get the layout of a table replicated to Warehouse", + "tags": ["Projects Warehouse"], + "x-badges": [ + { + "name": "OAuth scope: database:read", + "position": "after" + }, + { + "name": "Alpha", + "position": "before" + } + ], + "x-endpoint-owners": ["pipelines"], + "x-fga-permissions": [["database_read"]], + "x-oauth-scope": "database:read", + "x-operation": { + "group": "warehouse.tables.layout", + "method": "get" + }, + "x-scalar-stability": "experimental" + } + }, + "$comment": "The Warehouse table layout contract is not yet in the deployed Management API specification." + }, + { + "op": "add", + "path": "/components/schemas/V2WarehouseTableLayoutResponse_Output", + "value": { + "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.", + "exclusiveMinimum": true, + "maximum": 2147483647, + "minimum": 0, + "type": "integer" + }, + "kind": { + "enum": ["bucket"], + "type": "string" + } + }, + "required": ["count", "kind"], + "type": "object" + } + ] + } + }, + "required": ["column", "transform"], + "type": "object" + }, + "nullable": true, + "type": "array" + }, + "sort_by": { + "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.", + "nullable": true, + "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], + "nullable": true, + "type": "string" + } + }, + "required": ["direction", "name", "nulls"], + "type": "object" + }, + "type": "array" + }, + "kind": { + "enum": ["columns"], + "type": "string" + } + }, + "required": ["columns", "kind"], + "type": "object" + } + ] + } + }, + "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.", + "nullable": true, + "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" + }, + "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 of a table replicated to Warehouse.", + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + }, + "type": { + "description": "Resource type.", + "enum": ["warehouse_table_layout"], + "type": "string" + } + }, + "required": ["attributes", "id", "type"], + "type": "object" + } + }, + "required": ["data"], + "type": "object" + }, + "$comment": "The Warehouse table layout contract is not yet in the deployed Management API specification." + }, { "op": "test", "path": "/paths/~1v2~1projects~1{ref}~1warehouse~1setups~1current/get/x-operation", diff --git a/packages/api/src/generated/contracts.ts b/packages/api/src/generated/contracts.ts index b5a6a4c5c8..11db7c91a7 100644 --- a/packages/api/src/generated/contracts.ts +++ b/packages/api/src/generated/contracts.ts @@ -15191,6 +15191,145 @@ export const V2GetWarehouseTableOutput = Schema.Struct({ type: Schema.Literal("warehouse_table").annotate({ description: "Resource type." }), }), }); +export const V2GetWarehouseTableLayoutInput = Schema.Struct({ + ref: Schema.String.check( + Schema.isMinCodePoints(20).annotate({ expected: "a string with at least 20 code points" }), + ) + .check( + Schema.isMaxCodePoints(20).annotate({ expected: "a string with at most 20 code points" }), + ) + .check( + Schema.isPattern(new RegExp("^[a-z]+$", "u")).annotate({ + expected: "a string matching the RegExp ^[a-z]+$", + }), + ), + table_id: Schema.String.check( + Schema.isMaxCodePoints(10).annotate({ expected: "a string with at most 10 code points" }), + ).check( + Schema.isPattern(new RegExp("^[1-9]\\d*$", "u")).annotate({ + expected: "a string matching the RegExp ^[1-9]\\d*$", + }), + ), +}); +export const V2GetWarehouseTableLayoutOutput = Schema.Struct({ + data: Schema.Struct({ + attributes: Schema.Struct({ + desired: Schema.Struct({ + partition_by: Schema.Union([ + Schema.Array( + Schema.Struct({ + column: Schema.String.annotate({ description: "Source column name." }), + transform: Schema.Union( + [ + Schema.Struct({ kind: Schema.Literal("identity") }), + Schema.Struct({ kind: Schema.Literal("year") }), + Schema.Struct({ kind: Schema.Literal("month") }), + Schema.Struct({ kind: Schema.Literal("day") }), + Schema.Struct({ kind: Schema.Literal("hour") }), + Schema.Struct({ + count: Schema.Number.annotate({ description: "Number of hash buckets." }) + .check(Schema.isInt().annotate({ expected: "an integer" })) + .check( + Schema.isLessThanOrEqualTo(2147483647).annotate({ + expected: "a value less than or equal to 2147483647", + }), + ) + .check( + Schema.isGreaterThan(0).annotate({ expected: "a value greater than 0" }), + ), + kind: Schema.Literal("bucket"), + }), + ], + { mode: "oneOf" }, + ), + }), + ).annotate({ + description: + "Configured partition keys in order. An empty list explicitly clears partitioning; null leaves it unmanaged.", + }), + Schema.Null, + ]), + sort_by: Schema.Union( + [ + Schema.Struct({ kind: Schema.Literal("none") }), + Schema.Struct({ kind: Schema.Literal("primary_key") }), + Schema.Struct({ + columns: Schema.Array( + Schema.Struct({ + direction: Schema.Union([Schema.Literals(["asc", "desc"]), OpenString]), + name: Schema.String.annotate({ description: "Source column name." }), + nulls: Schema.Union([ + Schema.Union([Schema.Literals(["first", "last"]), Schema.Null]).annotate({ + description: "Null placement. Null uses DuckLake's default placement.", + }), + OpenString, + ]), + }), + ), + kind: Schema.Literal("columns"), + }), + Schema.Null, + ], + { mode: "oneOf" }, + ).annotate({ + 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.", + }), + }).annotate({ + description: + "Saved layout rules. The replicator applies them on start and hourly, so they can differ from the observed layout.", + }), + name: Schema.String.annotate({ description: "Source PostgreSQL table name." }), + observation_status: Schema.Union([ + Schema.Literals(["observed", "table_missing", "unavailable"]).annotate({ + 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.", + }), + OpenString, + ]), + observed: Schema.Union([ + Schema.Struct({ + observed_at: Schema.String.annotate({ + description: "Time the catalog metadata was read.", + format: "date-time", + }), + partition_by: Schema.Array( + Schema.Struct({ column: Schema.String, transform: Schema.String }), + ).annotate({ + description: + "Active partition keys in key order, with transforms as the catalog reports them, for example bucket(16).", + }), + sort_by: Schema.Array( + Schema.Struct({ + direction: Schema.String, + expression: Schema.String, + nulls: Schema.String, + }), + ).annotate({ + description: "Active sort expressions in key order, as the catalog reports them.", + }), + }).annotate({ + 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.", + }), + Schema.Null, + ]), + schema: Schema.String.annotate({ description: "Source PostgreSQL schema of the table." }), + }), + id: Schema.String.annotate({ + description: "Source PostgreSQL table OID of a table replicated to Warehouse.", + }) + .check( + Schema.isMaxCodePoints(10).annotate({ expected: "a string with at most 10 code points" }), + ) + .check( + Schema.isPattern(new RegExp("^[1-9]\\d*$", "u")).annotate({ + expected: "a string matching the RegExp ^[1-9]\\d*$", + }), + ), + type: Schema.Literal("warehouse_table_layout").annotate({ description: "Resource type." }), + }), +}); export const V2GetWarehouseTeardownInput = Schema.Struct({ ref: Schema.String.check( Schema.isMinCodePoints(20).annotate({ expected: "a string with at least 20 code points" }), @@ -20398,6 +20537,7 @@ export const openApiOperationIdMap = { "v2-get-warehouse-setup": "v2GetWarehouseSetup", "v2-get-warehouse-status": "v2GetWarehouseStatus", "v2-get-warehouse-table": "v2GetWarehouseTable", + "v2-get-warehouse-table-layout": "v2GetWarehouseTableLayout", "v2-get-warehouse-teardown": "v2GetWarehouseTeardown", "v2-list-all-compute-instances": "v2ListAllComputeInstances", "v2-list-log-drains": "v2ListLogDrains", @@ -23628,6 +23768,20 @@ export const operationDefinitions = { inputSchema: V2GetWarehouseTableInput, outputSchema: V2GetWarehouseTableOutput, }, + v2GetWarehouseTableLayout: { + id: "v2GetWarehouseTableLayout", + description: + "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.\n\nThis endpoint is currently in its **Alpha** stage.", + method: "GET", + path: "/v2/projects/{ref}/warehouse/tables/{table_id}/layout", + pathParams: ["ref", "table_id"], + queryParams: [], + headerParams: [], + requestBody: { kind: "none" }, + response: { kind: "json" }, + inputSchema: V2GetWarehouseTableLayoutInput, + outputSchema: V2GetWarehouseTableLayoutOutput, + }, v2GetWarehouseTeardown: { id: "v2GetWarehouseTeardown", description: diff --git a/packages/api/src/generated/effect-client.ts b/packages/api/src/generated/effect-client.ts index dfcad4c47e..d8832c0141 100644 --- a/packages/api/src/generated/effect-client.ts +++ b/packages/api/src/generated/effect-client.ts @@ -3156,6 +3156,22 @@ export const versionedEffectOperations = { options, ); }), + getWarehouseTableLayout: ( + input: typeof operationDefinitions.v2GetWarehouseTableLayout.inputSchema.Type, + options?: SupabaseApiRequestOptions, + ): Effect.Effect< + typeof operationDefinitions.v2GetWarehouseTableLayout.outputSchema.Type, + SupabaseApiError, + SupabaseApiClient + > => + Effect.gen(function* () { + const client = yield* SupabaseApiClient; + return yield* client.execute<"v2GetWarehouseTableLayout">( + operationDefinitions.v2GetWarehouseTableLayout, + input, + options, + ); + }), getWarehouseTeardown: ( input: typeof operationDefinitions.v2GetWarehouseTeardown.inputSchema.Type, options?: SupabaseApiRequestOptions, diff --git a/packages/api/src/generated/openapi.json b/packages/api/src/generated/openapi.json index 253bef208c..e2c2c40eac 100644 --- a/packages/api/src/generated/openapi.json +++ b/packages/api/src/generated/openapi.json @@ -33084,6 +33084,126 @@ }, "x-scalar-stability": "experimental" } + }, + "/v2/projects/{ref}/warehouse/tables/{table_id}/layout": { + "get": { + "description": "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.\n\nThis endpoint is currently in its **Alpha** stage.", + "operationId": "v2-get-warehouse-table-layout", + "parameters": [ + { + "description": "Project ref", + "in": "path", + "name": "ref", + "required": true, + "schema": { + "example": "abcdefghijklmnopqrst", + "maxLength": 20, + "minLength": 20, + "pattern": "^[a-z]+$", + "type": "string" + } + }, + { + "description": "Source PostgreSQL table OID of a table replicated to Warehouse.", + "in": "path", + "name": "table_id", + "required": true, + "schema": { + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/V2WarehouseTableLayoutResponse_Output" + } + } + }, + "description": "" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Unauthorized" + }, + "403": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Forbidden action" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Table not replicated to Warehouse" + }, + "429": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Rate limit exceeded" + }, + "503": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponseBody" + } + } + }, + "description": "Warehouse feature, project metadata or table layout unavailable" + } + }, + "security": [ + { + "bearer": [] + } + ], + "summary": "Get the layout of a table replicated to Warehouse", + "tags": ["Projects Warehouse"], + "x-badges": [ + { + "name": "OAuth scope: database:read", + "position": "after" + }, + { + "name": "Alpha", + "position": "before" + } + ], + "x-endpoint-owners": ["pipelines"], + "x-fga-permissions": [["database_read"]], + "x-oauth-scope": "database:read", + "x-operation": { + "group": "warehouse.tables.layout", + "method": "get" + }, + "x-scalar-stability": "experimental" + } } }, "components": { @@ -49288,6 +49408,250 @@ }, "required": ["data"], "type": "object" + }, + "V2WarehouseTableLayoutResponse_Output": { + "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.", + "exclusiveMinimum": true, + "maximum": 2147483647, + "minimum": 0, + "type": "integer" + }, + "kind": { + "enum": ["bucket"], + "type": "string" + } + }, + "required": ["count", "kind"], + "type": "object" + } + ] + } + }, + "required": ["column", "transform"], + "type": "object" + }, + "nullable": true, + "type": "array" + }, + "sort_by": { + "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.", + "nullable": true, + "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], + "nullable": true, + "type": "string" + } + }, + "required": ["direction", "name", "nulls"], + "type": "object" + }, + "type": "array" + }, + "kind": { + "enum": ["columns"], + "type": "string" + } + }, + "required": ["columns", "kind"], + "type": "object" + } + ] + } + }, + "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.", + "nullable": true, + "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" + }, + "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 of a table replicated to Warehouse.", + "example": "16385", + "maxLength": 10, + "pattern": "^[1-9]\\d*$", + "type": "string" + }, + "type": { + "description": "Resource type.", + "enum": ["warehouse_table_layout"], + "type": "string" + } + }, + "required": ["attributes", "id", "type"], + "type": "object" + } + }, + "required": ["data"], + "type": "object" } } } diff --git a/packages/api/src/generated/permissions.ts b/packages/api/src/generated/permissions.ts index d074d62edf..85ddcad1f1 100644 --- a/packages/api/src/generated/permissions.ts +++ b/packages/api/src/generated/permissions.ts @@ -452,4 +452,5 @@ export const operationPermissions: Readonly "v2-get-warehouse-connection": { fga: [["database_read"]], oauthScope: "database:read" }, "v2-list-warehouse-tables": { fga: [["database_read"]], oauthScope: "database:read" }, "v2-get-warehouse-table": { fga: [["database_read"]], oauthScope: "database:read" }, + "v2-get-warehouse-table-layout": { fga: [["database_read"]], oauthScope: "database:read" }, }; From 69832718f83681503b704e1e5bdca9c157bdc369 Mon Sep 17 00:00:00 2001 From: Benjamin <5719034+bnjjj@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:56:42 +0100 Subject: [PATCH 5/5] chore(api): sync the Warehouse table layout table ID description --- apps/cli/src/commands/api/generated.schemas.ts | 2 +- apps/cli/src/commands/api/generated.ts | 2 +- packages/api/scripts/openapi-overrides.json | 4 ++-- packages/api/src/generated/contracts.ts | 2 +- packages/api/src/generated/openapi.json | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/cli/src/commands/api/generated.schemas.ts b/apps/cli/src/commands/api/generated.schemas.ts index c4a5e8b820..334a34bed9 100644 --- a/apps/cli/src/commands/api/generated.schemas.ts +++ b/apps/cli/src/commands/api/generated.schemas.ts @@ -1439,7 +1439,7 @@ export const apiCommandSchemas = { type: "object", }, id: { - description: "Source PostgreSQL table OID of a table replicated to Warehouse.", + description: "Source PostgreSQL table OID, as returned by the Warehouse tables list.", maxLength: 10, pattern: "^[1-9]\\d*$", type: "string", diff --git a/apps/cli/src/commands/api/generated.ts b/apps/cli/src/commands/api/generated.ts index 3b22b9cb0c..52f0e35045 100644 --- a/apps/cli/src/commands/api/generated.ts +++ b/apps/cli/src/commands/api/generated.ts @@ -265,7 +265,7 @@ export const apiCommands = [ }, argument: { name: "table-id", - description: "Source PostgreSQL table OID of a table replicated to Warehouse.", + description: "Source PostgreSQL table OID, as returned by the Warehouse tables list.", }, flags: [], bindings: [ diff --git a/packages/api/scripts/openapi-overrides.json b/packages/api/scripts/openapi-overrides.json index b30eff636c..53c67b1f0e 100644 --- a/packages/api/scripts/openapi-overrides.json +++ b/packages/api/scripts/openapi-overrides.json @@ -1494,7 +1494,7 @@ } }, { - "description": "Source PostgreSQL table OID of a table replicated to Warehouse.", + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", "in": "path", "name": "table_id", "required": true, @@ -1825,7 +1825,7 @@ "type": "object" }, "id": { - "description": "Source PostgreSQL table OID of a table replicated to Warehouse.", + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", "example": "16385", "maxLength": 10, "pattern": "^[1-9]\\d*$", diff --git a/packages/api/src/generated/contracts.ts b/packages/api/src/generated/contracts.ts index 11db7c91a7..07acba934a 100644 --- a/packages/api/src/generated/contracts.ts +++ b/packages/api/src/generated/contracts.ts @@ -15317,7 +15317,7 @@ export const V2GetWarehouseTableLayoutOutput = Schema.Struct({ schema: Schema.String.annotate({ description: "Source PostgreSQL schema of the table." }), }), id: Schema.String.annotate({ - description: "Source PostgreSQL table OID of a table replicated to Warehouse.", + description: "Source PostgreSQL table OID, as returned by the Warehouse tables list.", }) .check( Schema.isMaxCodePoints(10).annotate({ expected: "a string with at most 10 code points" }), diff --git a/packages/api/src/generated/openapi.json b/packages/api/src/generated/openapi.json index e2c2c40eac..bec32a428f 100644 --- a/packages/api/src/generated/openapi.json +++ b/packages/api/src/generated/openapi.json @@ -33104,7 +33104,7 @@ } }, { - "description": "Source PostgreSQL table OID of a table replicated to Warehouse.", + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", "in": "path", "name": "table_id", "required": true, @@ -49634,7 +49634,7 @@ "type": "object" }, "id": { - "description": "Source PostgreSQL table OID of a table replicated to Warehouse.", + "description": "Source PostgreSQL table OID, as returned by the Warehouse tables list.", "example": "16385", "maxLength": 10, "pattern": "^[1-9]\\d*$",