Revert (down)
Rolling back with the scripts the database stored at deploy time.
trek revert --last 1 # the most recently deployed change
trek revert --to create-customer # everything deployed after it (it stays)
trek revert --to @release-1.4
trek revert --all
trek revert --to x --dry-run # list, change nothing
trek rebase --to x # revert to x, then deploy to the head again
trek 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, trek says so and uses the saved one.
Guards
!irreversiblechanges stop the revert before anything runs.- Environments with
allowRevert: falserefuse 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
trek 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:
trek rebase --to <previous change>on a dev database runs revert and deploy back to back.trek verifyafterwards should match the original fingerprint.