Skip to the page

Learn · Scale & operations

Branches

A branch is an isolated database beside main with its own endpoint, keys and sessions for development, pull requests and release rehearsals.

In the schema
—

Branches beside main#

A branch forks your project’s database from main onto one shard of the cluster. Each branch keeps separate rows, service keys and sessions, so schema pushes and writes on a branch never touch main.

Isolated branches

Each branch forks the main schema with separate rows, keys and sessions.

A branch answers at the project’s address followed by /branches/<name>. Every route of main answers under the branch’s address too, so an app switches branches by changing the address alone. For the project notes, main answers at https://notes.napalmdata.com and the branch dev-ada at https://notes.napalmdata.com/branches/dev-ada.

A branch name is up to 48 characters long. The name starts with a lowercase letter and holds only lowercase letters, digits and hyphens, such as pr-12.

New branches#

napalm branches create creates a branch from main and requires an org token with manage scope.

Terminal
# Clone main's schema and settings with empty tablesnapalm branches create notes dev-ada # Clone main's rows too and wait for the copy operationnapalm branches create notes rehearsal --data # Start a data copy in the background and print the operation idnapalm branches create notes trial --data --no-waitnapalm operations show <operation-id> --wait # Place a preview branch on the cluster's preview shard when configurednapalm branches create notes demo --preview # List branches alongside row status and shard volume usagenapalm branches ls notes
Schema only
Without --data, the branch copies main’s schema with empty tables and is ready as soon as the command returns.
--data
Copies main’s rows into the branch as well. Larger datasets take longer to copy, and napalm branches ls lists the branch as copying until the operation finishes. Writes to main after the snapshot stay on main.
--no-wait
Returns immediately with the operation id while branch creation continues in the background.
--preview
Routes the branch to the cluster’s single-machine preview shard away from main’s primary, or places it beside main when the cluster has no preview shard.
Other branches
Every other branch goes to the least full data shard. A cluster of one shard keeps every branch beside main.
Room
Branches may fill 80% of a shard’s volume. main and copied rows count toward the limit. Without room, the request fails with 409 volume_full.
Names
The request fails with 409 conflict when a branch with that name already exists or is still copying.

The Schema & branches API exposes the same operations over HTTP.

A new branch’s contents#

A new branch copies main’s schema and endpoint settings while starting with empty credentials and outbound bindings, so a branch never accepts main’s keys or calls main’s handlers.

Part of mainOn a new branch
Schema and extensionsCopied.
Endpoint settingsCopied (passthrough, browser origins and schema sharing). A change on the branch leaves main alone.
Sign-in settingsCopied (providers, redirect addresses and mail server).
RowsCopied with --data, including user accounts and file records. Copied file records reference main’s stored bytes, so deleting a file on the branch leaves main’s file intact. Built-in jobs (ext::napalm::Job) and sign-in sessions stay on main so queued jobs execute only once on main. Custom job subtypes copy with their fields in a cancelled state and never run on the branch.
Service keysNone. Each branch issues separate keys.
Session signing keyA new key, so a session from main never works on the branch.
Actions and hosted handlersNone, so the branch never calls main’s handlers.
SchedulesNone, so the branch never runs main’s schedules.
WebhooksNone, so main’s receivers never hear of writes or sign-in events on the branch.

Release rehearsals tries a whole release on a branch with a copy of main’s rows.

Keys, sessions and sign-in#

A branch admits only its own service keys and sessions. A branch refuses a service key issued for main, and main refuses a key issued for a branch. Issue branch-scoped keys with napalm keys create --branch.

Terminal
# A service key for the branch alone, shown oncenapalm keys create notes --label ci --branch pr-12 --days 7 # The accounts on a branch with copied rowsnapalm people ls notes --branch rehearsal

Each branch signs sessions with a separate key, so a person signed in on main signs in again on a branch. Data branches copy main’s accounts along with their email addresses and send sign-in mail through main’s mail server, whereas schema-only branches start empty so testers sign up fresh.

Service keys covers expiry, read-only keys and a key’s reach.

Deployed queries on a branch#

Deployed queries belong to main, so a branch serves no deployed queries by name. On a branch, the app sends each statement with the call. A client generated without napalm generate --deployed sends statement text directly, and napalm generate --branch checks every query against the branch’s schema during generation.

Terminal
# Generate a client whose queries are typechecked against the branch schemanapalm generate notes --lang ts --branch dev-ada # Typecheck dbschema/queries against the branch without deployingnapalm queries push notes --branch dev-ada # Allow statement passthrough from user sessions as well as service keysnapalm endpoint notes --branch dev-ada --passthrough all

The branch’s passthrough sets the callers allowed to send statements. all admits sessions and service keys, and keys admits service keys only. A schema push to a branch checks the queries in dbschema/queries against the new schema and deploys none.

Pull request branches#

A project that follows a GitHub repository gets a branch named pr-<number> for each pull request. Pull request branches are previews and land on the preview shard when configured.

Pull request previews

Every pull-request push updates an isolated branch and posts the migration plan.

A new pull request branch starts with main’s schema, or with main’s rows too when the project follows with --copy data. Give every pull request a branch sets up the GitHub App and a preview site for each pull request.

The GitHub App#

Napalm’s GitHub App manages the branch lifecycle from the first push through merge or close.

A push
The first push creates pr-<number>. Each push applies the pull request’s schema to the branch and edits one comment on the pull request in place. The comment shows the migration plan, each type’s root and the deployed query check. A new branch then runs the pull request’s dbschema/seed.edgeql if the file exists.
The check
The Napalm schema check fails when the schema does not apply, needs a decision or breaks a deployed query. A change that drops a type or field waits for Approve from someone with write access to the repository. A replace answer drops the old field and waits for the same approval.
Decisions
Each commit’s dbschema/decisions.yaml supplies migration answers for both pr-<number> and main. The comment lists applied decisions with rewritten row counts alongside any remaining decisions and their YAML snippets. Invalid YAML fails the check with the parser’s message.
Answers at a merge
Once a change has already applied on pr-<number>, later pushes to that branch skip its decision entry while main still uses the entry at merge time. Delete old entries from dbschema/decisions.yaml after merging to main.
A merge
Merging pushes the schema to main, drops pr-<number> and checks every other open pull request again against the new main. A project that follows with --no-push-main leaves main alone on a merge.
A close
Closing a pull request drops its branch.
Missed events
A nightly sweep compares each pull request branch with GitHub. The sweep drops the branch of a closed pull request and pushes a newer commit to the branch.

Pull request branches from your own CI#

Without the GitHub App, a workflow creates each pull request’s branch and posts the plan. napalm schema push --review prints the migration plan against main as Markdown and exits non-zero when the plan needs a decision or breaks a query. Both pushes read dbschema/decisions.yaml from the checkout. The review lists each decision still needed with YAML to add to the file. Migration decisions covers the file format.

.github/workflows/schema.yml
on: pull_requestjobs:  schema:    runs-on: ubuntu-latest    permissions:      pull-requests: write    env:      NAPALM_TOKEN: ${{ secrets.NAPALM_TOKEN }}      BRANCH: pr-${{ github.event.number }}    steps:      - uses: actions/checkout@v4      - run: curl -fsSL https://downloads.napalmdata.com/cli/install.sh | sh && echo "$HOME/.napalm/bin" >> "$GITHUB_PATH"      - run: napalm branches ls notes --json | grep -q "\"$BRANCH\"" || napalm branches create notes "$BRANCH"      - run: napalm schema push notes --branch "$BRANCH" --yes      - run: napalm schema push notes --review > review.md      - if: always()        run: gh pr comment ${{ github.event.number }} --edit-last --create-if-none --body-file review.md        env:          GH_TOKEN: ${{ github.token }}

A branch created from a workflow counts as a manual branch. Remove the branch when the pull request closes, or let the nightly sweep clean it up after 14 days without a schema push.

Personal branches#

Each developer can work against a branch created with napalm branches create. The app’s development build points at the branch’s address, and schema changes go to the branch with napalm schema push --branch. Develop against a personal branch sets up the branch, the endpoint and the app.

Moves between shards#

napalm branches move copies a branch to another shard of the same cluster. The branch keeps the same URL and serves from the source shard until cutover.

Unchanged branch URL

The branch keeps its URL and credentials while rows copy in the background.

Live shard cutover

Traffic switches to the target shard with only a brief write pause.

Pass the branch name and target shard label to start an online move.

Terminal
napalm branches move notes rehearsal --shard shard-k3m9x2p7qa

By default the branch serves during the copy, and writes pause briefly at the switch. With --pause, writes stop until the copy finishes. A branch that cannot publish changes pauses writes for the whole move.

main never moves, and a preview moves only onto the preview shard. A branch placed by root moves only after root placement is off. A shard without room answers 409 volume_full, and another copy or move of the branch answers 409 conflict.

Branch restores#

napalm branches restore rewinds a branch in place to a timestamp inside the backup window. The restore rewinds the branch’s whole shard, so every other branch on that shard goes back to the same moment. The command lists those co-located branches before prompting, and --with confirms those branches in non-interactive scripts. A preview on the preview shard never rewinds with main.

Restore a whole branch lists each refusal, and Point-in-time restore shows a restore in the terminal.

Branch removal#

Removing a branch drops its rows, closes open connections, revokes every service key issued for that branch and removes its hosted handler machines. main is the project itself and cannot be removed.

Terminal
napalm branches remove notes dev-ada

Removing a branch requires manage scope. A branch still copying main’s rows cannot be removed until the copy ends and answers 409 conflict in the meantime. An in-flight branch move or core copy holds the branch the same way.

Change logs of removed branches#

On a cluster that keeps a change log, a removed branch’s log stays readable until the branch’s retention window ends. The log’s stored bytes are billed until then.

Terminal
# List retained change logs from removed branches with sizes and deletion datesnapalm branches dropped notes # Read the last day of changes from a removed branchnapalm changes notes --branch rehearsal --since 1d # Set 90-day retention on branches and 30-day retention on pull request branchesnapalm branches keep notes --days 90 --pull-requests 30 # Purge one removed branch's retained change log immediatelynapalm branches forget notes rehearsal

napalm branches keep sets the window for every branch, for pull request branches or for one branch. Days beyond the included 30-day window are billed per GB-month. napalm branches forget purges a removed branch’s log immediately and stops retention billing after that day. The change log covers reading changes.

Type a word or two to search every docs page.