DT7: dbt: transformations as tested code

Lesson 5 of 5 · reading 15–25 minutes; practice and project time is on the module page

dbt in a team

🎯You'll be able to

Use separate development and production environments, run dbt in CI on every pull request, check source freshness, and review changes to models safely.

🏠The everyday picture

A newspaper's reporters write drafts in their own files; editors check them; only approved pages go to print. Nobody edits the printed paper directly.

📘What it really is

yaml loaded_at_field: loaded_at freshness: warn_after: {count: 30, period: hour} error_after: {count: 54, period: hour} Run it in the scheduled job (DT3 Lesson 4) so stale data alerts someone.

📝A worked example

Input: in the solution, after loading the data, run dbt source freshness --profiles-dir ..

Expected output: PASS freshness of clean.order_lines, because loaded_at is from the load you just ran. If the pipeline stopped for more than 30 hours, the same command would warn, and after 54 hours it would fail. Project 2 test 8 checks the freshness settings and runs this command.

🌍Where it's used

📝Case scenario

An analyst at a quick-commerce company edited a production model directly to fix an urgent number. The fix broke two other marts, and nobody knew until morning. With development schemas and CI on pull requests, the breakage would have shown as a failed check before anything changed in production.

🖱️Try it

Write the sources.yml freshness settings you'd use for SabziSathi if files arrived every hour instead of once a day, and explain your choice. Success: your warning and error times fit the new arrival rate with some slack.

⚠️Common mistakes

🛠️For your project

Project 2 test 8 checks the freshness settings on order_lines; your refresh.yml from Project 1 runs freshness after dbt build.

✅Quick check

What does CI on a dbt project do?

Show the answer

Builds and tests the changed models (and what depends on them) before a change is merged.

What does dbt source freshness compare?

Show the answer

The newest loaded_at time with the warning and error limits.

← PreviousMaterialisations: view, table, incremental
ProLearners Assist