Skip to content

Execution ​

Run your SQL files against a database and re-run only the ones whose SQL changed.

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

Run it again and every file is skipped:

bash
noorm run build
• log  /srv/shop/db/sql/01_tables/01_party.sql (skipped: unchanged)
• log  /srv/shop/db/sql/01_tables/02_sales_order.sql (skipped: unchanged)
• log  /srv/shop/db/sql/01_tables/03_product.sql (skipped: unchanged)
• log  /srv/shop/db/sql/02_views/01_open_orders.sql (skipped: unchanged)
• log  /srv/shop/db/sql/09_seeds/01_products.sql.tmpl (skipped: unchanged)
• log  Build completed  status=success filesRun=0 filesSkipped=5 filesFailed=0 durationMs=8.991874999999993

Each line also starts with a [YY-MM-DD HH:mm:ss] timestamp, left out here.

Which command runs what? ​

CommandRunsApplies build.include, build.exclude, rules
noorm run buildevery file under paths.sqlyes
noorm run file <path>one fileno
noorm run dir <path>every file under a directoryno
noorm run exec <dir-or-glob>a directory, or the files a glob matchesno
noorm run files --paths a.sql,b.sqlthe listed files, in the order listedno
noorm run preview <file>nothing: prints a template's rendered SQLn/a
noorm run inspect <file>nothing: lists what a template can read from $n/a

Directories and globs run in path order, the order Organization describes. The five commands that run SQL take these flags:

FlagEffect
--force, -fRun every file without the checksum test
--dry-runRender to tmp/. Run nothing and record nothing
--config, -cUse a config other than the active one
--jsonPrint the result as JSON on stdout

preview and inspect take --config and --json only. Exit codes and JSON shapes are in noorm run.

How does noorm decide to skip a file? ​

A file skips only when its newest record succeeded on the same SQL. Everything else runs:

The hash covers the SQL the database would receive. For a .sql.tmpl that is the rendered output, so a changed data file, config, or secret re-runs the template while its own bytes stay the same.

One lookup decides the whole batch before anything runs. A skipped file leaves no row, and a batch where every file skips creates no operation record. Records are per config and per file path, whichever command wrote them, so run file after run build skips an unchanged file.

What does --dry-run do? ​

It renders every file, templates included, and writes the result under tmp/, mirroring the source path and dropping .tmpl. Nothing runs and nothing is recorded. The skip test does not apply, so unchanged files render too:

bash
noorm run build --dry-run
• log  /srv/shop/db/sql/09_seeds/01_products.sql.tmpl (success, dry-run) -> /srv/shop/tmp/db/sql/09_seeds/01_products.sql
• log  Build (dry-run) completed  status=success filesRun=5 filesSkipped=0 filesFailed=0 durationMs=11.70675 dryRun=true

Dry-run files hold your secrets

Rendering resolves every secret a template reads and writes it to tmp/ in plain text. The files are owner-only (0600, in 0700 directories), but noorm init does not add tmp/ to .gitignore. Add it, and delete the output when you finish.

What gets tracked ​

Each batch that runs writes to two tables in your database. PostgreSQL and SQL Server keep them in a noorm schema, as noorm.change and noorm.executions. MySQL and SQLite name them __noorm_change__ and __noorm_executions__.

TableColumns
change (one row per batch)id, name, change_type, direction, checksum, executed_at, executed_by, config_name, cli_version, status, error_message, duration_ms
executions (one row per file)id, change_id, filepath, file_type, checksum, cli_version, status, error_message, skip_reason, duration_ms

change_type is build, run, or change. filepath is relative to the project root. Before the first file runs, every file in the run set gets a pending row, so an interrupted build still shows what it intended. The next build treats a pending row as never started.

What happens when a file fails? ​

The batch stops at the first failure. Files after it are not attempted:

FileRecorded asNext build
ran before the failuresuccessskipped
the one that failedfailedruns
after the failureskipped, with Skipped: failure in <file>runs

The command exits 3 when some files ran and 1 when none did.

How do I watch a slow file? ​

A file still running after 10 seconds logs Still running <file> (Ns) every 10 seconds. The entry carries the progress the database reports (an index build's phase and block count) and any session the file waits on for a lock, which tells a slow file from a stuck one. To cancel a run, use the TUI: Long-Running Files.

Multiple statements per file ​

DialectA file with several statements
PostgreSQLRuns as one call, in one implicit transaction
SQL ServerSplits on a line that holds only GO, then runs each batch in order
SQLiteSplits on statement boundaries. Semicolons inside strings, quoted identifiers, comments, and trigger bodies do not count
MySQLThe driver rejects it. Use one statement per file

SQL Server needs GO because CREATE VIEW, CREATE PROCEDURE, CREATE FUNCTION, CREATE TRIGGER, and CREATE TYPE must each be alone in their batch:

sql
-- db/sql/02_views/02_order_views.sql
CREATE OR ALTER VIEW open_orders AS
SELECT party_id, order_no FROM sales_order WHERE status = 'open';
GO

CREATE OR ALTER VIEW invoiced_orders AS
SELECT party_id, order_no FROM sales_order WHERE status = 'invoiced';
GO

When a batch fails, the error starts with [batch 2 of 2]. SQLite errors start with [statement N of M]. Files in db/changes/ split the same way. Splitter rules are in the runner internals.

What bites ​

Mistake or symptomCauseFix
A build skips files after you dropped tables by handThe records still say success and the checksums matchnoorm run build --force. To empty a database, use noorm db teardown, which marks the records stale
run build fails with already exists, and the error ends with 1 prior successful executionA CREATE TABLE file changed, so it ran again against a table that existsrun build is for new databases. Bring an existing one up to date with noorm change ff
A template runs on every buildIts SQL changes on every render: $.now(), $.uuid()Use a fixed value
The first build on a second config runs every fileRecords are per config nameNone needed. The config has not run them yet
Progress reports show only elapsed time, or describe another sessionconnection.pool.max: 1 leaves no second connection. A transaction-mode pooler (PgBouncer, RDS Proxy, Supabase port 6543) can route the report to another sessionRaise the pool max, and connect to the database directly for builds you want to watch
A line that is only GO inside a string or block comment splits the fileThe splitter reads lines, not SQLKeep GO out of strings and /* */ comments

Next ​