Save a Mark before every deploy
One step in your deploy workflow saves a named restore point before every migration.
Most bad database days start with a deploy: a migration drops the wrong column, or a backfill rewrites a million rows. Save a Mark right before each deploy, and you know exactly where to rewind to.
This is part of Guard, the same safety net AI agents use.
GitHub Actions
Create an API key
In the dashboard, open Settings, API keys, and create a read-write key named after the workflow, like deploy-ci. Or from a terminal:
rowsafe api-keys create deploy-ciSave it as a secret
In your GitHub repository, open Settings, Secrets and variables, Actions, and add a secret named ROWSAFE_API_KEY. If your deploy job uses an environment, put it there.
Add the step before your migrations
- name: Save a Mark before the migration
uses: rowsafe/action@v1
with:
api-key: ${{ secrets.ROWSAFE_API_KEY }}
database: app
- run: npx prisma migrate deploydatabase is the name in the dashboard. Leave it out if your repository has a .rowsafe.json (from rowsafe init app) or your organization has one database.
On each deploy, the step:
- checks that
appcan be restored right now, and warns if not; - saves the Mark
before-deploy-<commit>and waits until it's confirmed in your bucket (usually seconds); - adds a summary to the run: the Mark, the backup a rewind starts from, and a Rewind to this Mark link.
If the Mark can't be confirmed, the step fails, so the migration never runs without one.
Complete workflows
name: deploy
on:
push:
branches: [main]
concurrency: deploy-production
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # lets the preview find the migrations this push adds
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- uses: rowsafe/action@v1
with:
api-key: ${{ secrets.ROWSAFE_API_KEY }}
database: app
preview-sql: prisma/migrations/*/migration.sql
- run: npx prisma migrate deploy
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}Stop deploys when backups aren't working
By default the action only warns when the database can't be restored right now (for example, changes stopped reaching your bucket, or no restore test passed in 8 days). With require-protected: true, it stops the job before the migration and lists the reasons:
- uses: rowsafe/action@v1
with:
api-key: ${{ secrets.ROWSAFE_API_KEY }}
database: app
require-protected: truePreview the migration first
With preview-sql, the action first runs the migration files this push adds on a copy of the database next to production, never on production. The run summary shows the verdict and what it found, such as a table rewrite that would block writes or a new table without row-level security.
| Verdict | What the action does |
|---|---|
| safe | Goes on. |
| careful, dangerous | Warns and goes on. With fail-on: dangerous (or careful), stops the job before the Mark. |
| failed | The migration fails on the copy, so it would fail on production too: the job stops before the Mark, with the SQL error in the summary. |
preview-sqltakes glob patterns:prisma/migrations/*/migration.sql,drizzle/*.sql,db/migrate/**/*.sql.- Only files added or changed since the previous push (or the pull request's base) are previewed, since migrations that already ran would fail on the copy. Check out with
fetch-depth: 0. If the action can't tell which files are new, it skips the preview and says so. - An older rowsafe CLI without
rowsafe previewskips the preview, says so, and still saves the Mark.
More in Preview a migration.
If the deploy goes wrong
Stop deploying. Click Rewind to this Mark in the run summary: it opens the database's Marks in the dashboard, where you rewind. Nothing is restored automatically. Options: Restore a database.
From a terminal, the summary's From the command line section has the commands: a copy of the database as it was at the Mark, next to production, and the rows that changed since.
rowsafe rewind copy app --mark before-deploy-3f2a1c9
rowsafe rewind compare appThe step's outputs, for later steps: mark, restore-from-backup, dashboard-url, database, protected and preview-verdict. Every input and output: GitHub Action reference.
GitLab CI
Store the key as a masked, protected CI/CD variable named ROWSAFE_API_KEY (Settings, CI/CD, Variables). Then, in the deploy job:
deploy:
stage: deploy
environment: production
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables:
ROWSAFE_VERSION: "0.10.15" # https://github.com/rowsafe/rowsafe/releases
before_script:
- curl -fsSLO "https://github.com/rowsafe/rowsafe/releases/download/v$ROWSAFE_VERSION/rowsafe-linux-amd64"
- curl -fsSLO "https://github.com/rowsafe/rowsafe/releases/download/v$ROWSAFE_VERSION/SHA256SUMS"
- sha256sum --check --ignore-missing SHA256SUMS
- install -m 0755 rowsafe-linux-amd64 /usr/local/bin/rowsafe
script:
- rowsafe status app # fails the job (exit 3) when app can't be restored right now
- rowsafe mark app "before-deploy-$CI_COMMIT_SHORT_SHA"
- npx prisma migrate deployTo only warn instead, write rowsafe status app || true.
Bitbucket Pipelines
Add ROWSAFE_API_KEY as a secured repository or deployment variable, then:
pipelines:
branches:
main:
- step:
name: Deploy
deployment: production
script:
- export ROWSAFE_VERSION=0.10.15
- curl -fsSLO "https://github.com/rowsafe/rowsafe/releases/download/v$ROWSAFE_VERSION/rowsafe-linux-amd64"
- curl -fsSLO "https://github.com/rowsafe/rowsafe/releases/download/v$ROWSAFE_VERSION/SHA256SUMS"
- sha256sum --check --ignore-missing SHA256SUMS
- install -m 0755 rowsafe-linux-amd64 /usr/local/bin/rowsafe
- rowsafe status app
- rowsafe mark app "before-deploy-$(echo "$BITBUCKET_COMMIT" | cut -c1-7)"
- npx prisma migrate deployAny other CI
Install the CLI (checked against the release's SHA256SUMS, or its build provenance), set ROWSAFE_API_KEY, and run before the migration:
rowsafe status app # exit 0: can be restored; 3: can't, with the reasons
rowsafe mark app before-deploy-42 # waits until the Mark is in your bucket; exit 1 if it isn'tFor scripts, add --json to rowsafe mark to get the Mark as JSON, with status and restore_from_backup.
Good to know
- A Mark is a moment, not an undo button. Rewinding the whole database also removes what your app wrote after the deploy. To avoid that, restore a copy and bring back only the rows you need.
- Re-runs get a new Mark. Names are unique per database: re-running the same commit saves
before-deploy-<commit>-2, then-3. Alabelyou set yourself must be new each time. - Pull requests from forks don't get secrets. Run the step on pushes to your deploy branch.
- A Rowsafe outage blocks the deploy by default, because the step fails without a Mark. To deploy anyway, add
continue-on-error: trueto the step. - Rowsafe never connects to your database from CI. The Rowsafe agent on your server writes the Mark and runs the preview on a copy there. The workflow only needs the API key.