Skip to the page

Learn · Scale & operations

Branches

A branch is a separate database beside main with a dedicated address, keys and sessions. Branches carry development, pull requests, rehearsals and previews.

In the schema
—

Branches beside main#

A branch is a Gel branch of the project’s database, and main is the project itself. Every branch lives on one shard of the cluster. A branch starts from main and then keeps separate rows, keys and sessions. A push or a write on a branch never changes main.

Isolated branch track at /branches/<name>

Every branch forks main’s schema onto an isolated database with separate rows, ndb_… service keys and session signing keys, so pushes and writes on a branch never touch main.

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 makes a branch from main. Making a branch takes the manage scope.

Terminal
# main's schema and settings, with no rowsnapalm branches create notes dev-ada # main's rows too. The command waits for the operation that copies the rows.napalm branches create notes rehearsal --data # Without waiting. The command prints the id of the operation that copies the rows.napalm branches create notes trial --data --no-waitnapalm operations show <operation-id> --wait # A preview, on the cluster's preview shard when the cluster has a preview shardnapalm branches create notes demo --preview # Every branch with the branch's rows, and the space branches take on the volumenapalm branches ls notes
Schema only
Without --data, the branch gets main’s schema and no rows. An operation makes every branch, and the branch is ready when 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 takes the same requests as these commands.

A new branch’s contents#

A new branch copies main’s schema and settings. The settings that act for main’s callers start empty, so a branch never admits main’s keys or calls main’s handlers.

Part of mainOn a new branch
Schema and extensionsCopied.
Endpoint settingsCopied, with passthrough, browser origins and schema sharing. A change on the branch leaves main alone.
Sign-in settingsCopied, with the providers, the redirect addresses and the 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 --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. A branch with copied rows holds main’s accounts, and a branch without rows holds none. On a branch without rows, people sign up as on a new project. Copied accounts hold real addresses, and the branch sends sign-in mail through main’s mail server.

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 --deployed sends statement text directly, and --branch checks every query against the branch’s schema during generation.

Terminal
# A client that sends each statement, with every query checked against the branch's schemanapalm generate notes --lang ts --branch dev-ada # The queries in dbschema/queries, compiled against the branch. Nothing deploys.napalm queries push notes --branch dev-ada # Statements from 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. 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.

Automated PR branch & schema check

Each pull request provisions pr-<number> on the preview shard and posts an updated migration plan, root classification and deployed-query compile check on every push.

The GitHub App#

A push
The first push makes 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
The commit’s dbschema/decisions.yaml goes with the schema. The push to pr-<number> and the plan for main both take the file’s answers. The comment lists each decision taken with the rows the answer rewrites, then each decision still needed with YAML to add to the file. A file that isn’t valid 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. Answer what a migration asks covers the file.

.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 made by a workflow counts as made by hand. 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 made 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 in an operation. The branch keeps the same address and answers from the old shard until the switch.

Branch Fork Rail

The branch preserves its /branches/<name> address and isolated credentials while rows stream off the source shard.

Shard Bay placement

Traffic switches cleanly onto the target data shard or preview shard bay with only a brief write pause at cutover.

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 takes a branch back in place to a moment 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 names those branches before asking, and --with names the same branches for a restore without a question. A preview on the preview shard never goes back with main.

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

Branch removal#

Terminal
napalm branches remove notes dev-ada

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

A branch still copying main’s rows cannot be removed until the copy ends, returning 409 conflict. 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
# Removed branches' logs, with the size and deletion date of each lognapalm branches dropped notes # A day of one removed branch's changesnapalm changes notes --branch rehearsal --since 1d # 90 days of changes for every branch, and 30 days for pull request branchesnapalm branches keep notes --days 90 --pull-requests 30 # One removed branch's log, deleted at oncenapalm branches forget notes rehearsal

napalm branches keep sets the window for every branch, for pull request branches or for one branch. Days past the included 30 days are charged. napalm branches forget deletes a removed branch’s log before the window ends, and the log’s charges end with the day. The change log covers reading changes.

Type a word or two to search every docs page.