Skip to content

Commit

Permalink
Update constraints.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mirnawong1 authored Oct 4, 2024
1 parent 749dc8a commit 3ae24bd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions website/docs/reference/resource-properties/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Constraints require the declaration and enforcement of a model [contract](/refer

Constraints may be defined for a single column, or at the model level for one or more columns. As a general rule, we recommend defining single-column constraints directly on those columns.

If you are defining multiple `primary_key` constraints for a single model, those _must_ be defined at the model level. Defining multiple `primary_key` constraints at the column level is not supported.
If you define multiple `primary_key` constraints for a single model, those _must_ be defined at the model level. Defining multiple `primary_key` constraints at the column level is not supported.

The structure of a constraint is:
- `type` (required): one of `not_null`, `unique`, `primary_key`, `foreign_key`, `check`, `custom`
Expand Down Expand Up @@ -588,7 +588,8 @@ You can implement constraints in a couple of different ways:

- [Custom constraints with tags](#custom-constraints-with-tags)
- [Custom constraints without tags](#custom-constraints-without-tags)
### Custom constraints with tags

<Expandable alt_header="Custom constraints with tags">

Here's an example of how to implement tag-based masking policies with contracts and constraints using the following syntax:

Expand Down Expand Up @@ -616,9 +617,9 @@ models:
Using this syntax requires configuring all the columns and their types as it’s the only way to send a create or replace `<cols_info_with_masking> mytable as ...`. It’s not possible to do it with just a partial list of columns. This means making sure the columns and constraints fields are fully defined.

To generate a YAML with all the columns, you can use `generate_model_yaml` from [dbt-codegen](https://github.com/dbt-labs/dbt-codegen/tree/0.12.1/?tab=readme-ov-file#generate_model_yaml-source).
</Expandable>


### Custom constraints without tags
<Expandable alt_header="Custom constraints without tags"/>

Alternatively, you can add a masking policy without tags:

Expand All @@ -642,5 +643,5 @@ models:
```

</File>

</Expandable>

0 comments on commit 3ae24bd

Please sign in to comment.