Skip to content

noorm run ​

Execute SQL files against the active database, or render a template without touching it.

bash
noorm run build
noorm run build
• log  Build completed  status=success filesRun=3 filesSkipped=0 filesFailed=0 durationMs=13.153750000000002

• log  /work/shop/db/sql/01_tables/01_party.sql (skipped: unchanged)
• log  /work/shop/db/sql/01_tables/02_sales_order.sql (skipped: unchanged)
• log  /work/shop/db/sql/02_views/01_open_orders.sql (skipped: unchanged)
• log  Build completed  status=success filesRun=0 filesSkipped=3 filesFailed=0 durationMs=3.4714580000000126

The first run executes all three files. The second skips them, because their checksums match a prior success. Log lines go to stderr. With --json, the result is one JSON object on stdout.

Which command runs what? ​

CommandRunsNeeds the database
noorm run buildEvery file under paths.sql, narrowed by build.include and build.excludeYes
noorm run file <path>One fileYes
noorm run dir <path>Every .sql and .sql.tmpl file under a directory, recursively, sortedYes
noorm run files --paths a.sql,b.sqlThe listed files, in the order givenYes
noorm run exec <dir-or-glob>A directory (as dir) or the .sql and .sql.tmpl files a glob matches, sortedYes
noorm run inspect <path>Nothing. Lists what a .sql.tmpl can readOnly to read vault secrets
noorm run preview <path>Nothing. Prints the rendered SQLOnly to read vault secrets

Each file takes one of these paths, and the first failure stops the batch:

Files after the failed one do not run and do not appear in the result.

Flags ​

FlagCommandsEffect
--config <name>, -c <name>all sevenUse a stored config instead of the active one
--force, -fthe five executing commandsRun even when the checksum matches a prior success
--dry-runthe five executing commandsRender templates into tmp/ and write nothing to the database
--jsonall sevenPrint the result as JSON on stdout

inspect and preview never execute, so they have no --force or --dry-run.

WARNING

A dry run writes every rendered file with its secrets resolved, in plaintext, to tmp/. noorm creates the files owner-only (0600) but does not add tmp/ to .gitignore. A template at db/sql/09_seeds/01_products.sql.tmpl renders to tmp/db/sql/09_seeds/01_products.sql.

What does each command do at the edges? ​

CommandConditionBehavior
buildA build.include entry matches no fileWarns Ignored N build.include entries that matched no files. Paths are relative to paths.sql: 01_tables, not sql/01_tables
buildA build.exclude entry matches no fileWarns that nothing was excluded, so those files ran
build--dry-runHeader reads Build (dry-run) completed; each file line ends -> <path in tmp/>; --json adds "dryRun": true
fileFile does not existerror: Failed to read file: <path>, exit 1
dirDirectory does not existError: Directory not found: <path>, exit 2
dirNo SQL files insideError: No SQL files found in: <path>, exit 2
files--paths omittedUsage text and Missing required argument: --paths, exit 1
files--paths "" or only commasError: --paths must contain at least one file path, exit 1
execGlob or directory matches nothingError: No SQL files found matching: <input>, exit 2
inspect, previewTemplate does not existError: Template not found: <path>, exit 2
inspect, previewThe database is unreachableVault secrets are skipped, local secrets still render, and the output says Vault-backed secrets were not resolved (no reachable database) — showing local-only secrets.; --json adds vaultProbeFailed: true and notice
inspect, previewThe role lacks run:file on the configPolicy message, exit 1
any executing commandRole lacks the permission, such as the default viewer agent roleCannot run.build on config "dev": "run:build" is not allowed on config "dev" (role: viewer)., exit 1
MSSQL filesGO alone on a lineSplit into batches. A failure is prefixed [batch N of M]. See execution

What do inspect and preview show? ​

inspect lists the variables a template can read. preview prints the SQL the template renders to, on stdout, so it pipes to a file.

bash
noorm run inspect db/sql/09_seeds/01_products.sql.tmpl
Template: db/sql/09_seeds/01_products.sql.tmpl
Config:   dev

Data Files:
  $.products  Array [1]

Built-ins: include, escape, quote, json, now, uuid
Secrets: 0 resolved, 0 global
bash
noorm run preview db/sql/09_seeds/01_products.sql.tmpl > rendered.sql
sql
INSERT INTO product (sku, name, list_price)
VALUES ('HW-DONGLE', 'USB security key', 49);

inspect adds Helpers ($helpers): and Helper Errors: sections when the folder has a $helpers file. preview prints resolved secrets, and both commands execute the template's helper scripts, so both check the run:file permission first. --json gives { filepath, context, … } for inspect and { filepath, sql, durationMs } for preview.

What does the output look like? ​

A failed file prints its SQL error under its status line:

✗ log  /work/shop/db/sql/03_mixed/02_bad.sql (failed)
✗ log    error: [Err 1] no such table: invoice_line_missing
✗ log  Run directory partial  filesRun=1 filesSkipped=0 filesFailed=1

The summary line reads Build completed for build, Run directory <status> for dir, Run files <status> for files, and Run exec <status> for exec. --json prints the batch result, with success added:

json
{
  "success": false,
  "status": "partial",
  "files": [
    { "filepath": "/work/shop/db/sql/03_mixed/01_ok.sql", "checksum": "8ece28fd…", "status": "success", "durationMs": 1.36 },
    { "filepath": "/work/shop/db/sql/03_mixed/02_bad.sql", "checksum": "3dd15369…", "status": "failed", "error": "[Err 1] no such table: invoice_line_missing", "durationMs": 0.24 }
  ],
  "filesRun": 1,
  "filesSkipped": 0,
  "filesFailed": 1,
  "durationMs": 7.4,
  "changeId": 1
}
FieldAppears when
files[].skipReasonA file was skipped: unchanged
files[].outputPathA dry run wrote the file
unmatchedInclude, unmatchedExcludebuild had patterns that matched nothing
errorThe batch failed before any file ran, or dir found no files
dryRun: truebuild --dry-run

run file --json returns one file result, with success added.

Exit codes ​

CodeMeaningRemedy
0Every file succeeded or was skippedNone
1Nothing succeeded: no connection, project not initialized, role denied, a missing required flag, file or files target missing, or every file that ran failedRead the error: line, fix the SQL or the connection, run again
2Nothing was attempted: dir or exec found no SQL files, or inspect or preview found no templateFix the path or glob
3Some files succeeded and some failedPart of the database changed. Check the failed file's effect, fix it, run again; files that succeeded skip

A re-run that fails again at the same file reports failed and exits 1, not 3: the earlier files skip, so nothing executed successfully in that run.

What bites ​

SymptomCauseFix
--force fails with table party already exists; 1 prior successful execution--force re-executes files that already ran, and CREATE TABLE is not guardedUse --force only on files that are safe to run twice; new schema reaches an existing database through a change
run build fails after you edit a table fileThe new checksum makes the file run again against a table that existsBuild only fresh databases. Existing ones catch up with noorm change ff
Seed files report skipped: unchanged after db truncateTruncate keeps noorm's tracking tables, so each file still has a successful recordRe-run the seed files with --force

Next ​