RECIPE

dbt Primer

A pragmatic walkthrough of dbt (data build tool) for analytics engineers shipping production warehouses on Meridian. We cover models, sources, tests, and a minimal project skeleton you can run against any Postgres-compatible target in under five minutes.

01.Models and the SELECT-only contract

A dbt model is a single SELECT statement saved as a .sql file inside the models/ directory. dbt wraps the query in either a CREATE TABLE AS or CREATE VIEW AS depending on the materialization you choose. Never write DDL by hand — let dbt handle the lifecycle.

02.Sources, refs, and the DAG

Declare raw tables in sources.yml and reference them with {{ source() }}. Reference other models with {{ ref() }}. dbt builds the dependency graph at compile time and runs models in topological order.

03.Tests, docs, and CI

Attach generic tests (unique, not_null, accepted_values, relationships) to columns in your schema YAML. Run dbt build in CI to compile, run, and test the whole project in one command.

Minimal project skeleton

-- models/staging/stg_orders.sql
with source as (
  select * from {{ source('raw', 'orders') }}
)
select
  id          as order_id,
  customer_id,
  amount_cents / 100.0 as amount_usd,
  status,
  created_at
from source
where status != 'cancelled'

-- models/marts/fct_orders.sql
select
  order_id,
  customer_id,
  amount_usd,
  date_trunc('day', created_at) as order_date
from {{ ref('stg_orders') }}