Skip to main content

Model configurations

Available configurations

Model-specific configurations

Resource-specific configurations are applicable to only one dbt resource type rather than multiple resource types. You can define these settings in the project file (dbt_project.yml), a property file (models/properties.yml for models, similarly for other resources), or within the resource’s file using the {{ config() }} macro.

The following resource-specific configurations are only available to Models:

dbt_project.yml
models:
<resource-path>:
+materialized: <materialization_name>
+sql_header: <string>
+on_configuration_change: apply | continue | fail #only for materialized views on supported adapters
+unique_key: <column_name_or_expression>

General configurations

General configurations provide broader operational settings applicable across multiple resource types. Like resource-specific configurations, these can also be set in the project file, property files, or within resource-specific files.

dbt_project.yml

Warehouse-specific configurations

Configuring models

Model configurations are applied hierarchically. You can configure models from within an installed package and also from within your dbt project in the following ways, listed in order of precedence:

  1. Using a config() Jinja macro within a model.
  2. Using a config resource property in a .yml file.
  3. From the dbt_project.yml project file, under the models: key. In this case, the model that's nested the deepest will have the highest priority.

The most specific configuration 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.

Model 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.

Example

Configuring directories of models in dbt_project.yml

To configure models in your dbt_project.yml file, use the models: configuration option. Be sure to namespace your configurations to your project (shown below):

dbt_project.yml


name: dbt_labs

models:
# Be sure to namespace your model configs to your project name
dbt_labs:

# This configures models found in models/events/
events:
+enabled: true
+materialized: view

# This configures models found in models/events/base
# These models will be ephemeral, as the config above is overridden
base:
+materialized: ephemeral

...


Apply configurations to one model only

Some types of configurations are specific to a particular model. In these cases, placing configurations in the dbt_project.yml file can be unwieldy. Instead, you can specify these configurations at the top of a model .sql file, or in its individual YAML properties.

models/events/base/base_events.sql
{{
config(
materialized = "table",
sort = 'event_time',
dist = 'event_id'
)
}}


select * from ...
models/events/base/properties.yml
version: 2

models:
- name: base_events
config:
materialized: table
sort: event_time
dist: event_id
0