0
0
dbtdata~20 mins

Environment management (dev, staging, prod) in dbt - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Environment Mastery in dbt
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Purpose of Different Environments in dbt

Why do data teams use separate environments like dev, staging, and prod in dbt projects?

ATo allow multiple users to edit the same model simultaneously without conflicts
BTo run the same models multiple times for faster results
CTo isolate development work, test changes safely, and deploy stable models to production
DTo store different versions of data in separate databases permanently
Attempts:
2 left
💡 Hint

Think about how changes are tested before affecting real data.

Predict Output
intermediate
1:30remaining
dbt Profile Target Output

Given this profiles.yml snippet, what is the active target when running dbt run --target staging?

my_project:
  target: dev
  outputs:
    dev:
      type: snowflake
      database: dev_db
    staging:
      type: snowflake
      database: staging_db
    prod:
      type: snowflake
      database: prod_db
AThe database used will be <code>staging_db</code>
BThe database used will be <code>dev_db</code>
CThe database used will be <code>prod_db</code>
Ddbt will raise an error because <code>target</code> is set to <code>dev</code> in the profile
Attempts:
2 left
💡 Hint

The --target flag overrides the default target in the profile.

data_output
advanced
2:00remaining
Effect of Environment Variable in dbt Model

Consider this dbt model SQL snippet that uses an environment variable to filter data:

select * from raw.sales
where region = '{{ env_var('REGION', 'all') }}'

If you run dbt run with REGION set to north, what will be the output?

AAll rows because default <code>all</code> is used
BRows where <code>region</code> equals <code>north</code>
CNo rows because <code>region</code> is filtered by a missing variable
DSyntax error due to incorrect use of <code>env_var</code>
Attempts:
2 left
💡 Hint

Check how env_var uses the environment variable if set.

🔧 Debug
advanced
2:00remaining
Debugging Environment-Specific Model Failures

A model runs fine in dev but fails in prod with a missing table error. What is the most likely cause?

AThe <code>prod</code> environment has incorrect Python dependencies
BThe model SQL syntax is invalid only in <code>prod</code>
CThe <code>dev</code> environment has a different dbt version causing the error
DThe <code>prod</code> environment is missing a required source table or schema
Attempts:
2 left
💡 Hint

Think about differences in data availability between environments.

🚀 Application
expert
2:30remaining
Configuring dbt for Multiple Environments

You want to configure dbt to use different schemas for dev, staging, and prod environments automatically. Which dbt_project.yml snippet correctly sets the schema based on the active target?

A
models:
  my_project:
    +schema: '{{ target.name }}_schema'
B
models:
  my_project:
    +schema: '{{ target.schema }}'
C
models:
  my_project:
    +schema: 'prod_schema' if target.name == 'prod' else 'dev_schema'
D
models:
  my_project:
    +schema: 'schema_{{ env_var('DB_ENV') }}'
Attempts:
2 left
💡 Hint

Use the target variable to dynamically set schema names.