Skip to content

Commit 1e319ba

Browse files
Merge pull request #93 from Snowflake-Labs/83-foreign-key-constraint-skips-execution-due-to-deferred-job-metadata-with-different-targetname
Change PK model to use config.database when it is not in the selected…
2 parents d6f6810 + 8f96bc3 commit 1e319ba

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

macros/create_constraints.sql

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,17 @@
390390
schema=fk_model.schema,
391391
identifier=fk_model.alias) -%}
392392

393-
{%- set pk_table_relation = adapter.get_relation(
394-
database=pk_model.database,
395-
schema=pk_model.schema,
396-
identifier=pk_model.alias) -%}
393+
{%- if pk_model.unique_id not in selected_resources -%}
394+
{%- set pk_table_relation = adapter.get_relation(
395+
database=(pk_model.config.database or pk_model.database),
396+
schema=(pk_model.config.schema or pk_model.schema),
397+
identifier=(pk_model.config.alias or pk_model.alias)) -%}
398+
{%- else -%}
399+
{%- set pk_table_relation = adapter.get_relation(
400+
database=pk_model.database,
401+
schema=pk_model.schema,
402+
identifier=pk_model.alias) -%}
403+
{%- endif -%}
397404

398405
{%- if fk_table_relation and pk_table_relation and fk_table_relation.is_table and pk_table_relation.is_table-%}
399406
{# Attempt to identify parameters we can use for the column names #}

0 commit comments

Comments
 (0)