The Note in the Toastie Iron
The story
It's the first week of December, 6am, and the Jaffle Shop in Philadelphia is cold and dark. Jairko, who runs the data side of the shop, has come in early to fix the oldest toastie iron on the wall. It's been there since the day the shop opened, and it won't heat.
Wedged behind the hinge he finds a note from the shop's founder, the Old Toastmaster, whom nobody has seen in twenty years:
The Golden Jaffle is not in a cookbook. It lives in the data. I tore the recipe card in two and gave each half to an apprentice. Build the project, follow the crumbs, and it will toast.
The note ends with the name of a dbt project that nobody ever built. It's on the shop's old laptop, next to six months of the Philly store's orders from last season, and its dbt_project.yml has a toast stain on it. Jairko's hands are covered in butter, so you take the keyboard.
How Advent of dbt works
Each day has two parts, and each part ends with a crumb: a number or a short word you find by running dbt. Type it into the answer box to check it. A new day opens every weekday at 8am CET. The Start here page has the rest: what you need, how to catch up, and how to reset.
A quick tour of the project
Skip this if you already use dbt.
- Project: a folder with a
dbt_project.ymlat its root. dbt reads everything under it. - Seed: a CSV file in
seeds/. dbt loads it into the database as a table. The shop's orders and the Old Toastmaster's notes are seeds. - Model: a
.sqlfile inmodels/holding oneselect. dbt builds it as a table or a view.{{ ref('other_model') }}points at another model or a seed, which is how dbt knows what to build first. - DuckDB: the database. It's a single file on your laptop, so there's nothing to install or sign up for.
dbt build: loads the seeds, builds the models in the right order and runs the tests, in one command.
Get today's starter
git clone https://github.com/dbt-labs/advent-of-dbt advent-of-dbt
cd advent-of-dbt
git checkout -f day-01-start
No git? Download day-01-start.zip. You need dbt 2.0.13 or later (dbt --version).
Open the advent-of-dbt folder in an editor such as VS Code, with its terminal at the bottom, and run every command there: you'll see the files dbt creates or rewrites as it happens. Install the official dbt extension too (publisher dbt Labs LLC), for VS Code, Cursor or Windsurf.
Part 1: The first toast
Before Jairko trusts anything the Old Toastmaster left behind, he wants to see the project work once. Install its packages, then build the whole thing with dbt build:
dbt deps
dbt build
Everything should come out green: the seeds load, the models build and the tests pass. The Toastmaster's note says to count the orders before you trust anything else, so:
How many rows does the orders model have?
Hint
dbt show --inline "<your SQL>" runs a query against your project and prints the result. In the SQL, write {{ ref('orders') }} wherever you'd write a table name.
Crumb 1: a number.
Part 2 appears once you have found crumb 1.
Part 2: The misspelled crumb
There is one more thing in the iron's drawer: founder/crumb_report.sql, the Old Toastmaster's own model. It reports on his recipe notes, which are the toastmaster_notes seed: five steps, each with a number of golden crumbs. Copy the model into the project:
cp founder/crumb_report.sql models/marts/crumb_report.sql
(cp works in macOS and Linux terminals and in Windows PowerShell. You can also drag the file into models/marts/ in your editor.)
The notes are spelled correctly, since they were copied from the card. The Toastmaster's SQL was written in a hurry, and it doesn't build. If you ran dbt build now, you'd only find out after dbt had started sending SQL to the database. On a big project that can be many minutes in.
dbt v2 can check your SQL before it runs anything. This is static analysis: dbt compares every column a model asks for with the columns it knows exist. By default it's relaxed about this. Switch it to strict and it checks everything, and the error names the exact spot in the file.
Run a compile with strict static analysis. Which line of models/marts/crumb_report.sql does the error point at?
Hint
The flag is --static-analysis strict. dbt compile is the quickest command to try it on, because it checks everything without building anything.
Crumb 2: a number, the line the error points at.
Then fix the model. The seed is right, so leave it alone. Check the whole project builds with dbt build --static-analysis strict.
What you just did
You built a whole dbt project with one command. dbt build loads the seeds, builds the models in the right order and runs the tests. Then you caught a mistake without running a single query. That was static analysis: dbt v2 reads your SQL and checks it against the columns it knows about. The default checks the basics. Strict mode checks every column and type, which is why it found the typo.
The flag applies to one command. To make strict mode the default for the whole project, set it in dbt_project.yml, for the models and for the seeds they read from:
seeds:
jaffle_shop:
+static_analysis: strict
models:
jaffle_shop:
+static_analysis: strict
Then a plain dbt build catches the typo too, with no flag. The seeds need it as well because a model can't be stricter than the things it reads from. The config stays in the project, so it persists for you and for anyone who clones it.
Go further
- Put the config above in your
dbt_project.yml, drop the flag, and check that a plaindbt buildstill catches the typo. - Break something else on purpose, such as a misspelled
ref('orders')or a column that doesn't exist inorders. Compare whatdbt compilesays with and without--static-analysis strict. - Read About static analysis and the
--static-analysisflag.