Snapshot configurations

Related documentation

Available configurations

Snapshot-specific configurations

dbt_project.yml
snapshots:
+target_schema: <string>
+target_database: <string>
+unique_key: <column_name_or_expression>
+strategy: timestamp | check
+updated_at: <column_name>
+check_cols: [<column_name>] | all

General configurations

dbt_project.yml
snapshots:
+enabled: true | false
+tags: <string> | [<string>]
+pre-hook: <sql-statement> | [<sql-statement>]
+post-hook: <sql-statement> | [<sql-statement>]
+persist_docs: {<dict>}

Configuring snapshots

Snapshots can be configured in one of two ways:

  1. Using a config block within a snapshot, or
  2. From the dbt_project.yml file, under the snapshots: key. To apply a configuration to a snapshot, or directory of snapshots, define the resource path as nested dictionary keys.

Snapshot configurations, like model configurations, are applied hierarchically — configurations applied to a marketing subdirectory will take precedence over configurations applied to the entire jaffle_shop project.

Examples

Apply the target_schema configuration to all snapshots

To apply a configuration to all snapshots, including those in any installed packages, nest the configuration directly under the snapshots key:

dbt_project.yml
snapshots:
+target_schema: snapshots

Apply the target_schema configuration to all snapshots in your project

To apply a configuration to all snapshots in your project only (i.e. excluding any snapshots in installed packages), provide your project name as part of the resource path.

For a project named jaffle_shop:

dbt_project.yml
snapshots:
jaffle_shop:
+target_schema: snapshot_data

Similarly, you can use the name of an installed package to configure snapshots in that package.

Apply configurations to one snapshot only

We recommend using config blocks if you need to apply a configuration to one snapshot only.

snapshots/postgres_app/orders_snapshot.sql
{% snapshot orders_snapshot %}
{{
config(
unique_key='id',
strategy='timestamp',
updated_at='updated_at'
)
}}
-- Pro-Tip: Use sources in snapshots!
select * from {{ source('jaffle_shop', 'orders') }}
{% endsnapshot %}

You can also use the full resource path (including the project name, and subdirectories) to configure an individual snapshot from your dbt_project.yml file.

For a project named jaffle_shop, with a snapshot file within the snapshots/postgres_app/ directory, where the snapshot is named orders_snapshot (as above), this would look like:

dbt_project.yml
snapshots:
jaffle_shop:
postgres_app:
orders_snapshot:
+unique_key: id
+strategy: timestamp
+updated_at: updated_at