4. Seeds, analyses and snapshots¶
Next steps ยท Previous: 3. Unit tests and CI

Run the commands from oms_dbt_proj, after a first dbt build --profiles-dir ..
seeds/payment_methods.csvis small reference data that lives in git and loads withdbt seed.analyses/revenue_by_payment_method.sqljoins it to payments. Analyses compile but never build.snapshots/snap_customers.ymlkeeps Type 2 history of raw customers.
dbt compile --profiles-dir . -s revenue_by_payment_method
dbt snapshot --profiles-dir .
python -c "import duckdb; duckdb.connect('../duckdb/raw.duckdb').execute(\"update jaffle_shop.customers set last_name = 'Q.' where id = 1\")"
dbt snapshot --profiles-dir .
dbt show --profiles-dir . --inline "select id, last_name, dbt_valid_from, dbt_valid_to from {{ ref('snap_customers') }} where id = 1"
Check: customer 1 has two rows. The P. row has a dbt_valid_to, and the Q. row has none. Run python duckdb/load_raw.py from the repo root to reset the raw data.
- Seeds suit small data that rarely changes, such as country codes or payment method labels. Load data that changes often with an EL tool instead.
- Analyses suit one-off queries and audits: they get Jinja and
ref(), and compile to plain SQL intarget/compiled/.
Try it¶
Snapshot raw orders, tracking changes to status only, then change an order's status and snapshot again.
Hint
Copy snapshots/snap_customers.yml, point it at the orders source, and use check_cols to watch only status. The update command in the chapter shows how to change raw data.
Answer
Create snapshots/snap_orders.yml:
snapshots:
- name: snap_orders
relation: source('jaffle_shop', 'orders')
config:
unique_key: id
strategy: check
check_cols: ['status']
dbt snapshot --profiles-dir . -s snap_orders
python -c "import duckdb; duckdb.connect('../duckdb/raw.duckdb').execute(\"update jaffle_shop.orders set status = 'completed' where id = 1\")"
dbt snapshot --profiles-dir . -s snap_orders
dbt show --profiles-dir . --inline "select id, status, dbt_valid_from, dbt_valid_to from {{ ref('snap_orders') }} where id = 1"
Order 1 has a closed returned row and a current completed row. Run python duckdb/load_raw.py from the repo root to reset the raw data.