First, you'll download Dagster's tutorial_dbt_dagster example and configure the dbt project it contains. This example uses dbt's jaffle shop project, but you can follow along with a different project as well.
We assume you use DuckDB as your data warehouse in order to run the tutorial entirely locally. If you plan on using a different data warehouse in production, that's totally fine: Dagster can orchestrate dbt regardless of what profile is configured. For example, we support dbt profiles for BigQuery, Redshift, Snowflake, and more.
In this step, you'll add a profile to the dbt project. Profiles in dbt allow you to connect dbt to a database - in this case, that's DuckDB.
Open the profiles.yml file, located in /tutorial_template/jaffle_shop/config.
Add the following code to the file:
# /tutorial_template/jaffle_shop/config/profiles.ymljaffle_shop:target: local
outputs:local:type: duckdb
path: tutorial.duckdb
schema: jaffle_shop
Next, you'll tell the dbt models where their source data will be located. There isn't any data yet - we'll create Dagster assets that fetch and provide data to the dbt models later in the tutorial.
In dbt, sources are declared using sources.yml files. We've provided this file for you in /tutorial_template/jaffle_shop/models, which defines the location of tables containing source data:
The Dagster assets you build in part three of this tutorial will create orders_raw and customers_raw tables when materialized. To have the models select data from these tables, you'll need to update the models.
In /tutorial_template/jaffle_shop/models/staging, update the stg_customers.sql and stg_orders.sql models to use the {{ source()}} function. This function tells the dbt model to select data from the defined source. In this example, that's the customers_raw and orders_raw tables in the DuckDB database:.
In stg_customers.sql, replace its contents with the following:
# /tutorial_template/jaffle_shop/models/staging/stg_customers.sqlselect
id as customer_id,
first_name,
last_name
from {{ source('jaffle_shop','customers_raw') }}
In stg_orders.sql, replace its contents with the following:
# /tutorial_template/jaffle_shop/models/staging/stg_orders.sqlselect
id as order_id,
user_id as customer_id,
order_date,statusfrom {{ source('jaffle_shop','orders_raw') }}