Skip to main content

GET /api/v1/schemas

List all schemas with their fields. Supports cursor-based pagination.

Query Parameters

Response


POST /api/v1/schemas

Create a new schema. This creates both a metadata record and a real PostgreSQL table via DDL.
Creating a schema executes CREATE TABLE against the database. If the DDL fails, the metadata record is automatically rolled back.

Request Body

To bring a related entity (accounts, orders, addresses) into decisions, don’t flag it on the schema — create a Schema Join (Data → Schema Joins) with the customer schema as primary, the related schema as foreign, and aggregations (sum/count/avg/min/max/any/all/first) to roll up one-to-many rows.

Field Object

Example

Example with customPrimaryKey sugar

This is equivalent to passing fields: [{ "name": "account_id", "dataType": "varchar", "isPrimaryKey": true, "isNullable": false, "isUnique": true }] directly — pick whichever is more ergonomic for your use case. When set, the table is not given the default id BIGSERIAL auto-key. Response: 201 Created

Error Codes


PUT /api/v1/schemas

Update an existing schema’s metadata. Only provided fields are changed. This does not modify the underlying PostgreSQL table structure — use the field endpoints for DDL changes.

Request Body

Response: 200 OK with the updated schema object including fields.

Error Codes


DELETE /api/v1/schemas

Delete a schema and drop its backing PostgreSQL table.

Query Parameters

This drops the underlying database table. All data in the table is permanently lost.
Response: 204 No Content

GET /api/v1/schemas/fields

List the fields (columns) for a single schema. Used by the Schema Joins editor and any other UI surface that needs a column list without pulling the full schema object.

Query Parameters

Response: 200 OK with an array of field objects, sorted by ordinal.
Errors:
  • 400 Bad RequestschemaId query parameter missing
  • 404 Not Found — schema does not exist in caller’s tenant

POST /api/v1/schemas/fields

Add a column to an existing schema. Executes ALTER TABLE ADD COLUMN.

Request Body

Response: 201 Created with the field object on success, 200 OK when upsert: true matched an existing row.

Duplicate-name handling

Without upsert: true, the endpoint returns 409 Conflict if a field with the same name already exists on this schema:
This protects the metadata-vs-PG invariant — re-POSTing a field name without opting in won’t silently overwrite length/nullable/predictor flags while the real PG column stays unchanged.

PUT /api/v1/schemas/fields

Alter an existing column. Executes ALTER TABLE RENAME COLUMN and/or ALTER COLUMN TYPE / SET NOT NULL / DROP NOT NULL against the live table.

Request Body

Response: 200 OK with the updated field object.

Error Codes

Type changes run a USING cast on existing data. Narrowing casts that lose precision return 422 — the operation is refused, not silently truncated.

DELETE /api/v1/schemas/fields

Remove a column from a schema. Executes ALTER TABLE DROP COLUMN.

Query Parameters

This drops the column from the underlying table. Data in this column is permanently lost.
Response: 204 No Content

POST /api/v1/schemas//primary-key

Replace the live PostgreSQL PRIMARY KEY constraint on a schema’s ds_* table and sync each field’s isPrimaryKey flag to match. Supports composite keys (multiple columns). PK columns are forced NOT NULL (PostgreSQL requires it).

Path Parameters

Request Body

Response — 200 OK

primaryKey echoes the columns that now form the key (["id"] when reset), and isComposite is true when more than one column was supplied.

Error Codes

Roles

admin, editor

POST /api/v1/schemas//sync-table

Reconcile the live ds_* table with the schema’s field metadata. Use it to recover from drift — e.g. the table was dropped, a prisma db push ran, or a backup predates the schema’s fields. Never drops columns or tables: columns present in PostgreSQL but absent from metadata are reported in extraColumnsInPg, not removed.

Path Parameters

No request body.

Response

Returns 201 Created when the table was missing and had to be created, otherwise 200 OK. The status field distinguishes the three outcomes: "created", "patched", or "already-in-sync".

Error Codes

Roles

admin, editor

GET /api/v1/schemas//incoming-fks

List tables whose foreign-key constraints reference this schema’s ds_* table. Used by the blue_green target form to warn that a swap-table rebuild would fail while inbound FKs still point at the old table.

Path Parameters

Response — 200 OK

Error Codes

Roles

admin, editor, viewer

Roles

See also: Data Platform | Computed Values