Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old workarounds #6133

Merged
merged 9 commits into from
Sep 25, 2024
41 changes: 7 additions & 34 deletions website/docs/reference/resource-configs/target_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: "Target_schema - Read this in-depth guide to learn about configurat
datatype: string
---

:::note
:::info

For [versionless](/docs/dbt-versions/core-upgrade/upgrading-to-v1.8#versionless) dbt Cloud accounts and dbt Core v1.9+, this functionality is no longer required. Use the [schema](/reference/resource-configs/schema) config as an alternative to define a custom schema while still respecting the `generate_schema_name` macro.
nghi-ly marked this conversation as resolved.
Show resolved Hide resolved

nghi-ly marked this conversation as resolved.
Show resolved Hide resolved
nghi-ly marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -33,12 +33,13 @@ snapshots:
</File>

## Description
The schema that dbt should build a [snapshot](/docs/build/snapshots) <Term id="table" /> into. Snapshots build into the same `target_schema`, no matter who is running them.
The schema that dbt should build a [snapshot](/docs/build/snapshots) <Term id="table" /> into. When `target_schema` is provided, snapshots build into the same `target_schema`, no matter who is running them.

On **BigQuery**, this is analogous to a `dataset`.

## Default
This is a **required** parameter, no default is provided.

<VersionBlock lastVersion="1.8" >This is a required parameter, no default is provided. </VersionBlock>For versionless dbt Cloud accounts and dbt Core v1.9+, this is not a required parameter.
nghi-ly marked this conversation as resolved.
Show resolved Hide resolved

## Examples
### Build all snapshots in a schema named `snapshots`
Expand All @@ -53,38 +54,10 @@ snapshots:

</File>

### Use a target-aware schema
Use the [`{{ target }}` variable](/reference/dbt-jinja-functions/target) to change which schema a snapshot <Term id="table" /> is built in.

Note: consider whether this use-case is right for you, as downstream `refs` will select from the `dev` version of a snapshot, which can make it hard to validate models that depend on snapshots (see above [FAQ](#faqs))

<File name='dbt_project.yml'>

```yml
snapshots:
+target_schema: "{% if target.name == 'prod' %}snapshots{% else %}{{ target.schema }}{% endif %}"

```

</File>
<VersionBlock lastVersion="1.8" >

### Use the same schema-naming behavior as models

Leverage the [`generate_schema_name` macro](/docs/build/custom-schemas) to build snapshots in schemas that follow the same naming behavior as your models.

Notes:
* This macro is not available when configuring from the `dbt_project.yml` file, so must be configured in a snapshot config block.
* Consider whether this use-case is right for you, as downstream `refs` will select from the `dev` version of a snapshot, which can make it hard to validate models that depend on snapshots (see above [FAQ](#faqs))

For native support of environment-aware snapshots, upgrade to dbt Core version 1.9+.
nghi-ly marked this conversation as resolved.
Show resolved Hide resolved

<File name='snapshots/orders_snapshot.sql'>

```sql
{{
config(
target_schema=generate_schema_name('snapshots')
)
}}
```

</File>
</VersionBlock>
Loading