From 6704c711d66e9bf8d50ed4f642a3321c5b5f7d1b Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Fri, 5 May 2023 15:48:11 -0400 Subject: [PATCH 1/4] testing --- dev-requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 7d6994a6c..410ee1c2e 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,7 +1,7 @@ # install latest changes in dbt-core # TODO: how to automate switching from develop to version branches? -git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core -git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter +git+https://github.com/dbt-labs/dbt-core.git@fix-constraint-rendering#egg=dbt-core&subdirectory=core +git+https://github.com/dbt-labs/dbt-core.git@fix-constraint-rendering#egg=dbt-tests-adapter&subdirectory=tests/adapter # if version 1.x or greater -> pin to major version # if version 0.x -> pin to minor From 4f32975fdf14b48f41cca68e0a38441f1ec87de2 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 11 May 2023 14:29:52 -0400 Subject: [PATCH 2/4] test foreign key --- tests/functional/adapter/test_constraints.py | 31 ++++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/tests/functional/adapter/test_constraints.py b/tests/functional/adapter/test_constraints.py index 6b6189092..58a6f03cc 100644 --- a/tests/functional/adapter/test_constraints.py +++ b/tests/functional/adapter/test_constraints.py @@ -20,11 +20,15 @@ my_model_incremental_wrong_name_sql, model_schema_yml, constrained_model_schema_yml, + model_fk_constraint_schema_yml, + my_model_wrong_order_depends_on_fk_sql, + foreign_key_model_sql, + my_model_incremental_wrong_order_depends_on_fk_sql, ) _expected_sql_bigquery = """ create or replace table ( - id integer not null primary key not enforced, + id integer not null primary key not enforced references (id) not enforced, color string, date_day string ) @@ -34,6 +38,7 @@ color, date_day from ( + -- depends_on: select 'blue' as color, 1 as id, '2019-01-01' as date_day @@ -45,6 +50,8 @@ # - does not support a data type named 'text' (TODO handle this via type translation/aliasing!) constraints_yml = model_schema_yml.replace("text", "string") model_constraints_yml = constrained_model_schema_yml.replace("text", "string") +model_fk_constraint_schema_yml = model_fk_constraint_schema_yml.replace("text", "string") +constrained_model_schema_yml = constrained_model_schema_yml.replace("text", "string") class BigQueryColumnEqualSetup: @@ -117,8 +124,9 @@ class TestBigQueryTableConstraintsRuntimeDdlEnforcement(BaseConstraintsRuntimeDd @pytest.fixture(scope="class") def models(self): return { - "my_model.sql": my_model_wrong_order_sql, - "constraints_schema.yml": constraints_yml, + "my_model.sql": my_model_wrong_order_depends_on_fk_sql, + "foreign_key_model.sql": foreign_key_model_sql, + "constraints_schema.yml": model_fk_constraint_schema_yml, } @pytest.fixture(scope="class") @@ -145,8 +153,9 @@ class TestBigQueryIncrementalConstraintsRuntimeDdlEnforcement( @pytest.fixture(scope="class") def models(self): return { - "my_model.sql": my_model_incremental_wrong_order_sql, - "constraints_schema.yml": constraints_yml, + "my_model.sql": my_model_incremental_wrong_order_depends_on_fk_sql, + "foreign_key_model.sql": foreign_key_model_sql, + "constraints_schema.yml": model_fk_constraint_schema_yml, } @pytest.fixture(scope="class") @@ -171,8 +180,9 @@ class TestBigQueryModelConstraintsRuntimeEnforcement(BaseModelConstraintsRuntime @pytest.fixture(scope="class") def models(self): return { - "my_model.sql": my_incremental_model_sql, - "constraints_schema.yml": model_constraints_yml, + "my_model.sql": my_model_wrong_order_depends_on_fk_sql, + "foreign_key_model.sql": foreign_key_model_sql, + "constraints_schema.yml": constrained_model_schema_yml, } @pytest.fixture(scope="class") @@ -182,7 +192,8 @@ def expected_sql(self): id integer not null, color string, date_day string, - primary key (id) not enforced + primary key (id) not enforced, + foreign key (id) references (id) not enforced ) OPTIONS() as ( @@ -190,8 +201,10 @@ def expected_sql(self): color, date_day from ( - select 1 as id, + -- depends_on: + select 'blue' as color, + 1 as id, '2019-01-01' as date_day ) as model_subq ); From 91c2262ce0f3707bcc39f53f0ab290e4655df1f4 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 11 May 2023 14:32:26 -0400 Subject: [PATCH 3/4] changelog entry --- .changes/unreleased/Fixes-20230511-143217.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20230511-143217.yaml diff --git a/.changes/unreleased/Fixes-20230511-143217.yaml b/.changes/unreleased/Fixes-20230511-143217.yaml new file mode 100644 index 000000000..ff56ce5d8 --- /dev/null +++ b/.changes/unreleased/Fixes-20230511-143217.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: test foreign key constraint rendering +time: 2023-05-11T14:32:17.364819-04:00 +custom: + Author: michelleark + Issue: "7512" From 8f84f702bdf123ed5e9534760473d48ce8c0c2dc Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Fri, 2 Jun 2023 15:16:32 -0400 Subject: [PATCH 4/4] revert dev-requirements.txt changes --- dev-requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 010d490fc..0d914bd7e 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,7 +1,7 @@ # install latest changes in dbt-core # TODO: how to automate switching from develop to version branches? -git+https://github.com/dbt-labs/dbt-core.git@fix-constraint-rendering#egg=dbt-core&subdirectory=core -git+https://github.com/dbt-labs/dbt-core.git@fix-constraint-rendering#egg=dbt-tests-adapter&subdirectory=tests/adapter +git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core +git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter # if version 1.x or greater -> pin to major version # if version 0.x -> pin to minor