Skip to content

Commit

Permalink
Merge pull request #75 from Snowflake-Labs/Remove-parent-to-child-tra…
Browse files Browse the repository at this point in the history
…versal-for-FK

merge earlier emergency fixes
  • Loading branch information
sfc-gh-dflippo authored Aug 19, 2024
2 parents 682e5ef + b496da7 commit 1a45df7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions macros/create_constraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}
Expand All @@ -300,7 +300,7 @@
{#- Find the table models that are referenced by this test. -#}
{%- for table_node in test_model.depends_on.nodes -%}
{%- for node in graph.nodes.values() | selectattr("unique_id", "equalto", table_node)
if node.config.get("materialized", "other") not in ("view", "ephemeral")
if node.config.get("materialized", "other") not in ("view", "ephemeral", "dynamic_table")
and ( node.resource_type in ("model", "snapshot", "seed")
or ( node.resource_type == "source" and var('dbt_constraints_sources_enabled', false)
and ( ( var('dbt_constraints_sources_pk_enabled', false) and test_name in("primary_key") )
Expand Down
6 changes: 3 additions & 3 deletions macros/snowflake__create_constraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1a45df7

Please sign in to comment.