Project
dbt init <project>
Scaffold a project and profile
dbt debug
Check profile, project and connection
dbt deps
Install packages from packages.yml
Run again after changing packages.yml; writes
package-lock.yml.
dbt deps --add-package <pkg>@<ver>
Add a package and install it
dbt parse
Parse the project, write the manifest
dbt clean
Delete target/ and dbt_packages/
Removes the folders listed in clean-targets.
Jinja in models
{{ ref('<model>') }}
Reference another model or seed
{{ source('<src>', '<table>')
}}
Reference a raw table declared as a source
{{ config(materialized='table') }}
Set config at the top of a model
view (default), table, incremental, ephemeral.
{{ var('<name>', '<default>')
}}
Read a project variable
{{ this }}
The model's own relation
{% if is_incremental() %}
Filter only on incremental runs
{{ env_var('<VAR>') }}
Read an environment variable
{{ target.name }}
Current target, e.g. dev or prod
Run and build
dbt build
Seed, run, snapshot and test in DAG order
A failing test skips the models downstream of it.
dbt test
Run data and unit tests
dbt seed
Load seeds/*.csv into tables
dbt snapshot
Record changes in snapshot tables
dbt source freshness
Check sources against freshness rules
dbt compile -s <model>
Print the rendered SQL of a model
Compiled SQL also lands in target/compiled/.
dbt show -s <model> --limit <n>
Preview a model's rows
dbt show --inline "<sql>"
Run an ad-hoc query with Jinja
dbt ls -s <selector>
List what a selection matches
Dry-run any --select before running it.
dbt run-operation <macro> --args
'<yaml>'
Call a macro
dbt retry
Rerun only what failed last time
dbt docs generate
Build catalog and docs site
dbt docs serve --port <port>
Serve the docs locally
Selection
dbt run -s <model>
Select one model (--select)
dbt run -s <model>+
Model and everything downstream
dbt run -s +<model>
Model and everything upstream
dbt run -s +<model>+
Upstream, model and downstream
dbt run -s 1+<model>
Model and direct parents only
dbt run -s "<a> <b>"
Union: either selection
dbt run -s "tag:<t>,path:<dir>"
Intersection: both match
dbt run --exclude <model>
Leave nodes out
dbt run -s tag:<tag>
By tag
dbt run -s path:models/<dir>
By folder
dbt build -s source:<src>+
Everything fed by a source
dbt test -s test_type:unit
Only unit tests
dbt build --resource-type model
Only one resource type
State and CI
dbt build -s state:modified+ --state <dir>
Build changed nodes and children
dbt build -s result:error+ --state <dir>
Rebuild failures and their children
dbt run -s <model> --defer --state <dir>
Read unbuilt parents from prod
Unselected refs resolve to the relations in the state
manifest.
dbt clone -s <sel> --state <dir>
Clone prod relations into dev