Skip to main content

Snapshot configurations

Available 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 Snapshots:

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
snapshots:
<resource-path>:
+enabled: true | false
+tags: <string> | [<string>]
+alias: <string>
+pre-hook: <sql-statement> | [<sql-statement>]
+post-hook: <sql-statement> | [<sql-statement>]
+persist_docs: {<dict>}
+grants: {<dict>}

Configuring snapshots

Snapshots can be configured in multiple ways:

  1. Defined in YAML files, typically in your snapshots directory (available in Versionless or and dbt Core v1.9 and higher).
  2. Using a config block within a snapshot
  3. Using a config resource property in a .yml file
  4. 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 are applied hierarchically in the order above.

Examples

The following examples demonstrate how to configure snapshots using the dbt_project.yml file, a config block within a snapshot, and a .yml file.

  • Apply configurations 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:
    +unique_key: id
  • Apply configurations to all snapshots in your project

    To apply a configuration to all snapshots in your project only (for example, 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:
    +unique_key: id

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

  • Apply configurations to one snapshot only

    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

    You can also define some common configs in a snapshot's config block. We don't recommend this for a snapshot's required configuration, however.

    dbt_project.yml
    version: 2

    snapshots:
    - name: orders_snapshot
    config:
    persist_docs:
    relation: true
    columns: true
0