The plan / apply workflow
The core of working with NSchema is a short loop, the same shape as Terraform’s:
- Edit your desired schema — the
*.sqlfiles under your project. - Plan —
nschema planshows exactly what would change, without touching the database. - Apply —
nschema applyshows the plan again, asks for confirmation, then executes it.
# edit schemas/*.sql ...nschema plannschema applyBecause the plan is always computed and shown before anything runs — even apply recomputes
and displays it first — you never apply blind.
Scoping a run
Section titled “Scoping a run”Limit a run to specific database schemas (namespaces) with --scope, repeatable. Useful for
deploying parts of a system independently:
nschema plan --scope appnschema apply --scope app --scope billingDeclarations and drops for schemas outside the scope are ignored, so unmanaged schemas are never touched.
Saved plans: review now, apply later
Section titled “Saved plans: review now, apply later”Save the computed plan to a file and apply that exact file later, so what was reviewed is exactly what runs. This is the pattern for separating planning from applying — for example, plan in a pull request and apply after approval:
nschema plan --out tonight.nplan # compute and save# ... review tonight.nplan, get approval ...nschema apply --plan-file tonight.nplan # apply exactly that, no re-planThe saved plan fixes its own scope, desired schema, and destructive-action policy, so those
inputs are ignored on apply — and the *.sql files needn’t even be present. A live database
to write to is still required.
Previewing changes in CI without a database
Section titled “Previewing changes in CI without a database”If you’ve configured a state store, plan can run offline against the
last recorded snapshot — no database connection needed. Combine that with
--detailed-exitcode to gate CI on whether a change would occur:
nschema plan --detailed-exitcode # exit 2 if the schema would change, 0 if notSee Running in CI for the full pipeline pattern.
Tearing down
Section titled “Tearing down”To preview or execute a teardown of the managed schema, see
plan --destroy and
destroy.