Configuration blocks
Project configuration lives in your .sql files alongside the schema, in
SQL-statement-shaped blocks — à la Terraform’s terraform / provider blocks, but written
in SQL. They describe where your schema lives (the database and state store) and
project-level policy; the schema itself is not configured — it’s every *.sql file under the
project directory.
nschema init puts these in a dedicated config.sql, but they can live in any .sql file.
The three blocks
Section titled “The three blocks”-- which database to connect to (the connection string is best supplied via the environment)PROVIDER postgres ( connection_string = '', command_timeout = 30);
-- where to keep stateBACKEND file ( path = './nschema.state.json');
-- optional project settingsNSCHEMA ( destructive_action = 'error');| Block | Purpose |
|---|---|
PROVIDER <label> | The live database. postgres is the only label today. See the PostgreSQL provider. |
BACKEND <label> | The state backend. file or s3. See Backends. |
NSCHEMA | Project-level settings (no label). |
The BACKEND block may instead select S3:
BACKEND s3 ( bucket = 'my-bucket', key = 'env/state.json');Precedence
Section titled “Precedence”Settings resolve from three layers, in increasing order of precedence:
- Config blocks (above) — the base values.
- Environment variables —
NSCHEMA_*. - Command-line options — the per-run flags.
An unspecified flag never clobbers a configured value; a flag is only applied when it (or its environment variable) is actually set.
What belongs in a block — and what doesn’t
Section titled “What belongs in a block — and what doesn’t”Config blocks are static: they’re read in a lightweight bootstrap pass before the engine
is configured, so they cannot reference variables or computed values (the same reason
Terraform forbids interpolation in its backend block).
Typos surface as errors: an unknown block type, label, or attribute is rejected rather than silently ignored.
Environments
Section titled “Environments”A project can carry environment overlays: files named *.env.<name>.sql that are layered
over the base configuration only when you select that environment with
--environment <name> (or NSCHEMA_ENVIRONMENT).
- The base configuration is every
*.sqlfile except environment overlays. - When
--environment prodis set, every*.env.prod.sqlfile is layered on top.
This lets you keep environment-specific backends, scopes, or schema tweaks beside the base project without them taking effect until the environment is chosen:
nschema plan --environment prod # base + *.env.prod.sqlnschema plan --environment staging # base + *.env.staging.sqlnschema plan # base onlySee also
Section titled “See also”- Environment variables — the full list of
NSCHEMA_*overrides. - PostgreSQL provider — every
PROVIDER postgresattribute. - Backends — the state backend, with a page per backend (
BACKEND file/BACKEND s3).