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

Updated constraints doc to include the new recommended syntax #6105

Closed
wants to merge 48 commits into from
Closed
Changes from 46 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
eca97e6
Updated constraints doc to include the new recommended syntax
nataliefiann Sep 20, 2024
bee1850
Merge branch 'current' into nfiann-constraints-foreignkey
mirnawong1 Sep 20, 2024
a7c4303
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
4ceebf5
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
3b29db8
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
147536f
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
51b7906
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
c614e0e
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
4d39385
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
29b9f99
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
878d3c6
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
eb80fc5
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
76ce5ee
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
5fcc692
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
ce6b8c2
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
62f61da
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
a952ac3
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
e895010
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
f7737bb
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
1bec002
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
5519154
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
4786527
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
214d990
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
3f8c49c
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
406f5ae
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
0168346
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
5586331
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
15e4b60
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
0464cce
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
0a1d6d4
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
6f1b976
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
34e5c4f
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
6f040dd
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
ae4887d
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
66b456d
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
8c96d99
Merge branch 'current' into nfiann-constraints-foreignkey
nataliefiann Sep 20, 2024
83c4489
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
1e4cf71
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
583fd26
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 20, 2024
2d62385
Updated constraints doc to show relevant syntax for v1.9
nataliefiann Sep 23, 2024
03e57e4
Merge branch 'current' into nfiann-constraints-foreignkey
mirnawong1 Sep 24, 2024
78352d5
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 24, 2024
7c443de
Merge branch 'current' into nfiann-constraints-foreignkey
mirnawong1 Sep 24, 2024
18eba31
updated doc to perfect version block
nataliefiann Sep 24, 2024
fb3da8e
Merge branch 'current' into nfiann-constraints-foreignkey
mirnawong1 Sep 25, 2024
0b87eff
Update constraints.md
mirnawong1 Sep 25, 2024
a7b7291
Update website/docs/reference/resource-properties/constraints.md
nataliefiann Sep 25, 2024
c3be91a
Merge branch 'current' into nfiann-constraints-foreignkey
mirnawong1 Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions website/docs/reference/resource-properties/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ The structure of a constraint is:
- `type` (required): one of `not_null`, `unique`, `primary_key`, `foreign_key`, `check`, `custom`
- `expression`: Free text input to qualify the constraint. Required for certain constraint types, and optional for others.
- `name` (optional): Human-friendly name for this constraint. Supported by some data platforms.
- `columns` (model-level only): List of column names to apply the constraint over
- `columns` (model-level only): List of column names to apply the constraint over.

<VersionBlock lastVersion="1.8">

When using `foreign_key`, you need to specify the referenced table's schema manually. Use `{{ target.schema }}` in the `expression` field to automatically pass the schema used by the target environment. Note that later versions of dbt will have more efficient ways of handling this.

For example: `expression: "{{ target.schema }}.customers(customer_id)"`

</VersionBlock>

<File name='models/schema.yml'>

```yml
Expand Down Expand Up @@ -70,7 +68,54 @@ models:

</File>

In [dbt Cloud Versionless](/docs/dbt-versions/upgrade-dbt-version-in-cloud#versionless), you can use the improved syntax to define foreign keys, which uses `ref`. This feature will be available in the upcoming 1.9 release. For more information, update the documentation version to 1.9 and refer to the [What's better about this syntax section](/reference/resource-properties/constraints?version=1.9.1#whats-better-about-this-syntax).
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

</VersionBlock>

<VersionBlock firstVersion="1.9">
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

In [dbt Cloud Versionless](/docs/dbt-versions/upgrade-dbt-version-in-cloud#versionless), you can use the improved syntax to define foreign keys, which uses `ref`. This feature will be available in the upcoming 1.9 release.

#### What's better about this syntax

The recommended syntax means dbt automatically resolves references to other models, ensuring they:

- Capture dependencies
- Work across different environments

Here's an example showing how to use the recommended syntax:

<File name='models/schema.yml'>
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

```yml
models:
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
- name: <model_name>

nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
# required
config:
contract:
enforced: true

# Model-level constraints
constraints:
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
- type: foreign_key
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
columns: [id]
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
to: {{ ref('my_model_to') }} # or {{ source('source', 'source_table') }}
to_columns: [id]
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

# Column-level definitions and constraints
columns:
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
- name: id
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
data_type: integer
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
constraints:
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
- type: foreign_key
to: {{ ref('my_model_to') }} # or {{ source('source', 'source_table') }}
to_columns: [id]
```

</File>

</VersionBlock>

## Platform-specific support

Expand Down
Loading