diff --git a/dbt_project.yml b/dbt_project.yml index a32fb9f..a6c708c 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -1,6 +1,6 @@ name: 'dbt_constraints' -version: '1.0.0' +version: '1.0.1' config-version: 2 # These macros depend on the results and graph objects in dbt >=0.19.0 diff --git a/macros/create_constraints.sql b/macros/create_constraints.sql index 2b029ce..674cf94 100644 --- a/macros/create_constraints.sql +++ b/macros/create_constraints.sql @@ -177,7 +177,7 @@ {%- if test_model.unique_id in selected_resources -%} {{ return("TEST_SELECTED") }} {%- endif -%} - {%- if lists_intersect(test_model.depends_on.nodes, selected_resources) -%} + {%- if dbt_constraints.lists_intersect(test_model.depends_on.nodes, selected_resources) -%} {{ return("MODEL_SELECTED") }} {%- endif -%} @@ -196,9 +196,9 @@ {%- for fk_model in graph.nodes.values() | selectattr("resource_type", "equalto", "test") if fk_model.test_metadata and fk_model.test_metadata.name in ("foreign_key", "relationships") - and lists_intersect(test_model.depends_on.nodes, fk_model.depends_on.nodes) + and dbt_constraints.lists_intersect(test_model.depends_on.nodes, fk_model.depends_on.nodes) and ( fk_model.unique_id in selected_resources - or lists_intersect(fk_model.depends_on.nodes, selected_resources) ) -%} + or dbt_constraints.lists_intersect(fk_model.depends_on.nodes, selected_resources) ) -%} {%- set fk_test_args = fk_model.test_metadata.kwargs -%} {%- set fk_test_columns = [] -%} {%- if fk_test_args.pk_column_names -%} @@ -270,13 +270,13 @@ {%- set test_parameters = test_model.test_metadata.kwargs -%} {%- set test_name = test_model.test_metadata.name -%} - {%- set selected = test_selected(test_model) -%} + {%- set selected = dbt_constraints.test_selected(test_model) -%} {#- We can shortcut additional tests if the constraint was not selected -#} {%- if selected is not none -%} {#- rely_clause clause will be RELY if a test passed, NORELY if it failed, and '' if it was skipped -#} - {%- set rely_clause = lookup_should_rely(test_model) -%} - {%- set always_create_constraint = should_always_create_constraint(test_model) -%} + {%- set rely_clause = dbt_constraints.lookup_should_rely(test_model) -%} + {%- set always_create_constraint = dbt_constraints.should_always_create_constraint(test_model) -%} {%- else -%} {%- set rely_clause = '' -%} {%- set always_create_constraint = false -%} diff --git a/macros/snowflake__create_constraints.sql b/macros/snowflake__create_constraints.sql index 35ed439..cc32956 100644 --- a/macros/snowflake__create_constraints.sql +++ b/macros/snowflake__create_constraints.sql @@ -22,7 +22,7 @@ {#- Check that the table does not already have this PK/UK -#} {%- set existing_constraint = dbt_constraints.unique_constraint_exists(table_relation, column_names, lookup_cache) -%} {%- if constraint_name == existing_constraint -%} - {%- do set_rely_norely(table_relation, constraint_name, lookup_cache.unique_keys[table_relation][constraint_name].rely, rely_clause) -%} + {%- do dbt_constraints.set_rely_norely(table_relation, constraint_name, lookup_cache.unique_keys[table_relation][constraint_name].rely, rely_clause) -%} {%- do lookup_cache.unique_keys.update({table_relation: {constraint_name: { "constraint_name": constraint_name, "columns": column_names, @@ -63,7 +63,7 @@ {#- Check that the table does not already have this PK/UK -#} {%- set existing_constraint = dbt_constraints.unique_constraint_exists(table_relation, column_names, lookup_cache) -%} {%- if constraint_name == existing_constraint -%} - {%- do set_rely_norely(table_relation, constraint_name, lookup_cache.unique_keys[table_relation][constraint_name].rely, rely_clause) -%} + {%- do dbt_constraints.set_rely_norely(table_relation, constraint_name, lookup_cache.unique_keys[table_relation][constraint_name].rely, rely_clause) -%} {%- do lookup_cache.unique_keys.update({table_relation: {constraint_name: { "constraint_name": constraint_name, "columns": column_names, @@ -107,7 +107,7 @@ {#- Check if the table already has this foreign key -#} {%- set existing_constraint = dbt_constraints.foreign_key_exists(fk_table_relation, fk_column_names, lookup_cache) -%} {%- if constraint_name == existing_constraint -%} - {%- do set_rely_norely(fk_table_relation, constraint_name, lookup_cache.foreign_keys[fk_table_relation][constraint_name].rely, rely_clause) -%} + {%- do dbt_constraints.set_rely_norely(fk_table_relation, constraint_name, lookup_cache.foreign_keys[fk_table_relation][constraint_name].rely, rely_clause) -%} {%- do lookup_cache.foreign_keys.update({fk_table_relation: {constraint_name: {"constraint_name": constraint_name, "columns": fk_column_names,