Skip to the page

Reference · Control API

Schema & branches

Plan and apply migrations, typecheck statements, deploy queries, manage preview and data branches and automate GitHub pull requests.

In the schema
—

Schema migrations#

Schema and branch routes plan and apply declarative .gel migrations, typecheck EdgeQL statements, swap deployed query catalogs atomically and manage isolated database branches.

Transactional SDL diff and query guard

POST /projects/{id}/schema plans DDL from .gel files and recompiles every deployed query inside the migration transaction before committing.

Static policy and compiler diagnostics

Schema plans, GET /projects/{id}/schema/warnings and /check surface policy traversal advisories and inferred JSON schemas without reading row data.

RouteDescriptionScope
GET /projects/{id}/schema#Read the active SDL schema for main or a specified ?branch=Scoperead
POST /projects/{id}/schemaPlan or apply a declarative schema migration in a single transactionScopemanage
GET /projects/{id}/schema/warnings#Read the engine’s warnings for the schema of main or a specified ?branch=Scoperead

POST/projects/{id}/schema#

Request body

sdlstringrequired
Complete target schema in SDL syntax (concatenated .gel files), up to 512 KiB.
isAppliedboolean
When true, executes the planned DDL statements inside one atomic transaction. When omitted or false, returns the migration plan without modifying the database.
queriesobject[]
Optional list of named queries to compile and deploy atomically alongside the schema migration.
branchstring
Target branch name (defaults to main).
decisionsobject[]
Answers to migration prompts, matching dbschema/decisions.yaml. Each answer has a field and a kind: fill, convert or single with an expression, or rename with to and a choice of rename or replace.

The engine diffs your submitted SDL against the active catalog and returns the generated DDL in statements. When a migration step requires an expression for existing rows or the engine detects a possible rename, planning pauses with isComplete: false and lists the required inputs and prompt text in pendingDecisions. Pass your answers in decisions and plan again until isComplete is true. The response’s decisions lists each applied decision with rowCount for rewritten rows, while spentDecisions lists unused answers. Invalid decisions fail with 400 schema_invalid and type: DecisionError. Answer what a migration asks covers each kind.

The response also includes review, a Markdown summary of added or dropped objects, affected deployed queries and notify webhook triggers ready for pull-request comments.

Napalm applies the submitted SDL verbatim without injecting implicit lines. Every schema must declare using extension napalm; (which also enables auth, pgcrypto and ai), or the push fails with 400 schema_invalid naming the missing line in message. Any other extension omitted from the submitted SDL is dropped.

warnings lists non-blocking compiler advisories with message, hint, details and line, such as an allow policy that traverses another type without checking global caller. GET /projects/{id}/schema/warnings returns the active branch warnings without line numbers.

A branch takes 100 dry runs, tests, checks and plans a minute. Schema plans, index plans, query checks, erasure plans and file import plans each count as one. A check of many statements counts as one too. Past the limit these routes answer 429 rate_limited with the seconds to wait in Retry-After.

Plan a schema migration
curl https://api.napalmdata.com/projects/$PROJECT/schema \  -H "Authorization: Bearer $NAPALM_TOKEN" \  -H "Content-Type: application/json" \  -d "$(jq -n --rawfile sdl dbschema/default.gel '{sdl: $sdl}')"
Migration plan response
{  "isComplete": true,  "isApplied": false,  "statements": [    "ALTER TYPE default::Note {\n    CREATE PROPERTY archived: std::bool;\n};"  ],  "question": null,  "decisions": [],  "pendingDecisions": [],  "spentDecisions": []}

Statement typechecks#

POST/projects/{id}/check#

Send { "query": "…", "branch"?: "…" } to compile an EdgeQL statement against the project’s schema without executing it. The response reports compilation status, write classification, result cardinality, inferred parameter types and the JSON Schema of the output rows. Send up to 256 statements as queries to check them together. The response’s checks holds each statement’s check in the order sent. A statement holds at most 64 KiB. napalm generate sends its query files as queries to build typed client SDKs, and napalm test sends a suite’s statements the same way. Each request counts once against the branch’s 100 dry runs, tests, checks and plans a minute, regardless of how many statements the batch contains.

Questions in words#

POST/projects/{id}/ask#

Send { "question": "…", "answer"?: true } to ask main a question in plain words. The route answers as the Project API’s service context under the access rules rather than as one person, returning the synthesized EdgeQL statement, its rows and a prose summary. When a question asks for a data change, nothing commits: the response returns the unexecuted statement in proposed alongside dryRun with the before and after state of every affected object (or dryRunFailure with the reason when a preview cannot run).

Asking requires manage, answers 409 conflict while the Project API is disabled, schema sharing is off or passthrough is none, and times out after 120 seconds.

POST/projects/{id}/apply#

Send { "statement": "…" } to execute a proposed change once on main as the same service context under your access rules. The change log records the caller as { "kind": "service", "via": "console" }, and the route returns { "result", "count" }. Read-only statements, parameterized statements ($parameters) and statements that fail compilation return 400 invalid_request.

Applying requires manage scope and returns 409 conflict under the same conditions as /ask or when the Project API is read-only. Each applied statement is logged in the organization’s audit trail as projectChangeApplied with the acting manager.

Deployed queries#

RouteDescriptionScope
GET /projects/{id}/queries#List all currently deployed named queriesScoperead
POST /projects/{id}/queries#Typecheck and atomically replace the project’s deployed query setScopemanage
GET /projects/{id}/openapi.json#Export an OpenAPI 3.0 specification for all deployed queriesScoperead

Send { "queries": [{ "name": "getNote", "query": "…" }], "isDeployed": true } (up to 256 queries, 64 KiB each). Every query compiles against the active schema, and the catalog swaps atomically only when every statement succeeds. Omitting isDeployed validates the set without replacing active routes. See Actions, handlers & schedules to attach HTTP handlers or cron schedules to deployed queries.

Pushing a schema migration via POST /projects/{id}/schema recompiles all existing deployed queries inside the migration transaction unless you pass a replacement queries array in the same request, rolling back the DDL change whenever any deployed query would break.

Recommended indexes#

RouteDescriptionScope
POST /projects/{id}/schema/indexes#Plan or apply a secondary index recommended by query insights on mainScopemanage

Pass { "type": "default::Note", "properties": ["created_at"], "isApplied": true } to build a recommended index directly on main. Commit the matching index on (.created_at) declaration to dbschema/default.gel afterward so future full-schema pushes keep the index.

Database branches#

RouteDescriptionScope
GET /projects/{id}/branches#List main and all branches with shard placement, volume usage and API URLsScoperead
POST /projects/{id}/branchesCreate an isolated branch from main in an operation (schema-only or full data clone)Scopemanage
POST /projects/{id}/branches/{name}/move#Move a branch to another shard online or offline in an operationScopemanage
POST /projects/{id}/branches/{name}/remove#Remove a branch and reclaim its storageScopemanage
POST /projects/{id}/branch-restoresWind a branch back in place to an RFC 3339 targetTime in an operationScopemanage
POST /projects/{id}/branches/{name}/log-retention#Set how long the change log keeps one branch’s changesScopemanage

POST/projects/{id}/branches#

Request body

namestringrequired
Branch slug (a-z, 0-9 and hyphens). Served at https://<label>.napalmdata.com/branches/{name} with isolated keys, sessions and endpoint settings.
copyModestring
schema (default, main’s schema with empty tables) or data (main’s rows too). A branchCopy operation makes the branch in either mode.
isPreviewboolean
Places the branch on the cluster’s dedicated preview shard when one is configured.

The route waits up to 8 seconds for the branchCopy operation. If the copy finishes in time (as schema branches usually do), the route returns 200 OK with the ready branch. If the copy is still running (as data clones usually are), the route returns 202 Accepted with the branch, the operation and a Location header. Poll GET /operations/{id} until the operation completes and branch.isCopying clears. If the operation fails during the initial wait, no branch is created and the route returns 409 branch_copy_failed (or a specific status such as 409 cluster_unavailable) with message and operationId.

Branch creation fails with 409 volume_full once the target shard volume exceeds 80% utilization.

POST/projects/{id}/branch-restores#

POST /projects/{id}/branch-restores

?branchstring
Branch to rewind (defaults to main).
targetTimestringrequired
RFC 3339 timestamp within the cluster’s backup retention window.
otherBranchesstring[]
Exact list of other branches co-located on the same shard, acknowledging that shard-level point-in-time recovery rewinds every branch on that shard.

Mismatched co-located branch lists return 409 shard_holds_branches with the current branches array. Branches created or moved onto the shard after targetTime block the rewind with 409 branch_newer_than_moment or 409 branch_moved_after_moment until moved off or removed.

Create a data-cloned preview branch · curl
curl https://api.napalmdata.com/projects/$PROJECT/branches \  -H "Authorization: Bearer $NAPALM_TOKEN" \  -H "Content-Type: application/json" \  -d {    "name": "pr-12",    "copyMode": "data",    "isPreview": true  }
202 Accepted response
{  "branch": {    "name": "pr-12",    "isMain": false,    "isCopying": true,    "address": "https://notes-a1b2c3.napalmdata.com/branches/pr-12",    "lastMigration": "m1a2b3c4…",    "copyMode": "data",    "isPreview": true,    "isMoving": false,    "isReachable": true,    "shard": { "slug": "shard-preview-01", "shardType": "preview" }  },  "operation": {    "id": "0192c4a1-8e2f-7b3c-9d10-4f5e6a7b8c9d",    "operationType": "branchCopy",    "status": "pending"  }}
Restore main to an earlier moment · curl
curl https://api.napalmdata.com/projects/$PROJECT/branch-restores \  -H "Authorization: Bearer $NAPALM_TOKEN" \  -H "Content-Type: application/json" \  -d {    "targetTime": "2026-11-07T09:30:00Z",    "otherBranches": ["pr-12"]  }

GitHub integration#

RouteDescriptionScope
GET /github#List GitHub App installations connected to the organizationScoperead
POST /github/installs#Start a GitHub App installation flow and return the redirect URLScopemanage
GET /github/installations/{id}/repositories#List repositories accessible to a connected GitHub App installationScoperead
GET /projects/{id}/repository#Read the GitHub repository currently linked to the projectScoperead
POST /projects/{id}/repository#Link the project to a GitHub repository and configure PR branch automationScopemanage
POST /projects/{id}/repository/remove#Stop following the repository and clean up the automated preview branchesScopemanage

Linking a repository ({ "installationId": "…", "repositoryId": 123, "schemaPath": "dbschema", "pushesMainOnMerge": true, "branchCopyMode": "schema" }) automatically provisions a preview branch pr-<number> for every pull request, posts a live migration review comment, gates destructive changes on repository write-permission approval and applies the schema to main on merge. Each commit’s decisions.yaml in the schema folder answers the migration’s questions on the pull request’s branch, in the plan for main and at the merge.

Type a word or two to search every docs page.