Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ca3dfcb
placeholder outline
sungchun12 Dec 19, 2022
9bb5245
add version blocks
sungchun12 Dec 19, 2022
99673b8
add to sidebar
sungchun12 Dec 19, 2022
4dc1c09
remove version blocks
sungchun12 Dec 19, 2022
1dea692
add 2 sections
sungchun12 Dec 19, 2022
ddeae87
postgres section example
sungchun12 Dec 19, 2022
8b5f874
add more docs
sungchun12 Dec 19, 2022
8788c7c
correct DDL
sungchun12 Dec 19, 2022
56004bd
correct config name
sungchun12 Dec 19, 2022
6fc8c70
fix data type
sungchun12 Dec 19, 2022
6e93abe
add redshift docs
dave-connors-3 Dec 21, 2022
769053e
Update constraints docs for Snowflake
b-per Dec 21, 2022
08daa11
Merge branch 'dbt-constraints-docs' of github.com:dbt-labs/docs.getdb…
b-per Dec 21, 2022
bff560e
Merge branch 'current' of https://github.com/dbt-labs/docs.getdbt.com…
sungchun12 Jan 3, 2023
bcdc1fa
add model config links
sungchun12 Jan 3, 2023
2d04d37
update warehouse to spark
sungchun12 Jan 3, 2023
63475b8
update not null syntax
sungchun12 Jan 3, 2023
2b0fc9e
add more config examples
sungchun12 Jan 4, 2023
c33f705
fix ordering
sungchun12 Jan 4, 2023
dc6634f
update docs based on new parsing
sungchun12 Jan 9, 2023
e295c43
add a note
sungchun12 Jan 17, 2023
181a07d
add example error messages
sungchun12 Feb 3, 2023
82a4752
Update config name on Redshift
b-per Feb 3, 2023
1df2052
Update description for Spark
b-per Feb 3, 2023
f97d987
add explainers
sungchun12 Feb 16, 2023
92eb51c
add check
sungchun12 Feb 16, 2023
b0243ff
remove fluff
sungchun12 Feb 16, 2023
f98639a
Merge branch 'current' into dbt-constraints-docs
sungchun12 Feb 16, 2023
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
Prev Previous commit
Next Next commit
add example error messages
  • Loading branch information
sungchun12 committed Feb 3, 2023
commit 181a07d52585add03d67bfbd147ebe2cc10ba988
42 changes: 41 additions & 1 deletion website/docs/reference/resource-configs/constraints_enabled.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,52 @@ You can manage data type constraints on your models using the `constraints_enabl
You can configure `constraints_enabled` in `schema.yml` files to apply constraints one-by-one for specific dbt models in `yml` config blocks. You'll receive dynamic error messages if you do not configure constraints based on the criteria below.

- Constraints must be defined in a `yml` schema configuration file like `schema.yml`.

- Only the `SQL` **table** materialization is supported for constraints.

```txt
Parsing Error
Original File Path: (models/constraints_examples/constraints_example.sql)
Constraints must be defined in a `yml` schema configuration file like `schema.yml`.
Only the SQL table materialization is supported for constraints.
`data_type` values must be defined for all columns and NOT be null or blank.
Materialization Error: {'materialization': 'snapshot'}
```

- `data_type` values must be defined for all columns and NOT be null or blank.

```txt
Parsing Error
Original File Path: (models/constraints_examples/constraints_example.sql)
Constraints must be defined in a `yml` schema configuration file like `schema.yml`.
Only the SQL table materialization is supported for constraints.
`data_type` values must be defined for all columns and NOT be null or blank.
Columns with `data_type` Blank/Null Errors: {'id'}
```

- `constraints_enabled=true` can only be configured within `schema.yml` files NOT within a model file(ex: .sql, .py) or `dbt_project.yml`. *(Note: Current parsing mechanics require all constraints configs be written in schema files to be implemented exactly as configured. This may change in the future.)*

```txt
Parsing Error
Original File Path: (models/constraints_examples/constraints_example.sql)
Constraints must be defined in a `yml` schema configuration file like `schema.yml`.
Only the SQL table materialization is supported for constraints.
`data_type` values must be defined for all columns and NOT be null or blank.
`constraints_enabled=true` can only be configured within `schema.yml` files
NOT within a model file(ex: .sql, .py) or `dbt_project.yml`.
```

- Please ensure the name, order, and number of columns in your `yml` file match the columns in your SQL file.

> Note: constraints and data type inheritance across downstream tables depends on database-specific functionality. Bias towards defining constraints for all tables in scope where desired.
```txt
# example error message
Compilation Error in model constraints_example (models/constraints_examples/constraints_example.sql)
Please ensure the name, order, and number of columns in your `yml` file match the columns in your SQL file.
Schema File Columns: ['ID', 'COLOR', 'DATE_DAY']
SQL File Columns: ['ERROR', 'COLOR', 'DATE_DAY']
```

> Note: constraints and data type inheritance across downstream tables depends on database-specific functionality. We recommend defining constraints for all tables in scope where desired.

<Tabs
defaultValue="models"
Expand Down