Evolve a Kovlet schema and approve schema proposals
Change the tables of a Kovlet Data Space without breaking the other apps that use it. Safe changes apply at once, and risky ones wait for an owner to approve them.
On this page
At a glance
- Apps declare their tables in code (
t.string(),t.number(), …). On connect, Kovlet compares the declaration with the Data Space. - Applied at once, for any app with editor access: a new table, a new optional column (
.optional()),.indexed(), and a column order for a table that has none. - Anything that could break another app waits for an owner as a schema proposal. The app gets a
SchemaApprovalRequiredErrorand keeps syncing. - A column the app leaves out of its declaration is never dropped.
- An owner approves in the console under Safety (
https://kovlet.com/safety/<space id>). Approving checks every row first.
A table's schemaThe column definitions of every table in a Data Space. Additive changes apply at once; destructive ones become schema proposals. is its list of columns and their types. Kovlet sorts each change you make to it into one of two kinds:
- Additive changes apply on their own. They can't break another app.
- Destructive changes become a schema proposalA destructive schema change (drop, rename, change type, make required) that waits for a space owner to approve or reject it in the Kovlet console.. An owner of the Data Space approves it in the Kovlet console.
These changes become proposals: a new required column, making a column required, a type change, .unique(), and renames and drops. You send renames and drops with POST /v1/spaces/{space}/schema/changes or the MCP tool propose_schema_addition.
This guide adds a column that applies at once. Then it makes a change that waits for an owner, and walks the owner through approving it.
Tip To add a required column to a table that has rows, add it as optional, give every row a value, then make it required. Step 4 shows how. If a row has no value, approving fails with 409 rows_violate_schema, which names the rows to fix.
Before you start
- A Kovlet server. This guide uses a local
kovletd --devstarted with--dev-auto-approve, so the scripts connect without a browser. See Run Kovlet locally. Use the Docker image: it includes the console you need in step 4. - Against the hosted service, leave out
urlandconsoleUrl, and approve each run in the browser. - Node.js 22 or newer, and
npm i @kovlet/client tsxin an empty folder with"type": "module"in itspackage.json. - To approve proposals, the owner role on the Data Space. The person who created the space is its owner. Locally that is
dev@example.com, the user--dev-auto-approveacts as.
Step 1: Start with a table
Declare one table with one column:
import { createKovletClient, t } from "@kovlet/client";
export const kovlet = createKovletClient({
appName: "Expenses",
url: "http://127.0.0.1:8080", // kovletd --dev; leave out for https://api.kovlet.com
consoleUrl: "http://localhost:5173", // leave out for https://kovlet.com
spaces: {
main: {
tables: {
expenses: { amount: t.number() },
},
},
},
});Write one row, so the later steps have data to check against:
import { kovlet } from "./kovlet";
await kovlet.connect();
const expenses = kovlet.space("main").table("expenses");
await expenses.insert({ amount: 12.5 });
await kovlet.whenSynced();
console.log("space:", kovlet.space("main").spaceId);
console.log("rows:", expenses.all().length);
kovlet.disconnect();npx tsx seed.tsYou should see this (the IDs differ):
[kovlet] To connect Expenses, open http://localhost:5173/activate?user_code=V6Q3-RVGT and confirm code V6Q3-RVGT
space: 01a23730-72e9-74d4-9a74-024789ad000b
rows: 1With --dev-auto-approve, the code is approved at once. The app gets the Data Space named after it, "Expenses".
Note Keep the space ID. Step 4 opens it in the console.
Now add a script that prints the table's current columns and reports a pending approval. You run it after each change:
import { SchemaApprovalRequiredError } from "@kovlet/client";
import { kovlet } from "./kovlet";
kovlet.onError((err) => {
if (err instanceof SchemaApprovalRequiredError) {
console.log("waiting for an owner:", err.tables, err.proposalIds);
}
});
await kovlet.connect();
await kovlet.whenSynced();
const { expenses } = kovlet.space("main").schemas();
console.log("expenses:", JSON.stringify(expenses?.columns));
kovlet.disconnect();space.schemas() is the schema the server holds, not the one you declared.
Step 2: Add an optional column
Add note to the declaration as an optional column:
import { createKovletClient, t } from "@kovlet/client";
export const kovlet = createKovletClient({
appName: "Expenses",
url: "http://127.0.0.1:8080", // kovletd --dev; leave out for https://api.kovlet.com
consoleUrl: "http://localhost:5173", // leave out for https://kovlet.com
spaces: {
main: {
tables: {
− expenses: { amount: t.number() },
+ expenses: { amount: t.number(), note: t.string().optional() },
},
},
},
});
npx tsx main.tsYou should see
notein the printed columns, with"optional":true.
expenses: {"amount":{"type":"number"},"note":{"type":"string","optional":true}}The column was added when the app connected, before the first sync, with no approval. Every other app on the Data Space receives the new schema live. Existing rows have no value in note, which is fine for an optional column.
These changes apply at once in the same way:
| In the declaration | Change |
|---|---|
| A table the Data Space doesn't have | create_table |
A column the table doesn't have, with .optional() | add_column (optional) |
.indexed() on an existing column | add_index |
| The declared column order, on a table that has none | set_order |
Step 3: Make a change that needs approval
Make note required by removing .optional():
import { createKovletClient, t } from "@kovlet/client";
export const kovlet = createKovletClient({
appName: "Expenses",
url: "http://127.0.0.1:8080", // kovletd --dev; leave out for https://api.kovlet.com
consoleUrl: "http://localhost:5173", // leave out for https://kovlet.com
spaces: {
main: {
tables: {
− expenses: { amount: t.number(), note: t.string().optional() },
+ expenses: { amount: t.number(), note: t.string() },
},
},
},
});
npx tsx main.tsYou should see
waiting for an owner:, with the table and the proposal's ID.- The columns unchanged:
noteis still optional.
waiting for an owner: [ 'expenses' ] [ '01a23731-0e31-776d-8ec3-a986f2bc2dae' ]
expenses: {"amount":{"type":"number"},"note":{"type":"string","optional":true}}Kovlet did not apply the change. Instead:
- It recorded a schema proposal for an owner.
- It sent the app a
schema_proposal_requirederror. The client raises it asSchemaApprovalRequiredError, with thetablesandproposalIds.
The error is not fatal. The app stays connected and syncs. Only writes that need the new schema are rejected until an owner approves it. Connecting again with the same declaration reuses the pending proposal instead of making a new one.
What a declaration turns into a proposal:
| In the declaration | Proposal |
|---|---|
A new column without .optional() on an existing table | add_column (required) |
An optional column declared without .optional() | make_required |
A different type, or a t.ref() to another table | change_type |
.unique() on an existing column | add_unique |
Some differences are ignored:
- A column the declaration leaves out. Deleting a line from your code never drops data.
- A column the app declares optional that the Data Space stores as required.
Renames and drops have no declaration form. Request them as in step 5.
In a React app, read the same error from useSyncStatus().error. Tell the user that an owner needs to approve the change.
Step 4: Approve the proposal in the console
An owner of the Data Space approves or rejects proposals in the Kovlet console:
- Open Safety for the Data Space:
http://localhost:5173/safety/<space id>locally, orhttps://kovlet.com/safety/<space id>. You can also pick Safety in the console's navigation and choose the space. - Find the card marked Waiting for approval: "Expenses wants to change
expenses". It lists each change, the number of rows affected, and the other apps that use the table (May break). - Click Approve change, then Approve change again in the dialog. Or click Reject, and the schema stays as it is.
Here the approval fails, because the row from step 1 has no note. The card shows the error, and the proposal stays pending. Over the API, the same refusal is HTTP 409:
{"error": {"code": "rows_violate_schema", "message": "make_required on expenses.note: 1 rows have no value in note",
"table": "expenses", "column": "note", "op": "make_required", "reason": "required_missing",
"type": "string", "count": 1, "examples": ["01a23730-86fc-7497-ac8e-70360827db02"],
"hint": "Give these rows (trashed ones included) a value in note, then approve again; the proposal is still pending."}}Kovlet never rewrites rows to fit a stricter schema. It has no default values or backfill. So give every row a value first. An update reaches rows in the TrashWhere deleted rows and files go. Deletes are soft: a trashed row or file keeps its data and can be restored. too:
import { kovlet } from "./kovlet";
await kovlet.connect();
await kovlet.whenSynced();
const expenses = kovlet.space("main").table("expenses");
for (const row of expenses.all()) {
if (row.note == null) await expenses.update(row.id, { note: "" });
}
await kovlet.whenSynced();
console.log("rows without a note:", expenses.all().filter((row) => row.note == null).length);
kovlet.disconnect();npx tsx backfill.tsrows without a note: 0Caution table.all() lists live rows only. If the table has rows in the Trash, restore them or update them by ID too. Otherwise the approval names them in examples.
Click Approve change again. The change applies, and every app that uses expenses gets the new schema right away. main.ts now connects with no error:
npx tsx main.tsexpenses: {"amount":{"type":"number"},"note":{"type":"string"}}This is the safe way to add a required column to a table that has rows: add it as optional, give every row a value, then make it required. A required column added in one step can only be approved while the table has no rows, live or trashed.
Step 5: Rename or drop a column
Renames and drops are explicit changes. An app, a script or a coding agent with editor access sends them. They become proposals, just like in step 3.
With the local server, kovletd dev seed gives you an app token for the "Expenses" space. With Docker, prefix it with docker exec kovletd.
eval "$(kovletd dev seed --env --space Expenses)"
curl -s -X POST "$KOVLET_URL/v1/spaces/$KOVLET_SPACE_ID/schema/changes" \
-H "Authorization: Bearer $KOVLET_TOKEN" -H "Content-Type: application/json" \
-d '{"changes": [{"op": "rename_column", "table": "expenses", "column": "note", "new_name": "memo"}]}'The answer is HTTP 202 with the proposal (shortened):
{"tables": {"expenses": {"version": 3, "columns": {"amount": {"type": "number"}, "note": {"type": "string"}}, "order": ["amount", "note"]}},
"ops": [],
"proposals": [{"id": "01a23731-ae8c-7efe-b02f-05eeb0ec7d53", "table": "expenses", "base_version": 3,
"changes": [{"op": "rename_column", "table": "expenses", "column": "note", "new_name": "memo"}],
"status": "pending", "proposed_by": {"user_id": "…", "machine_id": "…", "app_id": "…"}}],
"head_seq": 5}How the server handles changes:
- It is a list, applied in order.
- The whole list must fit the current schema. Otherwise the call fails with
422 invalid_changeand nothing changes. - Additive changes in the list apply at once. The answer is HTTP 200 when every change is additive.
- Destructive changes become one proposal per table (HTTP 202).
The ops:
| Op | Fields | Applies |
|---|---|---|
create_table | table, columns, order (optional) | at once |
add_column | table, column, def ({"type": "string", "optional": true}) | at once if optional, else a proposal |
set_order, add_index | table, order / column | at once |
rename_column | table, column, new_name | proposal |
drop_column | table, column | proposal |
change_type | table, column, def (the new type, and ref_table for a ref) | proposal |
make_required | table, column | proposal |
rename_table | table, new_name | proposal |
drop_table | table | proposal |
add_unique, drop_unique, drop_index | table, column | proposal |
A coding agent sends the same changes with the MCP tool propose_schema_addition ({space, changes}). It can also add tables and optional columns with {space, tables}. See Connect a coding agent (MCP).
The owner approves the rename in Safety, as in step 4. Then update every app's declaration to the new name (memo: t.string()) right away.
Caution An app that still declares the old name asks for it again on its next connect. An optional column comes back at once as a new, empty column. A required one becomes a new proposal.
What approving a destructive change does to the data:
- Drop a column: the values are removed from every row. Their earlier values stay in the Data Space's activity history.
- Drop a table: its rows go to the Trash. A new table with that name later is accepted only if those rows fit its columns (
409 trashed_rows_conflictotherwise). - Rename: every row is rewritten to the new name.
make_required,change_type, requiredadd_column: existing rows are checked, not changed (409 rows_violate_schema).add_unique: refused with409 unique_violationwhile live rows share a value. The error lists them induplicates.
Step 6: List and decide proposals over the APIOptional
Any session with at least viewer access can list proposals:
curl -s "$KOVLET_URL/v1/spaces/$KOVLET_SPACE_ID/schema/proposals?status=pending" -H "Authorization: Bearer $KOVLET_TOKEN"{"proposals": [{"id": "01a23731-ae8c-7efe-b02f-05eeb0ec7d53", "space_id": "01a23730-72e9-74d4-9a74-024789ad000b", "table": "expenses",
"base_version": 3, "changes": [{"op": "rename_column", "table": "expenses", "column": "note", "new_name": "memo"}],
"status": "pending", "proposed_by": {"user_id": "…", "machine_id": "…", "app_id": "…"},
"created_at": "2026-12-02T14:38:52.556985Z"}]}status is pending, approved, rejected or superseded.
Deciding is for owners in the console. POST /v1/spaces/{space}/schema/proposals/{id}/approve and …/reject need the owner role and a console session. An app, a script or an agent gets 403 scope_required.
That is on purpose. An app can ask for a breaking change, but only a person who owns the data can accept it.
Troubleshooting
| What you see | Why | What to do |
|---|---|---|
SchemaApprovalRequiredError / schema_proposal_required on connect | The declaration has a destructive change (step 3). | Ask an owner to approve it in Safety, or change the declaration back. |
409 rows_violate_schema when approving | Rows (trashed ones included) have no value, or a value of another type, for the new definition. examples lists up to 5 IDs. | Fix those rows, then approve again. The proposal stays pending. |
409 proposal_stale when approving | The table changed after the proposal was made. The proposal is now superseded. | Connect the app again, or send the change again, to make a new proposal. |
409 unique_violation when approving add_unique | Live rows share a value; duplicates lists them. | Make the values unique, then approve again. |
409 rules_invalid when approving | The change drops or renames a column the space's end-user rules read. | Update the rules first. |
409 trashed_rows_conflict | A new or renamed table takes the name of a dropped table whose rows in the Trash don't fit it. | Declare columns those rows fit, or restore and fix them. |
409 proposal_decided | Someone already approved or rejected it. | Nothing to do. |
403 scope_required on approve or reject | Apps and agents can't decide proposals. | Approve as an owner in the console. |
422 invalid_change | A change is malformed or doesn't fit the current schema (for example a column that doesn't exist). Nothing changed. | Read the schema (GET /v1/spaces/{space}/tables) and fix the change. |
| A new empty column appears after a rename | An app still declares the old name as optional. | Update that app's declaration. |
KovletAuthError: the user denied the request right after the code appears, on kovletd --dev --dev-auto-approve | Every run of a Node script without a persistent storage signs in as a new personal device, and the free plan allows 10. The kovletd log says quota exceeded: devices limit is 10. | Start from an empty server (Run Kovlet locally). |
Every error code is in the errors and limits reference.
Next
- Upload and sync files:
t.fileRef()columns andspace.files. - Roll back an app's changes: undo what one app wrote, from the same Safety view.
- Kovlet sync protocol reference: how
hello.schemaand schema changes work on the wire.
Ready to try it? Start free. No credit card, no API keys.
For coding agents: this page is also Markdown. Add .md to the URL or send Accept: text/markdown. The full reference is at /llms-full.txt.