diff --git a/website/docs/reference/configs-and-properties.md b/website/docs/reference/configs-and-properties.md
index 20d762b7462..20892898a51 100644
--- a/website/docs/reference/configs-and-properties.md
+++ b/website/docs/reference/configs-and-properties.md
@@ -26,9 +26,18 @@ Whereas you can use **configurations** to:
Depending on the resource type, configurations can be defined in the dbt project and also in an installed package by:
+
+
+1. Using a [`config` property](/reference/resource-properties/config) in a `.yml` file in the `models/`, `snapshots/`, `seeds/`, `analyses`, or `tests/` directory
+2. From the [`dbt_project.yml` file](dbt_project.yml), under the corresponding resource key (`models:`, `snapshots:`, `tests:`, etc)
+
+
+
+
1. Using a [`config()` Jinja macro](/reference/dbt-jinja-functions/config) within a `model`, `snapshot`, or `test` SQL file
-2. Using a [`config` property](/reference/resource-properties/config) in a `.yml` file
+2. Using a [`config` property](/reference/resource-properties/config) in a `.yml` file in the `models/`, `snapshots/`, `seeds/`, `analyses/`, or `tests/` directory.
3. From the [`dbt_project.yml` file](dbt_project.yml), under the corresponding resource key (`models:`, `snapshots:`, `tests:`, etc)
+
### Config inheritance
diff --git a/website/docs/reference/project-configs/snapshot-paths.md b/website/docs/reference/project-configs/snapshot-paths.md
index 81b2759609d..8319833f1e6 100644
--- a/website/docs/reference/project-configs/snapshot-paths.md
+++ b/website/docs/reference/project-configs/snapshot-paths.md
@@ -12,7 +12,16 @@ snapshot-paths: [directorypath]
## Definition
-Optionally specify a custom list of directories where [snapshots](/docs/build/snapshots) are located. Note that you cannot co-locate models and snapshots.
+
+Optionally specify a custom list of directories where [snapshots](/docs/build/snapshots) are located.
+
+
+In [Versionless](/docs/dbt-versions/versionless-cloud) and on dbt v1.9 and higher, you can co-locate your snapshots with models if they are [defined using the latest YAML syntax](/docs/build/snapshots).
+
+
+
+Note that you cannot co-locate models and snapshots. However, in [Versionless](/docs/dbt-versions/versionless-cloud) and on dbt v1.9 and higher, you can co-locate your snapshots with models if they are [defined using the latest YAML syntax](/docs/build/snapshots).
+
## Default
By default, dbt will search for snapshots in the `snapshots` directory, i.e. `snapshot-paths: ["snapshots"]`
diff --git a/website/docs/reference/resource-configs/check_cols.md b/website/docs/reference/resource-configs/check_cols.md
index bd187409379..f7c6b85d372 100644
--- a/website/docs/reference/resource-configs/check_cols.md
+++ b/website/docs/reference/resource-configs/check_cols.md
@@ -3,6 +3,31 @@ resource_types: [snapshots]
description: "Read this guide to understand the check_cols configuration in dbt."
datatype: "[column_name] | all"
---
+
+
+
+
+ ```yml
+ snapshots:
+ - name: snapshot_name
+ relation: source('my_source', 'my_table')
+ config:
+ schema: string
+ unique_key: column_name_or_expression
+ strategy: check
+ check_cols:
+ - column_name
+ ```
+
+
+
+
+
+
+import SnapshotYaml from '/snippets/_snapshot-yaml-spec.md';
+
+
+
```jinja2
@@ -14,7 +39,7 @@ datatype: "[column_name] | all"
```
-
+
@@ -42,6 +67,29 @@ No default is provided.
### Check a list of columns for changes
+
+
+
+
+```yaml
+snapshots:
+ - name: orders_snapshot_check
+ relation: source('jaffle_shop', 'orders')
+ config:
+ schema: snapshots
+ unique_key: id
+ strategy: check
+ check_cols:
+ - status
+ - is_cancelled
+```
+
+
+To select from this snapshot in a downstream model: `select * from {{ ref('orders_snapshot_check') }}`
+
+
+
+
```sql
{% snapshot orders_snapshot_check %}
@@ -58,8 +106,32 @@ No default is provided.
{% endsnapshot %}
```
+
+
### Check all columns for changes
+
+
+
+
+```yaml
+snapshots:
+ - name: orders_snapshot_check
+ relation: source('jaffle_shop', 'orders')
+ config:
+ schema: snapshots
+ unique_key: id
+ strategy: check
+ check_cols:
+ - all
+ ```
+
+
+To select from this snapshot in a downstream model: `select * from {{{ ref('orders_snapshot_check') }}`
+
+
+
+
```sql
{% snapshot orders_snapshot_check %}
@@ -75,3 +147,4 @@ No default is provided.
{% endsnapshot %}
```
+
diff --git a/website/docs/reference/resource-configs/invalidate_hard_deletes.md b/website/docs/reference/resource-configs/invalidate_hard_deletes.md
index ba5b37c5d71..bdaec7e33a9 100644
--- a/website/docs/reference/resource-configs/invalidate_hard_deletes.md
+++ b/website/docs/reference/resource-configs/invalidate_hard_deletes.md
@@ -4,6 +4,31 @@ description: "Invalidate_hard_deletes - Read this in-depth guide to learn about
datatype: column_name
---
+
+
+
+
+
+```yaml
+snapshots:
+ - name: snapshot
+ relation: source('my_source', 'my_table')
+ [config](/reference/snapshot-configs):
+ strategy: timestamp
+ invalidate_hard_deletes: true | false
+```
+
+
+
+
+
+
+
+
+import SnapshotYaml from '/snippets/_snapshot-yaml-spec.md';
+
+
+
```jinja2
@@ -17,6 +42,7 @@ datatype: column_name
```
+
@@ -39,6 +65,26 @@ By default the feature is disabled.
## Example
+
+
+
+```yaml
+snapshots:
+ - name: orders_snapshot
+ relation: source('jaffle_shop', 'orders')
+ config:
+ schema: snapshots
+ database: analytics
+ unique_key: id
+ strategy: timestamp
+ updated_at: updated_at
+ invalidate_hard_deletes: true
+ ```
+
+
+
+
+
```sql
@@ -60,3 +106,4 @@ By default the feature is disabled.
```
+
diff --git a/website/docs/reference/resource-configs/pre-hook-post-hook.md b/website/docs/reference/resource-configs/pre-hook-post-hook.md
index e1e7d67f02e..ce818768134 100644
--- a/website/docs/reference/resource-configs/pre-hook-post-hook.md
+++ b/website/docs/reference/resource-configs/pre-hook-post-hook.md
@@ -109,6 +109,8 @@ snapshots:
+
+
```sql
@@ -125,13 +127,14 @@ select ...
```
+
-
+
```yml
snapshots:
- name: []
- config:
+ [config](/reference/resource-properties/config):
[pre_hook](/reference/resource-configs/pre-hook-post-hook): | []
[post_hook](/reference/resource-configs/pre-hook-post-hook): | []
```
diff --git a/website/docs/reference/resource-configs/snapshot_name.md b/website/docs/reference/resource-configs/snapshot_name.md
index bb4826a116b..62480ac3f84 100644
--- a/website/docs/reference/resource-configs/snapshot_name.md
+++ b/website/docs/reference/resource-configs/snapshot_name.md
@@ -2,6 +2,27 @@
description: "Snapshot-name - Read this in-depth guide to learn about configurations in dbt."
---
+
+
+
+```yaml
+snapshots:
+ - name: snapshot_name
+ relation: source('my_source', 'my_table')
+ config:
+ schema: string
+ database: string
+ unique_key: column_name_or_expression
+ strategy: timestamp | check
+ updated_at: column_name # Required if strategy is 'timestamp'
+
+```
+
+
+
+
+
+
```jinja2
@@ -13,9 +34,15 @@ description: "Snapshot-name - Read this in-depth guide to learn about configurat
+import SnapshotYaml from '/snippets/_snapshot-yaml-spec.md';
+
+
+
+
+
## Description
-The name of a snapshot, as defined in the `{% snapshot %}` block header. This name is used when selecting from a snapshot using the [`ref` function](/reference/dbt-jinja-functions/ref)
+The name of a snapshot, which is used when selecting from a snapshot using the [`ref` function](/reference/dbt-jinja-functions/ref)
This name must not conflict with the name of any other "refable" resource (models, seeds, other snapshots) defined in this project or package.
@@ -24,6 +51,26 @@ The name does not need to match the file name. As a result, snapshot filenames d
## Examples
### Name a snapshot `order_snapshot`
+
+
+
+
+```yaml
+snapshots:
+ - name: order_snapshot
+ relation: source('my_source', 'my_table')
+ config:
+ schema: string
+ database: string
+ unique_key: column_name_or_expression
+ strategy: timestamp | check
+ updated_at: column_name # Required if strategy is 'timestamp'
+```
+
+
+
+
+
```jinja2
@@ -35,6 +82,7 @@ The name does not need to match the file name. As a result, snapshot filenames d
+
To select from this snapshot in a downstream model:
diff --git a/website/docs/reference/resource-configs/strategy.md b/website/docs/reference/resource-configs/strategy.md
index b67feb64fbd..e2b2cac1c59 100644
--- a/website/docs/reference/resource-configs/strategy.md
+++ b/website/docs/reference/resource-configs/strategy.md
@@ -4,6 +4,13 @@ description: "Strategy - Read this in-depth guide to learn about configurations
datatype: timestamp | check
---
+
+
+import SnapshotYaml from '/snippets/_snapshot-yaml-spec.md';
+
+
+
+
+
+
+
+
+ ```yaml
+ snapshots:
+ - [name: snapshot_name](/reference/resource-configs/snapshot_name):
+ relation: source('my_source', 'my_table')
+ config:
+ strategy: timestamp
+ updated_at: column_name
+ ```
+
+
+
+
+
```jinja2
@@ -30,6 +54,7 @@ select ...
```
+
@@ -47,6 +72,22 @@ snapshots:
+
+
+
+
+ ```yaml
+ snapshots:
+ - [name: snapshot_name](/reference/resource-configs/snapshot_name):
+ relation: source('my_source', 'my_table')
+ config:
+ strategy: check
+ check_cols: [column_name] | "all"
+ ```
+
+
+
+
```jinja2
@@ -62,6 +103,7 @@ snapshots:
```
+
@@ -88,7 +130,25 @@ This is a **required configuration**. There is no default value.
## Examples
### Use the timestamp strategy
+
+
+
+```yaml
+snapshots:
+ - name: orders_snapshot_timestamp
+ relation: source('jaffle_shop', 'orders')
+ config:
+ schema: snapshots
+ strategy: timestamp
+ unique_key: id
+ updated_at: updated_at
+
+```
+
+
+
+
```sql
@@ -109,10 +169,32 @@ This is a **required configuration**. There is no default value.
```
+
### Use the check strategy
+
+
+
+```yaml
+snapshots:
+ - name: orders_snapshot_check
+ relation: source('jaffle_shop', 'orders')
+ config:
+ schema: snapshots
+ unique_key: id
+ strategy: check
+ check_cols:
+ - status
+ - is_cancelled
+
+```
+
+
+
+
+
```sql
{% snapshot orders_snapshot_check %}
@@ -129,6 +211,7 @@ This is a **required configuration**. There is no default value.
{% endsnapshot %}
```
+
### Advanced: define and use custom snapshot strategy
Behind the scenes, snapshot strategies are implemented as macros, named `snapshot__strategy`
@@ -140,6 +223,23 @@ It's possible to implement your own snapshot strategy by adding a macro with the
1. Create a macro named `snapshot_timestamp_with_deletes_strategy`. Use the existing code as a guide and adjust as needed.
2. Use this strategy via the `strategy` configuration:
+
+
+
+```yaml
+snapshots:
+ - name: my_custom_snapshot
+ relation: source('my_source', 'my_table')
+ config:
+ strategy: timestamp_with_deletes
+ updated_at: updated_at_column
+ unique_key: id
+```
+
+
+
+
+
```jinja2
@@ -155,3 +255,4 @@ It's possible to implement your own snapshot strategy by adding a macro with the
```
+
diff --git a/website/docs/reference/resource-configs/unique_key.md b/website/docs/reference/resource-configs/unique_key.md
index 9ad3417fd5e..996e7148292 100644
--- a/website/docs/reference/resource-configs/unique_key.md
+++ b/website/docs/reference/resource-configs/unique_key.md
@@ -4,6 +4,29 @@ description: "Unique_key - Read this in-depth guide to learn about configuration
datatype: column_name_or_expression
---
+
+
+
+
+
+```yaml
+snapshots:
+ - name: orders_snapshot
+ relation: source('my_source', 'my_table')
+ [config](/reference/snapshot-configs):
+ unique_key: id
+
+```
+
+
+
+
+
+
+import SnapshotYaml from '/snippets/_snapshot-yaml-spec.md';
+
+
+
```jinja2
@@ -12,8 +35,8 @@ datatype: column_name_or_expression
) }}
```
-
+
@@ -29,6 +52,8 @@ snapshots:
## Description
A column name or expression that is unique for the inputs of a snapshot. dbt uses this to match records between a result set and an existing snapshot, so that changes can be captured correctly.
+In Versionless and dbt v1.9 and later, [snapshots](/docs/build/snapshots) are defined and configured in YAML files within your `snapshots/` directory. The `unique_key` is specified within the `config` block of your snapshot YAML file.
+
:::caution
Providing a non-unique key will result in unexpected snapshot results. dbt **will not** test the uniqueness of this key, consider [testing](/blog/primary-key-testing#how-to-test-primary-keys-with-dbt) the source data to ensure that this key is indeed unique.
@@ -41,6 +66,26 @@ This is a **required parameter**. No default is provided.
## Examples
### Use an `id` column as a unique key
+
+
+
+
+
+```yaml
+snapshots:
+ - name: orders_snapshot
+ relation: source('jaffle_shop', 'orders')
+ config:
+ schema: snapshots
+ unique_key: id
+ strategy: timestamp
+ updated_at: updated_at
+
+```
+
+
+
+
```jinja2
@@ -55,7 +100,9 @@ This is a **required parameter**. No default is provided.
You can also write this in yaml. This might be a good idea if multiple snapshots share the same `unique_key` (though we prefer to apply this configuration in a config block, as above).
+
+You can also specify configurations in your `dbt_project.yml` file if multiple snapshots share the same `unique_key`:
```yml
@@ -70,6 +117,25 @@ snapshots:
### Use a combination of two columns as a unique key
This configuration accepts a valid column expression. As such, you can concatenate two columns together as a unique key if required. It's a good idea to use a separator (e.g. `'-'`) to ensure uniqueness.
+
+
+
+
+```yaml
+snapshots:
+ - name: transaction_items_snapshot
+ relation: source('erp', 'transactions')
+ config:
+ schema: snapshots
+ unique_key: "transaction_id || '-' || line_item_id"
+ strategy: timestamp
+ updated_at: updated_at
+
+```
+
+
+
+
@@ -93,10 +159,45 @@ from {{ source('erp', 'transactions') }}
```
+
Though, it's probably a better idea to construct this column in your query and use that as the `unique_key`:
+
+
+
+
+```yaml
+snapshots:
+ - name: transaction_items_snapshot
+ relation: {{ ref('transaction_items_ephemeral') }}
+ config:
+ schema: snapshots
+ unique_key: id
+ strategy: timestamp
+ updated_at: updated_at
+```
+
+
+
+
+```sql
+{{ config(materialized='ephemeral') }}
+
+select
+ transaction_id || '-' || line_item_id as id,
+ *
+from {{ source('erp', 'transactions') }}
+
+```
+
+
+
+In this example, we create an ephemeral model `transaction_items_ephemeral` that creates an `id` column that can be used as the `unique_key` our snapshot configuration.
+
+
+
```jinja2
@@ -121,3 +222,4 @@ from {{ source('erp', 'transactions') }}
```
+
diff --git a/website/docs/reference/resource-configs/updated_at.md b/website/docs/reference/resource-configs/updated_at.md
index c61b04264be..09122859e43 100644
--- a/website/docs/reference/resource-configs/updated_at.md
+++ b/website/docs/reference/resource-configs/updated_at.md
@@ -3,6 +3,29 @@ resource_types: [snapshots]
description: "Updated_at - Read this in-depth guide to learn about configurations in dbt."
datatype: column_name
---
+
+
+
+
+
+
+```yaml
+snapshots:
+ - name: snapshot
+ relation: source('my_source', 'my_table')
+ [config](/reference/snapshot-configs):
+ strategy: timestamp
+ updated_at: column_name
+```
+
+
+
+
+
+import SnapshotYaml from '/snippets/_snapshot-yaml-spec.md';
+
+
+
```jinja2
@@ -14,6 +37,7 @@ datatype: column_name
```
+
@@ -37,7 +61,6 @@ You will get a warning if the data type of the `updated_at` column does not matc
-
## Description
A column within the results of your snapshot query that represents when the record row was last updated.
@@ -50,6 +73,25 @@ No default is provided.
## Examples
### Use a column name `updated_at`
+
+
+
+
+```yaml
+snapshots:
+ - name: orders_snapshot
+ relation: source('jaffle_shop', 'orders')
+ config:
+ schema: snapshots
+ unique_key: id
+ strategy: timestamp
+ updated_at: updated_at
+
+```
+
+
+
+
```sql
@@ -72,12 +114,55 @@ select * from {{ source('jaffle_shop', 'orders') }}
```
+
### Coalesce two columns to create a reliable `updated_at` column
Consider a data source that only has an `updated_at` column filled in when a record is updated (so a `null` value indicates that the record hasn't been updated after it was created).
Since the `updated_at` configuration only takes a column name, rather than an expression, you should update your snapshot query to include the coalesced column.
+
+
+
+1. Create an staging model to perform the transformation.
+ In your `models/` directory, create a SQL file that configures an staging model to coalesce the `updated_at` and `created_at` columns into a new column `updated_at_for_snapshot`.
+
+
+
+ ```sql
+ select * coalesce (updated_at, created_at) as updated_at_for_snapshot
+ from {{ source('jaffle_shop', 'orders') }}
+
+ ```
+
+
+2. Define the snapshot configuration in a YAML file.
+ In your `snapshots/` directory, create a YAML file that defines your snapshot and references the `updated_at_for_snapshot` staging model you just created.
+
+
+
+ ```yaml
+ snapshots:
+ - name: orders_snapshot
+ relation: ref('staging_orders')
+ config:
+ schema: snapshots
+ unique_key: id
+ strategy: timestamp
+ updated_at: updated_at_for_snapshot
+
+ ```
+
+
+3. Run `dbt snapshot` to execute the snapshot.
+
+Alternatively, you can also create an ephemeral model to performs the required transformations. Then, you reference this model in your snapshot's `relation` key.
+
+
+
+
+
+
```sql
@@ -104,3 +189,4 @@ from {{ source('jaffle_shop', 'orders') }}
```
+
diff --git a/website/docs/reference/snapshot-configs.md b/website/docs/reference/snapshot-configs.md
index fd5969a4c8c..87063ce592e 100644
--- a/website/docs/reference/snapshot-configs.md
+++ b/website/docs/reference/snapshot-configs.md
@@ -24,15 +24,24 @@ Parts of a snapshot:
+
+
+import SnapshotYaml from '/snippets/_snapshot-yaml-spec.md';
+
+
+
+
+
+
@@ -87,6 +96,8 @@ snapshots:
+
+Refer to [configuring snapshots](/docs/build/snapshots#configuring-snapshots) for the available configurations.
@@ -108,33 +119,21 @@ snapshots:
-
-
-
+
-```jinja
-
-{{ config(
- [target_schema](/reference/resource-configs/target_schema)="",
- [target_database](/reference/resource-configs/target_database)="",
- [unique_key](/reference/resource-configs/unique_key)="",
- [strategy](/reference/resource-configs/strategy)="timestamp" | "check",
- [updated_at](/reference/resource-configs/updated_at)="",
- [check_cols](/reference/resource-configs/check_cols)=[""] | "all"
-) }}
+
-```
+Configurations can be applied to snapshots using [YAML syntax](/docs/build/snapshots), available in Versionless and dbt v1.9 and higher, in the the `snapshot` directory file.
-
+
```jinja
{{ config(
- [schema](/reference/resource-configs/schema)="",
- [database](/reference/resource-configs/database)="",
- [alias](/reference/resource-configs/alias)="",
+ [target_schema](/reference/resource-configs/target_schema)="",
+ [target_database](/reference/resource-configs/target_database)="",
[unique_key](/reference/resource-configs/unique_key)="",
[strategy](/reference/resource-configs/strategy)="timestamp" | "check",
[updated_at](/reference/resource-configs/updated_at)="",
@@ -142,7 +141,6 @@ snapshots:
) }}
```
-
@@ -159,7 +157,7 @@ snapshots:
defaultValue="project-yaml"
values={[
{ label: 'Project file', value: 'project-yaml', },
- { label: 'Property file', value: 'property-yaml', },
+ { label: 'YAML file', value: 'property-yaml', },
{ label: 'Config block', value: 'config', },
]
}>
@@ -184,6 +182,30 @@ snapshots:
+
+
+
+
+```yaml
+version: 2
+
+snapshots:
+ - name: []
+ config:
+ [enabled](/reference/resource-configs/enabled): true | false
+ [tags](/reference/resource-configs/tags): | []
+ [alias](/reference/resource-configs/alias):
+ [pre-hook](/reference/resource-configs/pre-hook-post-hook): | []
+ [post-hook](/reference/resource-configs/pre-hook-post-hook): | []
+ [persist_docs](/reference/resource-configs/persist_docs): {}
+ [grants](/reference/resource-configs/grants): {}
+```
+
+
+
+
+
+
```yaml
@@ -191,6 +213,7 @@ version: 2
snapshots:
- name: []
+ relation: source('my_source', 'my_table')
config:
[enabled](/reference/resource-configs/enabled): true | false
[tags](/reference/resource-configs/tags): | []
@@ -202,11 +225,19 @@ snapshots:
```
+
+
+
+Configurations can be applied to snapshots using [YAML syntax](/docs/build/snapshots), available in Versionless and dbt v1.9 and higher, in the the `snapshot` directory file.
+
+
+
+
```jinja
@@ -222,106 +253,140 @@ snapshots:
```
+
+
-
## Configuring snapshots
-Snapshots can be configured in one of three ways:
-
-1. Using a `config` block within a snapshot
-2. Using a `config` [resource property](/reference/model-properties) in a `.yml` file
-3. 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
-#### Apply configurations to all snapshots
-To apply a configuration to all snapshots, including those in any installed [packages](/docs/build/packages), nest the configuration directly under the `snapshots` key:
+Snapshots can be configured in multiple ways:
-
-
-```yml
-
-snapshots:
- +unique_key: id
-```
-
-
+
+1. Defined in YAML files using a `config` [resource property](/reference/model-properties), typically in your [snapshots directory](/reference/project-configs/snapshot-paths) (available in [Versionless](/docs/dbt-versions/versionless-cloud) or and dbt Core v1.9 and higher).
+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.
+
-#### 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`:
+1. Defined in YAML files using a `config` [resource property](/reference/model-properties), typically in your [snapshots directory](/reference/project-configs/snapshot-paths) (available in [Versionless](/docs/dbt-versions/versionless-cloud) or and dbt Core v1.9 and higher).
+2. Using a `config` block within a snapshot defined in Jinja SQL
+3. 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.
-
+Note that in Versionless and dbt v1.9 and later, snapshots are defined in an updated syntax using a YAML file within your `snapshots/` directory (as defined by the [`snapshot-paths` config](/reference/project-configs/snapshot-paths)). For faster and more efficient management, consider the updated snapshot YAML syntax, [available in Versionless](/docs/dbt-versions/versionless-cloud) or [dbt Core v1.9 and later](/docs/dbt-versions/core).
-```yml
+
-snapshots:
- jaffle_shop:
- +unique_key: id
-```
+Snapshot configurations are applied hierarchically in the order above with higher taking precedence.
-
+### 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.
-Similarly, you can use the name of an installed package to configure snapshots in that package.
+- #### Apply configurations to all snapshots
+ To apply a configuration to all snapshots, including those in any installed [packages](/docs/build/packages), nest the configuration directly under the `snapshots` key:
-#### Apply configurations to one snapshot only
+
-We recommend using `config` blocks if you need to apply a configuration to one snapshot only.
+ ```yml
-
+ snapshots:
+ +unique_key: id
+ ```
-```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 %}
-```
+
-
+- #### 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.
-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`:
-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:
+
-
+ ```yml
-```yml
-snapshots:
- jaffle_shop:
- postgres_app:
- orders_snapshot:
+ snapshots:
+ jaffle_shop:
+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.
-
-
-
-```yml
-version: 2
-
-snapshots:
- - name: orders_snapshot
- config:
- persist_docs:
- relation: true
- columns: true
-```
-
-
+ ```
+
+
+
+ Similarly, you can use the name of an installed package to configure snapshots in that package.
+
+- #### Apply configurations to one snapshot only
+
+
+ Use `config` blocks if you need to apply a configuration to one snapshot only.
+
+
+
+ ```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 %}
+ ```
+
+
+
+
+
+
+
+ ```yaml
+ snapshots:
+ - name: orders_snapshot
+ relation: source('jaffle_shop', 'orders')
+ config:
+ unique_key: id
+ strategy: timestamp
+ updated_at: updated_at
+ persist_docs:
+ relation: true
+ columns: true
+ ```
+
+ Pro-tip: Use sources in snapshots: `select * from {{ source('jaffle_shop', 'orders') }}`
+
+
+ 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:
+
+
+
+ ```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.
+
+
+
+ ```yml
+ version: 2
+
+ snapshots:
+ - name: orders_snapshot
+ +persist_docs:
+ relation: true
+ columns: true
+ ```
+
+
diff --git a/website/docs/reference/snapshot-properties.md b/website/docs/reference/snapshot-properties.md
index 49769af8f6d..d940a9f344c 100644
--- a/website/docs/reference/snapshot-properties.md
+++ b/website/docs/reference/snapshot-properties.md
@@ -3,12 +3,62 @@ title: Snapshot properties
description: "Read this guide to learn about using source properties in dbt."
---
+
+
+In Versionless and dbt v1.9 and later, snapshots are defined and configured in YAML files within your `snapshots/` directory (as defined by the [`snapshot-paths` config](/reference/project-configs/snapshot-paths)). Snapshot properties are declared within these YAML files, allowing you to define both the snapshot configurations and properties in one place.
+
+
+
+
+
Snapshots properties can be declared in `.yml` files in:
-- your `snapshots/` directory (as defined by the [`snapshot-paths` config](/reference/project-configs/snapshot-paths))
+- your `snapshots/` directory (as defined by the [`snapshot-paths` config](/reference/project-configs/snapshot-paths)).
- your `models/` directory (as defined by the [`model-paths` config](/reference/project-configs/model-paths))
+Note, in Versionless and dbt v1.9 and later, snapshots are defined in an updated syntax using a YAML file within your `snapshots/` directory (as defined by the [`snapshot-paths` config](/reference/project-configs/snapshot-paths)). For faster and more efficient management, consider the updated snapshot YAML syntax, [available in Versionless](/docs/dbt-versions/versionless-cloud) or [dbt Core v1.9 and later](/docs/dbt-versions/core).
+
+
+
We recommend that you put them in the `snapshots/` directory. You can name these files `whatever_you_want.yml`, and nest them arbitrarily deeply in subfolders within the `snapshots/` or `models/` directory.
+
+
+
+
+```yml
+version: 2
+
+snapshots:
+ - name:
+ [description](/reference/resource-properties/description):
+ [meta](/reference/resource-configs/meta): {}
+ [docs](/reference/resource-configs/docs):
+ show: true | false
+ node_color: # Use name (such as node_color: purple) or hex code with quotes (such as node_color: "#cd7f32")
+ [config](/reference/resource-properties/config):
+ [](/reference/snapshot-configs):
+ [tests](/reference/resource-properties/data-tests):
+ -
+ - ...
+ columns:
+ - name:
+ [description](/reference/resource-properties/description):
+ [meta](/reference/resource-configs/meta): {}
+ [quote](/reference/resource-properties/quote): true | false
+ [tags](/reference/resource-configs/tags): []
+ [tests](/reference/resource-properties/data-tests):
+ -
+ - ... # declare additional tests
+ - ... # declare properties of additional columns
+
+ - name: ... # declare properties of additional snapshots
+
+```
+
+
+
+
+
```yml
@@ -41,3 +91,4 @@ snapshots:
```
+
diff --git a/website/snippets/_snapshot-yaml-spec.md b/website/snippets/_snapshot-yaml-spec.md
new file mode 100644
index 00000000000..8bbdc6be72e
--- /dev/null
+++ b/website/snippets/_snapshot-yaml-spec.md
@@ -0,0 +1,4 @@
+:::info Use the latest snapshot syntax
+
+In Versionless and dbt v1.9 and later, snapshots are defined in an updated syntax using a YAML file within your `snapshots/` directory (as defined by the [`snapshot-paths` config](/reference/project-configs/snapshot-paths)). For faster and more efficient management, consider the updated snapshot YAML syntax, [available in Versionless](/docs/dbt-versions/versionless-cloud) or [dbt Core v1.9 and later](/docs/dbt-versions/core).
+:::