Detecting drift
Drift is when the live database no longer matches NSchema’s latest snapshot in the state store. This happens when people
make manual schema changes outside of NSchema, and it can cause data loss if not handled carefully. The nschema drift
command helps detect it.
How it works
Section titled “How it works”drift compares the latest backend state snapshot against the live database and outputs the difference. The diff
answers “what has been changed outside of NSchema?”:
- an out-of-band addition appears as an add;
- a manual drop appears as a remove.
nschema driftGating a monitor on drift
Section titled “Gating a monitor on drift”For a scheduled monitoring job, add --detailed-exitcode so the command’s exit code becomes 0 for no drift, 2 for drift (errors stay 1):
nschema drift --detailed-exitcodeReconciling drift
Section titled “Reconciling drift”Once you’ve reviewed the drift, you can choose to either adopt the drift using refresh, then
updating your .sql files to match, or you can revert the drift using apply to bring the
database back in line with your declared desired state.