diff --git a/.changes/unreleased/Features-20230223-182450.yaml b/.changes/unreleased/Features-20230223-182450.yaml index 45c0efe71..9d4446888 100644 --- a/.changes/unreleased/Features-20230223-182450.yaml +++ b/.changes/unreleased/Features-20230223-182450.yaml @@ -1,6 +1,6 @@ kind: Features -body: implement data_type_code_to_name on SnowflakeConnectionManager +body: Enforce contracts on models materialized as tables and views time: 2023-02-23T18:24:50.272955-05:00 custom: - Author: michelleark - Issue: "464" + Author: michelleark emmyoop + Issue: 464 490 diff --git a/dbt/include/snowflake/macros/adapters.sql b/dbt/include/snowflake/macros/adapters.sql index a8dd34dc2..daff74714 100644 --- a/dbt/include/snowflake/macros/adapters.sql +++ b/dbt/include/snowflake/macros/adapters.sql @@ -94,6 +94,9 @@ {{ get_persist_docs_column_list(model_columns, query_columns) }} {%- endif %} + {% if config.get('contract', False) -%} + {{ get_assert_columns_equivalent(sql) }} + {%- endif %} {% if copy_grants -%} copy grants {%- endif %} as ( {{ sql }} ); diff --git a/tests/functional/adapter/test_constraints.py b/tests/functional/adapter/test_constraints.py index 8e2607f76..fd1f41847 100644 --- a/tests/functional/adapter/test_constraints.py +++ b/tests/functional/adapter/test_constraints.py @@ -2,7 +2,8 @@ from dbt.tests.util import relation_from_name from dbt.tests.adapter.constraints.test_constraints import ( - BaseConstraintsColumnsEqual, + BaseTableConstraintsColumnsEqual, + BaseViewConstraintsColumnsEqual, BaseConstraintsRuntimeEnforcement ) @@ -21,8 +22,7 @@ """ -class TestSnowflakeConstraintsColumnsEqual(BaseConstraintsColumnsEqual): - +class SnowflakeColumnEqualSetup: @pytest.fixture def int_type(self): return "FIXED" @@ -46,6 +46,13 @@ def data_types(self, int_type, schema_int_type, string_type): ["""TO_VARIANT(PARSE_JSON('{"key3": "value3", "key4": "value4"}'))""", 'variant', 'VARIANT'], ] +class TestSnowflakeTableConstraintsColumnsEqual(SnowflakeColumnEqualSetup, BaseTableConstraintsColumnsEqual): + pass + + +class TestSnowflakeViewConstraintsColumnsEqual(SnowflakeColumnEqualSetup, BaseViewConstraintsColumnsEqual): + pass + class TestSnowflakeConstraintsRuntimeEnforcement(BaseConstraintsRuntimeEnforcement):