Dbt Deployment: Commands and CI/CD
Contents
Goal: master the dbt Command Line Interface (CLI) and implement efficient CI/CD pipelines.
1. The Essential Commands
While there are many commands, you will spend 90% of your time with these four.
dbt compile
Compiles your code into raw SQL in the target/ folder.
- Use when: Debugging complex Jinja logic without waiting for execution.
dbt run
Runs your models.
- Use when: You are actively developing and need to materialize tables.
dbt test
Runs your tests.
- Use when: You want to validate data quality without rebuilding tables.
dbt build ⭐️
The gold standard. It runs seeds, snapshots, models, and tests in dependency order.
- Why it’s better: If an upstream model fails, dbt build skips downstream models to save time and compute.
- Use when: Always, especially in CI/CD.
2. Surgical Precision: Node Selection
Don’t run the whole project every time. Use --select (or -s).
Basic Selection
|
|
Graph Operators (+)
The real power comes from selecting dependencies.
+my_model: Run model and everything upstream.my_model+: Run model and everything downstream.+my_model+: Run model and all related lineage.
Scenario: You changed a staging model. You want to test the impact downstream.
|
|
3. Advanced CI/CD: “Slim CI”
In a large project, running everything on every Pull Request is too slow and expensive. Enter Slim CI.
The Logic
- State: dbt compares your current code against a “manifest” (artifact) from a previous run (usually Production).
- Modified: It identifies which models have changed.
- Run: It runs only the modified models and their downstream dependencies.
The Command
|
|
state:modified: The changed models.+: Their downstream children (to ensure you haven’t broken anything).--state: Path to themanifest.jsonfrom production.
4. Deployment Environments
Always separate Dev from Prod.
- Dev: Local schema (e.g.,
dbt_alice). Sandbox for experimentation. - Prod: Production schema (e.g.,
analytics). Read-only for humans, writable only by the Orchestrator.
Command:
|
|
This concludes our series on Analytics Engineering with dbt. Happy modeling!