Skip to the page

Guides · Shipping & operations

Rollbacks and restores

Undo a bad release with the smallest fix that covers the damage, from one query file up to one customer’s rows or a whole branch.

API
—
In the schema
—

What you’ll build#

This page undoes a bad release. The fixes run from one query file up to a whole branch. A larger fix takes back more of the work done since the release, so start with the smallest fix that covers the damage.

ProblemFixAlso undone
A bad queryPush the previous query filesAlso undoneNo rows
A bad schema changePush the previous schemaAlso undoneThe release’s additions and the values written since
Bad writes to one customer’s rowsRestore the customer’s rootAlso undoneEvery write to that root after the moment
Bad writes across a branchRestore the branchAlso undoneEvery write after the moment on every branch of the shard

No fix reaches outside the database. Email, charges and other work done by jobs and actions stay done. Release rehearsals tries a release on a copy of main’s rows before main gets the release.

Before you start#

You need the first app’s project and a git repository that holds the project’s schema and query files. Every fix on this page needs a manager of the org. Sign in as a manager with napalm login or use a token with the manage scope.

Restores require backups and pinpointing a bad write requires the change log, so verify both settings before a release goes wrong.

Terminal
# Backups and the change log, with the days each keepsnapalm storage show <cluster> # A longer restore window, kept from the next nightly backup onnapalm storage keep <cluster> backups --days 30 # The change log, when the cluster keeps none yetnapalm storage enable <cluster> log
Restore window
Backups reach back 7 days at no charge and cover every moment up to 60 seconds ago. Extending retention costs $50 for 14 days, $100 for 30 days or $250 for 90 days per cluster each month plus standard storage for the retained backups, and takes effect from the next nightly backup, so widen the window before a risky release.
Change log
napalm changes reads the cluster’s change log. A cluster without a change log refuses the command with 409 change_log_not_configured.

Scale & recovery covers the backups and the window’s settings.

Find the bad change#

napalm activity lists recent org events alongside each author, recording schema pushes as project schema migrated and query pushes as project queries deployed. napalm changes lists every commit on a branch with its timestamp, caller and mutated types, and never exposes row values.

Value-blind commit & deploy timeline

napalm activity pairs org-level schema and query pushes with napalm changes, pinpointing the last clean RFC 3339 timestamp by caller kind and mutated type without exposing row values.

Terminal
# The org's recent changes, newest first, with the author of each changenapalm activity --limit 20 # Every commit on main in the last two hours: the time, the caller and the changed typesnapalm changes notes --since 2h

Pick the last moment before the first bad commit or push. --to takes an RFC 3339 time or a local time without an offset. napalm activity --json gives each event’s exact insertTime.

Further back
--since 1d reads a day back. --after continues from the bookmark at the end of the output.
A spread branch
The change log does not yet cover a spread branch, so napalm changes refuses the branch with 409 branch_distributed. Take the timestamp from napalm activity instead.

Roll back a deployed query#

A deployed query is a file in dbschema/queries. napalm queries push compiles every file in the folder against main’s schema and deploys the folder in place of the whole deployed set. Revert the commit in your repository and push the folder again. No rows change.

Terminal
# Undo the commit that changed the querygit revert <commit> # Compile every file against main's schema, then deploy the folder in place of the deployed setnapalm queries push notes --checknapalm queries push notes
A followed repository
Open and merge a pull request that reverts the commit to redeploy the prior schema and queries. Environments & going live sets up that deploy.
A query the release added
The reverted folder no longer holds the new query, so the push stops serving it. The command asks first, and --yes skips the prompt in CI.
A schema change too
Nothing deploys while any query fails to compile. When the release changed the schema too, revert both commits and run napalm schema push. The schema push deploys the queries in the same migration.
The app
The app calls each deployed query by name with its declared variables. Roll the app back in the same deploy so client and database stay in sync.

Roll back a schema change#

The schema is a file in the repository too. Revert the commit and run napalm schema push. The push applies the previous schema and deploys the queries in dbschema/queries in one migration. Run the push with --plan first. The plan lists every statement and highlights each drop.

Terminal
# Undo the commit that changed the schemagit revert <commit> # The plan, with each drop highlighted. Nothing applies.napalm schema push notes --plan # The previous schema and the queries in dbschema/queries, in one migrationnapalm schema push notes
Added a property, link or type
Drops the addition and the values written since the release. The push asks before any drop.
Changed an access rule
Restores the prior rule immediately. A rule holds no rows, so no data is lost.
Added an index or constraint
Drops the index or constraint without changing any rows.
Dropped a property, link or type
Re-adds the schema definition with empty values (requiring a default for required fields). Dropped values survive only in backups.

In a followed repository, revert through a pull request. The pull request’s check shows the plan, and a revert that drops something needs a repo writer’s approval before the merge. Branches covers the check.

Restore one customer’s rows#

napalm placement restore-root takes one root of a branch back to a moment. A root is the object that owns a group of rows, such as a customer’s organization. Napalm takes the root’s rows back from the shard’s backups while the shard keeps serving, and no other root changes.

Surgical root rewind

On a spread branch, napalm placement restore-root rewinds one customer’s root UUID and descendant rows from shard backups while co-located roots keep serving.

Whole-shard branch restore

On a single-shard branch, napalm branches restore --to rewinds the shard in place behind an unchanged URL after confirming any co-located branches via --with.

Terminal
# Placement must read "spread across shards"napalm placement show notes # One root back to the moment. Writes to the root after the moment are lost.napalm placement restore-root notes <root-id> --to 2026-11-14T16:20:00Z --wait
A spread branch
napalm placement show must report the branch’s roots as spread across shards. A branch with every row on one shard is refused, and the command points to napalm branches restore instead.
The root’s id
The id of the root object, such as an organization’s id. The root must still hold rows on the branch. A root with no rows left answers 404 not_found.
The moment
A past time inside the shard’s backups. Any other moment answers 400 invalid_request.
Later writes
Writes to the root after the moment are lost. The command asks first, and --yes skips the question.
Other branches
--branch pr-12 restores a root of another branch instead of main. A move or another operation on the branch answers 409 cluster_busy.

Multi-tenant B2B SaaS spreads organizations across shards and restores one organization.

Restore a whole branch#

napalm branches restore takes a branch back in place to a moment. The branch is main unless the command names another branch. The address stays the same, and every write after the moment is lost.

A branch restore rewinds the branch’s whole shard. Every other branch on that shard goes back to the same moment, and the shard stops answering until the restore finishes. The command names the other branches before asking. With --yes, --with must name exactly those branches.

Terminal
# The question names every other branch on the shardnapalm branches restore notes --to 2026-11-14T16:20:00Z # The same restore without a question, with every other branch on the shard namednapalm branches restore notes --to 2026-11-14T16:20:00Z --with dev-ada,pr-12 --yes
RefusalCause
409 shard_holds_branches--with does not name the exact other branches on the shard. The refusal lists those branches.
409 branch_newer_than_momentA branch on the shard was made after the moment. Remove the branch or pick a later moment.
409 branch_moved_after_momentA branch was moved onto or off the shard, copied or placed after the moment. Pick a later moment.
409 branch_distributedThe branch is spread across shards, shares the shard with a spread branch or has a core copy. Restore by root instead.
409 backups_not_configuredThe cluster keeps no backups.
409 cluster_busyAnother operation is running on the cluster or the branch.
400 invalid_requestThe moment is not in the past or comes before the branch was created.

Scale & recovery shows a restore in the terminal. The Schema & branches API takes the same restore as POST /projects/{id}/branch-restores.

Follow up on work outside the database#

A restore rewinds database rows, while side effects outside the database stay completed. Actions and jobs that call a handler send email, charge cards and call models outside the database transaction, so reconcile any external side effects triggered after the restore point.

Email and charges
An email sent after the moment stays sent, and a charge stays on the card. Send a correction or refund the charge through the payment provider.
The handler’s record
A handler records an outcome through call.db() as rows, and the restore takes those rows back. The database then shows no charge for a charge that still happened. Compare the restored rows with the payment provider’s records.
Events from senders
A restore also takes back the events an inbound webhook recorded after the moment. After a success, most senders never send an event again, so resend those events from each sender’s dashboard. The route in Receiving webhooks keeps each event once, so resending an event the database still holds does no harm.

Check the recovery setup#

  1. Read the restore window

    napalm storage show <cluster> lists backups as on, kept 30 days after the change above.

  2. Find a write in the change log

    Add a note in the app and run napalm changes notes --since 10m. The output shows the commit with Note (1 added) and a session as the caller.

  3. Plan a schema rollback

    Check out the commit before your last schema change and run napalm schema push notes --plan. The plan lists the statements, and main doesn’t change.

  4. Start a restore and answer no

    Run napalm branches restore notes --to with a time ten minutes ago. The question names any other branch on main’s shard. Answer N, and nothing changes.

Type a word or two to search every docs page.