All posts

Engineering3 min read

Rollback that brings the database with it

Rolling back code is easy. The hard part is the migration that already ran. Here is how Scaffold puts both back.

Code is the easy half

Rolling back code means pointing traffic at an older build. It takes seconds and nothing is lost. The trouble starts when the newer deploy changed the database: a dropped column, a renamed table, a backfill. The old code wakes up next to a schema it has never seen.

Many platforms roll back code only and leave the database to you. We wanted one button that puts the app back the way it was, data included, and says plainly what that costs.

A dump before every migration

When a deploy is about to run migrations, Scaffold dumps the database first. The dump sits next to the daily backups and is kept for 6 days. Deploys that don't migrate skip it, so the latest dump is always from just before the last schema change.

Build log
11:04:12  Migrations found: 211:04:12  Dumping the database before migrating11:04:19  Saved snap_2a91 (96 MB)11:04:20  Running migrations11:04:23  Live at pinecrest-web.scaffold.host

Two kinds of rollback

  • code puts the older build back. The database stays as it is now. Use it when the newer deploy didn't touch the schema.
  • code-and-database also restores the dump taken before the newer deploy migrated. Rows written since then are lost.

If no deploy since then ran migrations, there's no dump to restore, so the second option is disabled and the dialog says why.

What you lose. Restoring a dump removes every row written after it. The dialog shows the dump time before you confirm, and agents always ask a person first.

From your assistant

Rollback is a command like any other, so your assistant can run it over MCP or the SDK. A rollback is a new deploy that puts the earlier one back, so it shows up in history and can be rolled back the same way.

recover.ts
const deploy = await scaffold.deploy.get({ deploy: "dpl_3f9a2" }); if (deploy.status === "failed") {  await scaffold.deploy.rollback({    deploy: deploy.previous,    scope: "code-and-database",  });}

Try it

Rollback is on the Paid plan. Open a deploy, choose Roll back and pick what to restore. The docs cover the deploy.rollback command in full.

Get the changelog by email

One email a week, only when something ships.

RSSscaffold.llc/changelog.rss