Skip to main content

Define configs

Learn how to define configurations for your resources in a dbt project

Depending on the resource type, you can define configurations in a dbt project and also in an installed package by:

Config inheritance

The most specific config always takes precedence. This generally follows the order above: an in-file config() block --> properties defined in a .yml file --> config defined in the project file.

Note - Generic data tests work a little differently when it comes to specificity. See test configs.

Within the project file, configurations are also applied hierarchically. The most specific config always takes precedence. In the project file, for example, configurations applied to a marketing subdirectory will take precedence over configurations applied to the entire jaffle_shop project. To apply a configuration to a model or directory of models, define the resource path as nested dictionary keys.

Configurations in your root dbt project have higher precedence than configurations in installed packages. This enables you to override the configurations of installed packages, providing more control over your dbt runs.

Combining configs

Most configurations are "clobbered" when applied hierarchically. Whenever a more specific value is available, it will completely replace the less specific value. Note that a few configs have different merge behavior:

  • tags are additive. If a model has some tags configured in dbt_project.yml, and more tags applied in its .sql file, the final set of tags will include all of them.
  • meta dictionaries are merged (a more specific key-value pair replaces a less specific value with the same key)
  • pre-hook and post-hook are also additive.

Example

Here's an example that defines both sources and models for a project:

models/jaffle_shop.yml
version: 2

sources:
- name: raw_jaffle_shop
description: A replica of the postgres database used to power the jaffle_shop app.
tables:
- name: customers
columns:
- name: id
description: Primary key of the table
tests:
- unique
- not_null

- name: orders
columns:
- name: id
description: Primary key of the table
tests:
- unique
- not_null

- name: user_id
description: Foreign key to customers

- name: status
tests:
- accepted_values:
values: ['placed', 'shipped', 'completed', 'return_pending', 'returned']


models:
- name: stg_jaffle_shop__customers
config:
tags: ['pii']
columns:
- name: customer_id
tests:
- unique
- not_null

- name: stg_jaffle_shop__orders
config:
materialized: view
columns:
- name: order_id
tests:
- unique
- not_null
- name: status
tests:
- accepted_values:
values: ['placed', 'shipped', 'completed', 'return_pending', 'returned']
config:
severity: warn


You can find an exhaustive list of each supported property and config, broken down by resource type:

FAQs

Does my `.yml` file containing tests and descriptions need to be named `schema.yml`?
If I can name these files whatever I'd like, what should I name them?
Should I use separate files to declare resource properties, or one large file?
Can I add tests and descriptions in a config block?
Why do model and source yml files always start with `version: 2`?
Can I use a YAML file extension?

Troubleshooting common errors

 Invalid test config given in [model name]
 Invalid syntax in your schema.yml file
0