Devstack Migration Snapshot & Rollback
Overview
For a contributor about to apply or review a migration on the devstack: cargo xtask migrate snapshot dumps every Canopy database into .devstack/snapshots/<timestamp>/ and cargo xtask migrate rollback restores from one (xtask/src/cmd/migrate.rs).
This is dev/CI tooling only. Migrations are forward-only (ADR-016); production rollback is pg_basebackup plus WAL point-in-time recovery — see Database Backup & Restore.
| Concern | Tool |
|---|---|
Production point-in-time recovery |
|
Local dev — snapshot before applying a new migration |
|
Local dev — undo a broken migration |
|
Deploy-time migration job (runtime runs with |
|
Down migrations |
None, by design (ADR-016). A wrong migration is fixed forward or, when data was destroyed, recovered with PITR — never a down file. |
When to use
-
About to merge a migration MR that touches a table you don’t own — snapshot first, run
cargo xtask dev refreshto apply, smoke-test, roll back if the migration breaks something unexpected. -
Reviewing a migration MR locally — snapshot, check out the branch, apply migrations via
cargo xtask dev refresh, then roll back to your clean state when done. -
Reproducing a determined-to-be-broken state in CI for a bug — capture a snapshot from an affected developer’s box, ship it as an attachment, restore on your own devstack with
cargo xtask migrate rollback --id <ts>.
Commands
| Command | Effect |
|---|---|
|
Runs |
|
Prints all available snapshots in chronological order with their size, entry count, and git HEAD SHA at snapshot time. |
|
Restores from the most recent snapshot. Each archive is piped into
|
|
Restore from a specific snapshot by id. |
|
Restore only the named database(s). Pass |
|
Not a snapshot command, and not an xtask verb: applies the migrations of |
Output paths
.devstack/snapshots/
20260430T174056Z/
manifest.json
canopy_appeals.dump
canopy_applications.dump
...
canopy_wic.dump
The .devstack/ directory is gitignored — snapshots live on the
developer’s machine only and never get checked in.
Manifest schema
{
"snapshot_id": "20260430T174056Z",
"git_sha": "ca0f836f44a773493a5fb6161f336724a612efdb",
"shared_db": false,
"entries": [
{
"database": "canopy_snap",
"container": "canopy-postgres-snap-1",
"archive": "20260430T174056Z/canopy_snap.dump",
"size_bytes": 371320
}
]
}
Limitations
-
Devstack only. Container names are derived from the compose project name (
<project>-postgres-*-1). Production databases live behind a different naming scheme (cloud-managed Postgres, host:port endpoints with TLS) —pg_basebackupis the right tool there. -
Logical dump, not physical. Restored databases get the same data but may differ in toast/WAL state. Fine for dev; not equivalent to a physical replica.
-
No incremental snapshots. Each snapshot is a full dump of every database.
-
Per-database rollback uses the
--dbflag; no need to drop into rawpg_restorefor the common case.
Implementation notes
Source: xtask/src/cmd/migrate.rs. Container naming: container_for_db
in xtask/src/docker.rs. Migration authoring rules and recovery paths:
Migrations.