Lone Badger Tech

Revert (down)

Rolling back with the scripts the database stored at deploy time.

bsm revert --last 1               # the most recently deployed change
bsm revert --to create-customer    # everything deployed after it (it stays)
bsm revert --to @release-1.4
bsm revert --all
bsm revert --to x --dry-run        # list, change nothing
bsm rebase --to x                  # revert to x, then deploy to the head again
bsm revert --repeatable views/vCustomer.sql   # put a view back to its previous definition

Changes are reverted in reverse deploy order, each in its own transaction (unless !notx), with a revert event in the log. Revert asks for confirmation; pass --yes in scripts.

Stored scripts

When a change is deployed, its deploy, revert and verify scripts are saved in the journal. Revert runs the saved revert script. You can switch branches, delete the change, or roll back from a machine that never had the code, and the database still knows how to undo itself. If your working copy's revert script differs from the saved one, bsm says so and uses the saved one.

Guards

  • !irreversible changes stop the revert before anything runs.
  • Environments with allowRevert: false refuse revert and rebase. Use it for production and fix forward.
  • If a variable used by the revert script changed since deploy, revert refuses (it would undo something other than what was done). Check bsm vars; override with --allow-variable-drift.
  • Protected environments ask you to type the environment name.

A revert script with a bug can be fixed after deploy without breaking certification; see Fixing deployed changes. Repeatables are reverted one by one; see Repeatables.

Writing good revert scripts

  • Undo in reverse order of the deploy.
  • Drop what you created; restore what you changed. For data changes, keep enough information in the deploy (for example a backup table) to restore it.
  • Test the pair: bsm rebase --to <previous change> on a dev database runs revert and deploy back to back. bsm verify afterwards should match the original fingerprint.