+
+
+
+* PostgreSQL constraints documentation: [here](https://www.postgresql.org/docs/current/ddl-constraints.html#id-1.5.4.6.6)
+
+
+
+```sql
+{{
+ config(
+ materialized = "table"
+ )
+}}
+
+select
+ 1 as id,
+ 'blue' as color,
+ cast('2019-01-01' as date) as date_day
+```
+
+
+
+
+
+```yml
+models:
+ - name: constraints_example
+ docs:
+ node_color: black
+ config:
+ constraints_enabled: true
+ columns:
+ - name: id
+ data_type: integer
+ description: hello
+ constraints: ['not null','primary key']
+ constraints_check: (id > 0)
+ tests:
+ - unique
+ - name: color
+ data_type: text
+ - name: date_day
+ data_type: date
+```
+
+
+
+Expected DDL to enforce constraints:
+
+
+```sql
+create table "database_name"."schema_name"."constraints_example__dbt_tmp"
+(
+ id integer not null primary key check (id > 0),
+ color text,
+ date_day date
+)
+;
+insert into "database_name"."schema_name"."constraints_example__dbt_tmp"
+(
+ id,
+ color,
+ date_day
+)
+(
+select
+ 1 as id,
+ 'blue' as color,
+ cast('2019-01-01' as date) as date_day
+);
+```
+
+
+
+
+
+
+
+Redshift currently only enforces `not null` constraints; all other constraints are metadata only. Additionally, Redshift does not allow column checks at the time of table creation. See more in the Redshift documentation [here](https://docs.aws.amazon.com/redshift/latest/dg/t_Defining_constraints.html).
+
+
+
+```sql
+{{
+ config(
+ materialized = "table"
+ )
+}}
+
+select
+ 1 as id,
+ 'blue' as color,
+ cast('2019-01-01' as date) as date_day
+```
+
+
+
+
+
+```yml
+models:
+ - name: constraints_example
+ docs:
+ node_color: black
+ config:
+ constraints_enabled: true
+ columns:
+ - name: id
+ data_type: integer
+ description: hello
+ constraints: ['not null','primary key']
+ constraints_check: (id > 0)
+ tests:
+ - unique
+ - name: color
+ data_type: varchar
+ - name: date_day
+ data_type: date
+```
+
+
+
+Expected DDL to enforce constraints:
+
+
+```sql
+
+create table "database_name"."schema_name"."constraints_example__dbt_tmp"
+
+(
+ id integer not null,
+ color varchar,
+ date_day date,
+ primary key(id)
+)
+;
+
+insert into "database_name"."schema_name"."constraints_example__dbt_tmp"
+(
+select
+ 1 as id,
+ 'blue' as color,
+ cast('2019-01-01' as date) as date_day
+);
+```
+
+
+
+
+
+
+
+
+- Snowflake constraints documentation: [here](https://docs.snowflake.com/en/sql-reference/constraints-overview.html)
+- Snowflake data types: [here](https://docs.snowflake.com/en/sql-reference/intro-summary-data-types.html)
+
+Snowflake suppports four types of constraints: `unique`, `not null`, `primary key` and `foreign key`.
+
+It is important to note that only the `not null` (and the `not null` property of `primary key`) are actually checked today.
+There rest of the constraints are purely metadata, not verified when inserting data.
+
+Currently, Snowflake doesn't support the `check` syntax and dbt will skip the `check` config and raise a warning message if it is set on some models in the dbt project.
+
+
+
+```sql
+{{
+ config(
+ materialized = "table"
+ )
+}}
+
+select
+ 1 as id,
+ 'blue' as color,
+ cast('2019-01-01' as date) as date_day
+```
+
+
+
+
+
+```yml
+models:
+ - name: constraints_example
+ docs:
+ node_color: black
+ config:
+ constraints_enabled: true
+ columns:
+ - name: id
+ data_type: integer
+ description: hello
+ constraints: ['not null','primary key']
+ tests:
+ - unique
+ - name: color
+ data_type: text
+ - name: date_day
+ data_type: date
+```
+
+
+
+Expected DDL to enforce constraints:
+
+
+```sql
+create or replace transient table ..constraints_model
+(
+ id integer not null primary key,
+ color text,
+ date_day date
+)
+as
+(
+select
+ 1 as id,
+ 'blue' as color,
+ cast('2019-01-01' as date) as date_day
+);
+```
+
+
+
+
+
+
+
+BigQuery allows defining `not null` constraints. However, it does _not_ support or enforce the definition of unenforced constraints, such as `primary key`.
+
+Documentation: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
+
+Data types: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types
+
+
+
+```sql
+{{
+ config(
+ materialized = "table"
+ )
+}}
+
+select
+ 1 as id,
+ 'blue' as color,
+ cast('2019-01-01' as date) as date_day
+```
+
+
+
+
+
+```yml
+models:
+ - name: constraints_example
+ docs:
+ node_color: black
+ config:
+ constraints_enabled: true
+ columns:
+ - name: id
+ data_type: integer
+ description: hello
+ constraints: ['not null'] # 'primary key' is not supported
+ tests:
+ - unique
+ - name: color
+ data_type: string
+ - name: date_day
+ data_type: date
+```
+
+
+
+Expected DDL to enforce constraints:
+
+
+```sql
+create or replace table ``.``.`constraints_model`
+(
+ id integer not null,
+ color string,
+ date_day date
+)
+as
+(
+select
+ 1 as id,
+ 'blue' as color,
+ cast('2019-01-01' as date) as date_day
+);
+```
+
+
+
+
+
+
+
+Databricks allows you to define:
+
+- a `not null` constraint
+- and/or additional `check` constraints, with conditional expressions including one or more columns
+
+As Databricks does not support transactions nor allows using `create or replace table` with a column schema, the table is first created without a schema and `alter` statements are then executed to add the different constraints.
+
+This means that:
+
+- The names and order of columns is checked but not their type
+- If the `constraints` and/or `constraint_check` fails, the table with the failing data will still exist in the Warehouse
+
+See [this page](https://docs.databricks.com/tables/constraints.html) with more details about the support of constraints on Databricks.
+
+
+
+```sql
+{{
+ config(
+ materialized = "table"
+ )
+}}
+
+select
+ 1 as id,
+ 'blue' as color,
+ cast('2019-01-01' as date) as date_day
+```
+
+
+
+
+
+```yml
+models:
+ - name: constraints_example
+ docs:
+ node_color: black
+ config:
+ constraints_enabled: true
+ columns:
+ - name: id
+ data_type: integer
+ description: hello
+ constraints: ['not null']
+ constraints_check: "(id > 0)"
+ tests:
+ - unique
+ - name: color
+ data_type: text
+ - name: date_day
+ data_type: date
+```
+
+
+
+Expected DDL to enforce constraints:
+
+
+```sql
+ create or replace table schema_name.my_model
+ using delta
+ as
+ select
+ 1 as id,
+ 'blue' as color,
+ cast('2019-01-01' as date) as date_day
+```
+
+
+
+Followed by the statements
+
+```sql
+alter table schema_name.my_model change column id set not null;
+alter table schema_name.my_model add constraint 472394792387497234 check (id > 0);
+```
+
+
+
+
\ No newline at end of file
diff --git a/website/sidebars.js b/website/sidebars.js
index 28172be026a..36108a209a7 100644
--- a/website/sidebars.js
+++ b/website/sidebars.js
@@ -317,6 +317,15 @@ const sidebarSettings = {
"docs/collaborate/manage-access/audit-log",
],
}, // Manage access
+ {
+ type: "category",
+ label: "Publishing models",
+ items: [
+ "docs/collaborate/publish/model-contracts",
+ "docs/collaborate/publish/model-access",
+ "docs/collaborate/publish/model-versions",
+ ],
+ }, // publishing models
],
},
{
@@ -434,6 +443,7 @@ const sidebarSettings = {
items: [
"reference/resource-properties/columns",
"reference/resource-properties/config",
+ "reference/resource-properties/constraints",
"reference/resource-properties/description",
"reference/resource-properties/quote",
"reference/resource-properties/tests",
@@ -447,6 +457,7 @@ const sidebarSettings = {
"reference/resource-configs/database",
"reference/resource-configs/enabled",
"reference/resource-configs/full_refresh",
+ "reference/resource-configs/contract",
"reference/resource-configs/grants",
"reference/resource-configs/docs",
"reference/resource-configs/persist_docs",