Learn how to develop your favorite dbt models in Mage.
Set up new Mage project
demo_project
.Set up dbt project
init
command (for this tutorial, we’ll
use the dbt project name demo
):Create standard pipeline
+ New pipeline
and select the option labeled Standard (batch)
.Pipeline settings
icon in the left pane, and change its name
to dbt demo pipeline
, then click the Save pipeline settings
button.Create dbt profile for database connections
demo_project/dbt/demo/
.profiles.yml
.profiles.yml
file by pressing Command (⌘)
+ S
.X
button on the right side of the file
name dbt/demo/profiles.yml
.Add data loader block to pipeline
+ Data loader
button, select Python
, then click API
.
Data loader block name
, change its name to load data
,
then click the Save and add block
button.
Add dbt model block to pipeline
dbt model
,
then click the option Single model
.
my_second_dbt_model.sql
under the folders demo/models/example/
.
my_first_dbt_model
and the 2nd for the dbt model named my_second_dbt_model
.
my_first_dbt_model
was added to
the pipeline because my_second_dbt_model
references it.
Edit my_first_dbt_model
my_first_dbt_model
, next to the label
Target
at the top, choose dev
in the dropdown list. You can also
check Manually enter target
, and enter dev
in the input field.my_first_dbt_model
:Command
+ Enter
.Expand table
link at the bottom right corner.dbt run
command and create the table in your data source.Edit my_second_dbt_model
my_second_dbt_model
, next to the label
Target
at the top, choose dev
in the dropdown list. You can also
check Manually enter target
, and enter dev
in the input field.
my_second_dbt_model
:
dbt sources
When a dbt model depends on an upstream block that isn’t a dbt model, a
source for that block is automatically added to the
demo_project/dbt/demo/models/mage_sources.yml
file.
Read more about dbt sources in their
documentation.
Command
+ Enter
.
Expand table
link at the bottom right corner.
Add test for dbt model
Terminal
.demo_project/dbt/demo/tests/
and click the file named
test_my_second_dbt_model.sql
. If you don’t see it, refresh the page.Execute pipeline end-to-end
Schedule
and a Frequency once
.
For more details, follow these
steps.
Start trigger
button at the
top of the page.
demo_project/dbt/demo/models/example/schema.yml
and remove
the tests named unique
under both models. Your file should look like this:
Failed
button next to the pipeline run and click
Retry run
. It should complete running successfully after a few
minutes.