HTTP API: tables, migrations and history
Create and change tables, columns, indexes and constraints, row security, migrations (apply, dry-run, roll back, promote) and table history over HTTP.
Change the project's schema over HTTP: tables, columns, keys, indexes, owner-only rows, history and migrations. Most teams write SQL migrations instead (Migrations, Safe schema changes); these are what the table editor and the CLI call.
| Base URL | https://<project-ref>.sovarias.in — your project URL from Connect. |
| Keys | Send the project's key as apikey. Calls made for a signed-in user also send Authorization: Bearer <access token>. |
| Errors | A status code and {"detail": …} — a sentence, or {code, message} for errors your code may branch on (HTTP API). |
#Tables and columns
For the team and server keys; app users get 403. Every change is recorded as a migration you can roll back.
POST/api/v1/data/rel/create
Create a table.
Each change made through these endpoints is run as a recorded migration with down SQL, so it can be rolled back; rolling back a created table moves it to the sovaria_trash schema rather than deleting rows.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/create
Body
table_namestringrequired- 1–128 characters
columnsarray<object>required6 fields
namestringrequiredtypestringrequired- A Postgres type:
bigint,uuid,text,numeric(10,2),timestamptz,jsonb,text[]… is_primary_keybooleanoptionaldefaultfalsenullablebooleanoptionaldefaulttrueis_uniquebooleanoptionaldefaultfalsedefault_valuestring | number | booleanoptionalNULL,TRUE/FALSE, a number, a single-quoted string, orgen_random_uuid(),now(),CURRENT_TIMESTAMP,CURRENT_DATE,CURRENT_TIME,LOCALTIMESTAMP,timezone('utc', now()),'{}'::jsonb,'[]'::jsonb,'{}'::text[].
foreign_keysarray<object>optional3 fields
column_namestringrequiredreferenced_tablestringrequiredreferenced_columnstringrequired
Returns
migration_versionstring- The change is recorded as a migration with this version (a 17-digit UTC timestamp), so it can be rolled back (Migrations).
reversibleboolean- Whether it has down SQL.
Responses
- 200Success.
- 400No columns, an invalid type or default, a foreign key to a missing table or column, or Postgres refused it.
- 403App users can't change the schema; your role needs schema access.
- 503The project database is unavailable.
- 401No valid session or key.
curl -s -X POST "$URL/api/v1/data/rel/create" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "orders", "columns": [{"name": "id", "type": "bigint generated always as identity", "is_primary_key": true}, {"name": "customer_id", "type": "uuid", "nullable": false}, {"name": "total", "type": "numeric(10,2)", "default_value": 0}, {"name": "created_at", "type": "timestamptz", "default_value": "now()"}], "foreign_keys": [{"column_name": "customer_id", "referenced_table": "customers", "referenced_column": "id"}]}'Response
{
"status": "ok",
"table": "orders",
"migration_version": "20261018101500123",
"reversible": true
}POST/api/v1/data/rel/drop
Drop a table — recoverable: it moves to the sovaria_trash schema and rolling back the migration restores it.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/drop
Body
table_namestringrequired- The table.
- 1–128 characters
Returns
migration_versionstring- The change is recorded as a migration with this version (a 17-digit UTC timestamp), so it can be rolled back (Migrations).
reversibleboolean- Whether it has down SQL.
Responses
- 200Success.
- 409Other tables reference it — drop those foreign keys first.
- 403App users can't change the schema; your role needs schema access.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/drop" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "orders_old"}'Response
{
"status": "ok",
"table": "orders_old",
"migration_version": "20261018101500123",
"reversible": true
}POST/api/v1/data/rel/column/add
Add a column.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/column/add
Body
table_namestringrequired- The table.
- 1–128 characters
column_namestringrequired- New column.
- 1–128 characters
data_typestringrequired- Postgres type.
- at least 1 characters
is_nullablebooleanoptionaldefaulttrue- Allow NULL.
default_valuestring | nulloptional- Default (same forms as in create).
is_primary_keybooleanoptionaldefaultfalse- Make it the primary key.
is_uniquebooleanoptionaldefaultfalse- Add a unique constraint.
Returns
migration_versionstring- The change is recorded as a migration with this version (a 17-digit UTC timestamp), so it can be rolled back (Migrations).
reversibleboolean- Whether it has down SQL.
Responses
- 200Success.
- 403App users can't change the schema; your role needs schema access.
- 400An invalid name, type or default, a missing object, or Postgres refused the change (the message is Postgres's).
- 503The project database is unavailable.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/column/add" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "orders", "column_name": "status", "data_type": "text", "is_nullable": false, "default_value": "'pending'"}'Response
{
"status": "ok",
"table": "orders",
"column": "status",
"migration_version": "20261018101500123",
"reversible": true
}POST/api/v1/data/rel/column/alter
Change a column's default or whether it allows NULL.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/column/alter
Body
table_namestringrequired- The table.
- 1–63 characters
column_namestringrequired- The column.
- 1–63 characters
default_valuestring | integer | number | boolean | nulloptional- New default.
drop_defaultbooleanoptionaldefaultfalse- Remove the default.
nullableboolean | nulloptionaltrueallows NULL,falserequires a value.
Returns
appliedinteger- Statements run.
migration_versionstring- The change is recorded as a migration with this version (a 17-digit UTC timestamp), so it can be rolled back (Migrations).
reversibleboolean- Whether it has down SQL.
Responses
- 200Success.
- 400
NOT NULLwhile rows still hold NULL (Postgres's message). - 403App users can't change the schema; your role needs schema access.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/column/alter" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "orders", "column_name": "status", "nullable": false, "default_value": "'pending'"}'Response
{
"status": "ok",
"table": "orders",
"column": "status",
"applied": 2,
"migration_version": "20261018101500123",
"reversible": true
}POST/api/v1/data/rel/column/drop
Drop a column. Its values are kept in the trash schema when the table has a primary key, so a roll back restores them.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/column/drop
Body
table_namestringrequired- The table.
- 1–128 characters
column_namestringrequired- The column.
- 1–128 characters
Returns
data_restorablebooleanfalsewhen the table has no primary key: rolling back re-adds the column empty.migration_versionstring- The change is recorded as a migration with this version (a 17-digit UTC timestamp), so it can be rolled back (Migrations).
reversibleboolean- Whether it has down SQL.
Responses
- 200Success.
- 403App users can't change the schema; your role needs schema access.
- 400An invalid name, type or default, a missing object, or Postgres refused the change (the message is Postgres's).
- 503The project database is unavailable.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/column/drop" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "orders", "column_name": "note"}'Response
{
"status": "ok",
"table": "orders",
"column": "note",
"data_restorable": true,
"migration_version": "20261018101500123",
"reversible": true
}#Keys, indexes and constraints
POST/api/v1/data/rel/foreign-key/add
Add a foreign key.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/foreign-key/add
Body
table_namestringrequired- The table.
- 1–128 characters
column_namestringrequired- Its column.
- 1–128 characters
referenced_tablestringrequired- The table it points to.
- 1–128 characters
referenced_columnstringrequired- Usually that table's primary key.
- 1–128 characters
Responses
- 200Success.
- 400The column or referenced column doesn't exist, or the key points the wrong way (parent → child).
- 400Existing rows don't match (Postgres's message).
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/foreign-key/add" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "orders", "column_name": "customer_id", "referenced_table": "customers", "referenced_column": "id"}'Response
{
"status": "ok",
"table": "orders",
"column": "customer_id",
"referenced_table": "customers",
"referenced_column": "id",
"migration_version": "20261018101500123",
"reversible": true
}POST/api/v1/data/rel/foreign-key/drop
Drop a foreign key.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/foreign-key/drop
Body
table_namestringrequired- The table.
- 1–128 characters
column_namestringrequired- Its column.
- 1–128 characters
referenced_tablestringrequired- Referenced table.
- 1–128 characters
referenced_columnstringrequired- Referenced column.
- 1–128 characters
Responses
- 200Success.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/foreign-key/drop" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "orders", "column_name": "customer_id", "referenced_table": "customers", "referenced_column": "id"}'Response
{
"status": "ok",
"table": "orders",
"column": "customer_id",
"referenced_table": "customers",
"referenced_column": "id"
}POST/api/v1/data/rel/index/create
Create an index on up to 8 columns.
Without index_name the name is <table>_<columns>_idx (_key when unique). Created with IF NOT EXISTS.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/index/create
Body
table_namestringrequiredcolumnsarray<string>required- 1–8 items, no repeats
uniquebooleanoptionaldefaultfalsemethodstringoptionaldefaultbtree- One of
btree,hash,gin,gist,brin index_namestringoptional- up to 63 characters
Responses
- 200Success.
- 403App users can't change the schema; your role needs schema access.
- 400An invalid name, type or default, a missing object, or Postgres refused the change (the message is Postgres's).
- 503The project database is unavailable.
- 401No valid session or key.
curl -s -X POST "$URL/api/v1/data/rel/index/create" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "orders", "columns": ["customer_id", "created_at"]}'Response
{
"status": "ok",
"table": "orders",
"index": "orders_customer_id_created_at_idx"
}POST/api/v1/data/rel/index/drop
Drop an index of a table (restorable by rolling back).
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/index/drop
Body
table_namestringrequired- The table.
- 1–63 characters
namestringrequired- The index.
- 1–63 characters
Responses
- 200Success.
- 404No such index on that table.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/index/drop" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "orders", "name": "orders_customer_id_created_at_idx"}'Response
{
"status": "ok",
"table": "orders",
"index": "orders_customer_id_created_at_idx",
"migration_version": "20261018101500123",
"reversible": true
}POST/api/v1/data/rel/constraint/unique
Make a set of columns unique together.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/constraint/unique
Body
table_namestringrequired- The table.
- 1–63 characters
columnsarray<string>required- 1–8 columns.
- 1–8 items
constraint_namestring | nulloptional- Name (default
<table>_<columns>_key). - 0–63 characters
Responses
- 200Success.
- 400Existing rows have duplicates (Postgres's message).
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/constraint/unique" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "customers", "columns": ["email"]}'Response
{
"status": "ok",
"table": "customers",
"constraint": "customers_email_key",
"migration_version": "20261018101500123",
"reversible": true
}POST/api/v1/data/rel/constraint/check-values
Restrict a column to a fixed list of values (a CHECK constraint, like an enum).
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/constraint/check-values
Body
table_namestringrequired- The table.
- 1–63 characters
column_namestringrequired- The column.
- 1–63 characters
valuesarray<string | integer | number>required- 1–100 allowed strings or numbers.
- 1–100 items
constraint_namestring | nulloptional- Name (default
<table>_<column>_check). - 0–63 characters
Responses
- 200Success.
- 400Existing rows hold other values.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/constraint/check-values" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "orders", "column_name": "status", "values": ["pending", "paid", "shipped", "cancelled"]}'Response
{
"status": "ok",
"table": "orders",
"constraint": "orders_status_check",
"migration_version": "20261018101500123",
"reversible": true
}POST/api/v1/data/rel/constraint/drop
Drop a constraint (restorable by rolling back).
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/constraint/drop
Body
table_namestringrequired- The table.
- 1–63 characters
namestringrequired- The constraint.
- 1–63 characters
Responses
- 200Success.
- 409No such constraint on that table.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/constraint/drop" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "orders", "name": "orders_status_check"}'Response
{
"status": "ok",
"table": "orders",
"constraint": "orders_status_check",
"migration_version": "20261018101500123",
"reversible": true
}#Owner-only rows
GET/api/v1/data/rel/row-security
Whether a table has owner-only rows on, and on which column; every row policy and the column names.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/row-security
Query parameters
table_namestringrequired- The table.
- 1–63 characters
Returns
rls_enabled, forcedboolean- Postgres row-level security on, and applied to the table's owner too.
owner_policystring | null- The
sovaria_owner_rowspolicy's condition, ornull. policiesarray<object>- Every row policy on the table, ordered by name:
command(rselect,ainsert,wupdate,ddelete,*all),permissive,roles, andusing/checkas Postgres prints them (nullwhen absent). The app safety check reads these to tell which rows each caller reaches. columnsarray<string>- The table's column names, in order.
Responses
- 200Success.
- 401No valid session or key.
curl -s "$URL/api/v1/data/rel/row-security?table_name=notes" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN"Response
{
"table": "notes",
"rls_enabled": true,
"forced": true,
"owner_policy": "((current_setting('app.rls_bypass'::text, true) = 'on'::text) OR ((owner_id)::text = current_setting('app.user_id'::text, true)))",
"policies": [
{
"name": "notes_public_read",
"command": "r",
"permissive": true,
"roles": [
"public"
],
"using": "true",
"check": null
},
{
"name": "sovaria_owner_rows",
"command": "*",
"permissive": true,
"roles": [
"public"
],
"using": "((current_setting('app.rls_bypass'::text, true) = 'on'::text) OR ((owner_id)::text = current_setting('app.user_id'::text, true)))",
"check": "((current_setting('app.rls_bypass'::text, true) = 'on'::text) OR ((owner_id)::text = current_setting('app.user_id'::text, true)))"
}
],
"columns": [
"id",
"owner_id",
"title",
"created_at"
]
}POST/api/v1/data/rel/row-security
Turn owner-only rows on or off: each app user sees and changes only rows whose owner column is their id.
Turns on (and forces) Postgres row-level security with the policy sovaria_owner_rows: owner_column = the user's id, while the team and the service key still see everything. For a uuid or text owner column the column also gets the user's id as its default, so inserts fill it in. For other rules, write your own policies in SQL (Row-level security and access).
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/row-security
Body
table_namestringrequired- The table.
- 1–63 characters
owner_columnstringoptionaldefaultowner_id- The column holding the owner's user id.
- 1–63 characters
enabledbooleanoptionaldefaulttrue- On or off.
Responses
- 200Success.
- 400The column doesn't exist.
- 403App users can't change the schema; your role needs schema access.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/row-security" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "notes", "owner_column": "owner_id"}'Response
{
"status": "ok",
"table": "notes",
"owner_column": "owner_id",
"enabled": true,
"migration_version": "20261018101500123",
"reversible": true
}#Table history
GET/api/v1/data/rel/history
Tables that keep history, and the plan's limits.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/history
Returns
tablesarray<object>table,keep_days,enabled_at,versions(row versions kept) andoldest.limitsobjecttablesanddaysthe plan allows (db.history_tables,db.history_days).
Responses
- 200Success.
- 401No valid session or key.
curl -s "$URL/api/v1/data/rel/history" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN"Response
{
"tables": [
{
"table": "orders",
"keep_days": 7,
"enabled_at": "2026-10-10T08:00:00+00:00",
"versions": 18234,
"oldest": "2026-10-11T08:00:02+00:00"
}
],
"limits": {
"tables": 3,
"days": 7
}
}POST/api/v1/data/rel/history
Turn a table's history on (every row version kept) or off (versions dropped).
With history on, read past rows in SQL: select * from sov_as_of(null::orders, '2026-10-17 09:00+00'). Only the team and the service key can read history. The table needs a primary key (Table history (time travel)).
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/history
Body
table_namestringrequired- The table.
- 1–63 characters
enabledbooleanoptionaldefaulttrue- On or off.
keep_daysinteger | nulloptional- Days to keep (default and maximum: the plan's).
- 1.0–3650.0
Responses
- 200Success.
- 400The table has no primary key.
- 403
PLAN_LIMIT_REACHED— more tables or days than the plan allows. - 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/history" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"table_name": "orders", "keep_days": 7}'Response
{
"status": "ok",
"table": "orders",
"enabled": true,
"keep_days": 7,
"primary_key": [
"id"
],
"migration_version": "20261018101500123",
"reversible": true
}#Schema digest and plans
Read the whole schema in a few hundred tokens, and create or extend several tables in one checked, reversible step. Sovariq builds schemas this way; the CLI has sov db schema and sov db plan.
GET/api/v1/data/rel/schema/digest
The schema as one short line per table: columns with types, keys, references, allowed values, indexes and owner-only rows.
Legend (the first line): ! not null, =x default, pk primary key, uniq unique, →t foreign key to t's key (→t.col otherwise, then the on-delete action), in(a|b) allowed values, idx(..) index, rls:owner(col) owner-only rows, updated_at:auto kept current by a trigger, ~1.2k rows an estimate. A big schema lists every table and expands only the ones you name (plus the tables they reference and that reference them).
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/schema/digest
Query parameters
tablesstring | nulloptional- Comma-separated tables to expand in a big schema.
- 0–2,000 characters
max_charsintegeroptionaldefault6000- Length before the rest is listed briefly (default 6000; 0 = everything).
- 0–200000
sincestring | nulloptional- A version you already have: the answer is
unchangedwith no text when nothing changed. - 0–32 characters
Returns
versionstring- Changes whenever the schema does; send it back as
since. textstring- The digest: legend first, then one line per table, then
views: …. unchangedboolean- Only with
since, when nothing changed (notext).
Responses
- 200Success.
- 503
This schema operation needs the project's Postgres database— the project has none yet (still provisioning). - 401No valid session or key.
curl -s "$URL/api/v1/data/rel/schema/digest?tables=orders" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN"Response
{
"version": "79d083ae9b31",
"schema": "public",
"tables": 3,
"text": "# !=not null =default pk uniq →fk(table key) in()=allowed values idx()=index rls:owner(col)=owner-only rows updated_at:auto=kept current by a trigger\ncustomers(id uuid pk=gen_random_uuid(), email text! uniq, created_at timestamptz!=now()) ~1.2k rows\norders(id uuid pk=gen_random_uuid(), customer_id uuid →customers cascade, status text!='pending' in(pending|paid|shipped), total numeric(12,2)!, user_id uuid!=caller, created_at timestamptz!=now()) rls:owner(user_id) idx(customer_id) idx(user_id)\norder_items(id uuid pk=gen_random_uuid(), order_id uuid! →orders cascade, qty int!, created_at timestamptz!=now()) check(qty > 0) idx(order_id)"
}POST/api/v1/data/rel/schema/plan
Create or extend tables from one declarative plan: checked first, then applied as one reversible migration and verified.
Columns are objects ({name, type, nullable, default, unique, references, on_delete, values, check, index}) or the digest's short form: name type[!][=default] [pk] [uniq] [idx] [in(a|b)] [>0] [→table [cascade|setnull|restrict]]. Types are normalised (string → text, money → numeric(12,2), datetime → timestamptz); a reference without a type copies the key's type, and customer_id without a type refers to customers when it exists. New tables get id uuid primary key and created_at; references and owner columns get an index. Patterns: owner_rows (user_id + each signed-in user sees only their rows), public_read (with owner_rows: everyone reads, owners write), timestamps (updated_at kept current), soft_delete (deleted_at). Existing tables are extended, never retyped or dropped; sending the same plan again changes nothing. Roll it back with POST /api/v1/data/rel/migrations/rollback and its migration_version.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/schema/plan
Body
tablesarrayrequired[{name, columns, patterns, owner, primary_key, unique, indexes}], up to 30, in any order.dry_runboolean- Check it and return the SQL (
up_sql,down_sql) without applying. namestring- Migration name (default
schema plan: <tables>).
Returns
statusstringapplied,dry_run_okorunchanged.created / alteredarray / object- New tables; for extended tables what was added (
+column,idx(..),rls:owner(..)). digeststring- The touched tables as they now are.
verificationobject- What exists versus what the plan asked, per table;
problemslists any mismatch. notesarray- Things inferred or left as they were (e.g. a reference inferred from a name).
Responses
- 200Success.
- 422
{"message": "The plan has problems; nothing was changed…", "errors": ["orders.total: unknown type 'monee' — did you mean money?", "order_items.product_id → prodcts: no such table — did you mean products?"]}— every problem at once. - 400
Postgres refused the plan; nothing was changed: …(e.g. existing rows break a new rule). - 403App users, or an access policy that denies the change.
- 401No valid session or key.
curl -s -X POST "$URL/api/v1/data/rel/schema/plan" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"tables": [{"name": "orders", "patterns": ["owner_rows"], "columns": ["customer_id →customers cascade", "status text!='pending' in(pending|paid|shipped)", "total money! >=0"]}, {"name": "order_items", "columns": ["order_id →orders cascade", "product_id →products", "qty int! >0"], "unique": [["order_id", "product_id"]]}]}'Response
{
"status": "applied",
"migration_version": "20261018111530412",
"reversible": true,
"created": [
"orders",
"order_items"
],
"altered": {},
"notes": [],
"digest": "orders(id uuid pk=gen_random_uuid(), customer_id uuid →customers cascade, status text!='pending' in(pending|paid|shipped), total numeric(12,2)!, created_at timestamptz!=now(), user_id uuid!=caller) check(total >= 0) rls:owner(user_id) idx(customer_id) idx(user_id)\norder_items(id uuid pk=gen_random_uuid(), order_id uuid →orders cascade, product_id uuid →products, qty int!, created_at timestamptz!=now()) uniq(order_id,product_id) check(qty > 0) idx(product_id)",
"version": "a41f0c2e9d77",
"verification": {
"ok": true,
"checks": [
{
"check": "table orders",
"ok": true
},
{
"check": "table order_items",
"ok": true
}
]
}
}#Migrations
GET/api/v1/data/rel/migrations
Migration history, newest first.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/migrations
Query parameters
table_namestring | nulloptional- Only migrations whose SQL mentions this table.
limitintegeroptionaldefault100- How many (1–500).
- 1–500
offsetintegeroptionaldefault0- How many to skip.
- 0–…
Returns
versionstring- Digits; migrations run in version order.
statusstringappliedorrolled_back.sourcestringcli,api,console,promote…checksumstring- Of the up SQL: the same version with different SQL is refused.
sql, rollback_sql, timestamp, kind, seqmixed- Convenience copies for older clients.
Responses
- 200Success.
- 401No valid session or key.
curl -s "$URL/api/v1/data/rel/migrations?limit=20" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN"Response
{
"migrations": [
{
"version": "20261017143005000",
"name": "add orders status",
"up_sql": "alter table orders add column status text not null default 'pending';",
"down_sql": "alter table orders drop column status;",
"checksum": "9b2c…",
"status": "applied",
"source": "cli",
"applied_by": "6e19c0a2-…",
"applied_at": "2026-10-17T14:30:05.120000+00:00",
"rolled_back_at": null,
"rolled_back_by": null,
"duration_ms": 41,
"sql": "alter table orders add column status …",
"rollback_sql": "alter table orders drop column status;",
"reversible": true,
"timestamp": 1792247405.12,
"kind": "ALTER TABLE",
"seq": 20261017143005000
}
],
"total": 37
}POST/api/v1/data/rel/migrations/apply
Apply a migration and record it, all or nothing.
The up SQL runs in one transaction (don't include BEGIN/COMMIT; statements that can't run in a transaction, like CREATE INDEX CONCURRENTLY, are refused). Give down_sql to make it reversible. Without version, one is assigned (a timestamp). Applying the same version and SQL again is a no-op; the same version with different SQL is refused. Owners are emailed when a migration run from the CLI or API fails. sov db migrations push uses this (Migrations).
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/migrations/apply
Body
namestringrequired- Short name (letters, digits, spaces,
- _ . : / ( )). - 1–120 characters
up_sqlstringrequired- The change.
- 1–500,000 characters
down_sqlstring | nulloptional- How to undo it.
- 0–500,000 characters
versionstring | nulloptional- Digits, e.g.
20261018101500. - 0–32 characters
Responses
- 200Success.
- 400
Migration failed: <Postgres message> (at character N), no SQL, a bad name or version. - 409That version is already applied with different SQL, or no project database yet.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/migrations/apply" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"name": "add orders status", "up_sql": "alter table orders add column status text not null default 'pending';", "down_sql": "alter table orders drop column status;"}'Response
{
"version": "20261018101500123",
"name": "add orders status",
"status": "applied",
"duration_ms": 38,
"reversible": true
}POST/api/v1/data/rel/migrations/dry-run
Run a migration and roll it back: does it apply cleanly? Nothing changes.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/migrations/dry-run
Body
namestringrequired- Name.
- 1–120 characters
up_sqlstringrequired- The change.
- 1–500,000 characters
down_sqlstring | nulloptional- Undo.
- 0–500,000 characters
versionstring | nulloptional- Version.
- 0–32 characters
Responses
- 200Success.
- 400
Migration failed: <Postgres message>— it wouldn't apply. - 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/migrations/dry-run" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"name": "add orders status", "up_sql": "alter table orders add column status text not null default 'pending';"}'Response
{
"version": "20261018101500123",
"status": "dry_run_ok",
"duration_ms": 35
}POST/api/v1/data/rel/migrations/dry-run-sequence
Run several migrations in order and roll them all back — later ones see what earlier ones made.
What sov db migrations push --dry-run sends. Up to 500 migrations and 5 MB of SQL. On failure, failed.index is the first one that fails and checked how many ran cleanly before it.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/migrations/dry-run-sequence
Body
migrationsarray<object>required- 1–500 items
2 fields
namestringrequiredup_sqlstringrequired
Responses
- 200Success.
- 413More than 5 MB of SQL.
- 401No valid session or key.
curl -s -X POST "$URL/api/v1/data/rel/migrations/dry-run-sequence" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"migrations": [{"name": "create customers", "up_sql": "create table customers (id uuid primary key);"}, {"name": "orders customer", "up_sql": "alter table orders add column customer_id uuid references customers(id);"}]}'Response
{
"status": "dry_run_ok",
"checked": 2,
"total": 2,
"duration_ms": 61
}POST/api/v1/data/rel/migrations/rollback
Roll back the latest applied migration with its down SQL (or a given version with force).
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/migrations/rollback
Query parameters
versionstring | nulloptional- A specific version (needs
force=trueunless it's the latest). - 0–32 characters
forcebooleanoptionaldefaultfalse- Allow rolling back one that isn't the latest.
Responses
- 200Success.
- 404That version isn't applied.
- 409Nothing to roll back, it has no down SQL, or it isn't the latest (without
force). - 401No valid session or key.
curl -s -X POST "$URL/api/v1/data/rel/migrations/rollback?version=20261018101500123&force=true" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN"Response
{
"version": "20261018101500123",
"name": "add orders status",
"status": "rolled_back"
}POST/api/v1/data/rel/migrations/rollback-to
Undo every migration after a point (a time or a version), newest first, all or nothing.
If any of them has no down SQL nothing is undone and the answer lists the blockers. from_version includes that migration itself (undoing a Version History commit).
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/migrations/rollback-to
Body
sincestring | nulloptional- Undo migrations applied after this time.
versionstring | nulloptional- Undo those after this version.
- 0–32 characters
from_versionstring | nulloptional- Undo this one and those after it.
- 0–32 characters
dry_runbooleanoptionaldefaultfalse- Only check.
Responses
- 200Success.
- 400No point given.
- 409A down SQL failed (
Rolling back <name> (<version>) failed: …). - 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/migrations/rollback-to" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"version": "20261017143005000", "dry_run": true}'Response
{
"status": "dry_run_ok",
"rolled_back": [
{
"version": "20261018101500123",
"name": "add orders status"
},
{
"version": "20261017190000000",
"name": "orders index"
}
]
}POST/api/v1/data/rel/migrations/promote
Deploy a staging environment to production: its migrations, functions and policies, checked first.
Everything is first tried with nothing written: the pending migrations run on production and are rolled back, function bundles and policies are checked, and production's access is simulated with the new policies. If anything fails, or the simulation finds visitors would gain write access (unless accept_violations), nothing is deployed and status is failed or blocked. Then migrations are applied (each all or nothing), then functions, then policies, recorded as one Version History commit (Environments, staging and deploying to production).
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/migrations/promote
Body
from_env_idstringrequired- The staging environment's id.
- 36–36 characters
to_env_idstringoptional- 0–36 characters
from_namestringoptional- 0–64 characters
to_namestringoptional- 0–64 characters
dry_runbooleanoptionaldefaultfalse- Only check.
accept_violationsbooleanoptionaldefaultfalse- Deploy even if visitors would gain write access.
Returns
statusstringdry_run_ok,promoted,failed,blocked, orpartial(migrations went but a later step was unavailable —errorsays what).pending, applied, changesarray- Migration versions waiting, applied, and their names.
failedobject{version, name, error}of the migration that failed.functions, policiesobject- What each step did or would do.
simulation, blocked_byobject, array- The access check (Simulate access before you ship) and the violations that stopped the deploy.
Responses
- 200Success.
- 400That isn't a staging environment of this project.
- 409Either environment has no database yet.
- 503A step's service is unavailable; nothing was deployed.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/migrations/promote" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"from_env_id": "8d1e5c2a-4b7f-4e09-a3d6-1f2c9b8e7a50", "dry_run": true}'Response
{
"status": "dry_run_ok",
"applied": [],
"pending": [
"20261018101500123"
],
"changes": [
{
"version": "20261018101500123",
"name": "add orders status"
}
],
"functions": {
"status": "ok",
"dry_run": true,
"functions": [
{
"function_name": "send-receipt",
"change": "changed",
"env_version": 4,
"env_deploy_id": "dep_9a1…",
"production_version": 3
}
],
"settings": [],
"problems": [],
"names": [
"send-receipt"
]
},
"policies": {
"status": "ok",
"dry_run": true,
"policies": [
{
"name": "Signed-in users read orders",
"change": "changed",
"env_policy_id": "pol_5c…",
"replaces": "pol_orders_read",
"spl_source": "ALLOW IF …"
}
],
"drafts": [
{
"policy_id": "Signed-in users read orders",
"spl_source": "ALLOW IF …",
"replaces": "pol_orders_read"
}
],
"problems": []
},
"simulation": {
"kind": "policy",
"nothing_written": true,
"cases_checked": 48,
"changes": [],
"violations": [],
"summary": {
"gains": 0,
"losses": 0,
"violations": 0
},
"impact": []
},
"blocked_by": []
}#More endpoints
GET/api/v1/data/rel/cdc/capture
Whether the database records its own changes (writes over direct connections reach realtime and webhooks), for which tables, and the backlog.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/cdc/capture
Responses
- 200Success.
- 401No valid session or key.
curl -s "$URL/api/v1/data/rel/cdc/capture" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN"PUT/api/v1/data/rel/cdc/capture
Turn change capture on or off: tables null = every table (team + service key).
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/cdc/capture
Body
enabledbooleanrequiredtablesarray<string> | nulloptional- 0–500 items
Responses
- 200Success.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X PUT "$URL/api/v1/data/rel/cdc/capture" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN"POST/api/v1/data/rel/migrations/reset
Drop every user table and forget the migration history, in one transaction (what sov db reset runs). dry_run lists what would be dropped.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/migrations/reset
Body
dry_runbooleanoptionaldefaultfalse
Responses
- 200Success.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/migrations/reset" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN"GET/api/v1/data/rel/schema/diff
How two environments' databases differ (to_env '' = production): migrations to deploy and only in the target, and the tables, columns, indexes, constraints and row policies that would be added, changed or dropped. Read-only.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/schema/diff
Query parameters
from_envstringrequired- The environment to deploy from
- 36–36 characters
to_envstringoptional- The environment to deploy to ('' = production)
- 0–36 characters
Responses
- 200Success.
- 401No valid session or key.
curl -s "$URL/api/v1/data/rel/schema/diff" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN"POST/api/v1/data/rel/schema/diff/migration
Schema diff migration.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/schema/diff/migration
Body
from_envstringrequired- 36–36 characters
to_envstringoptional- 0–36 characters
include_dropsbooleanoptionaldefaultfalse
Responses
- 200Success.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/schema/diff/migration" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN"POST/api/v1/data/rel/schema/diff/migration/record
Record schema diff migration.
- Who
- Your team or your backend: a member's session, or a server key (
apikey: <service role or custom key>). Never from a browser or app. - Also at
/rest/rel/schema/diff/migration/record
Body
from_envstringrequired- 36–36 characters
to_envstringoptional- 0–36 characters
namestringrequired- 1–120 characters
sqlstringrequired- 1–2,000,000 characters
Responses
- 200Success.
- 401No valid session or key.
- 422The body is missing a required field or has a field of the wrong type.
curl -s -X POST "$URL/api/v1/data/rel/schema/diff/migration/record" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer $ACCESS_TOKEN"