From 5f33c1f9a6e88d86dcb653086d26793b62089562 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Wed, 25 Sep 2024 12:05:11 -0400 Subject: [PATCH 1/4] Update to use dbt_valid_to_current_date --- .../postgres/macros/materializations/snapshot_merge.sql | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dbt/include/postgres/macros/materializations/snapshot_merge.sql b/dbt/include/postgres/macros/materializations/snapshot_merge.sql index 894ea4b..c2c01c7 100644 --- a/dbt/include/postgres/macros/materializations/snapshot_merge.sql +++ b/dbt/include/postgres/macros/materializations/snapshot_merge.sql @@ -9,7 +9,12 @@ from {{ source }} as DBT_INTERNAL_SOURCE where DBT_INTERNAL_SOURCE.{{ columns.dbt_scd_id }}::text = {{ target }}.{{ columns.dbt_scd_id }}::text and DBT_INTERNAL_SOURCE.dbt_change_type::text in ('update'::text, 'delete'::text) - and {{ target }}.{{ columns.dbt_valid_to }} is null; + {% if config.get("dbt_valid_to_current_date") %} + and {{ target }}.{{ columns.dbt_valid_to }} = {{ config.get('dbt_valid_to_current_date') }}; + {% else %} + and {{ target }}.{{ columns.dbt_valid_to }} is null; + {% endif %} + insert into {{ target }} ({{ insert_cols_csv }}) select {% for column in insert_cols -%} From a684080d41e8fa285a6a7c98a7f42a7e20b13461 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Wed, 25 Sep 2024 18:19:30 -0400 Subject: [PATCH 2/4] Change name of config field --- .../postgres/macros/materializations/snapshot_merge.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt/include/postgres/macros/materializations/snapshot_merge.sql b/dbt/include/postgres/macros/materializations/snapshot_merge.sql index c2c01c7..d59517d 100644 --- a/dbt/include/postgres/macros/materializations/snapshot_merge.sql +++ b/dbt/include/postgres/macros/materializations/snapshot_merge.sql @@ -9,8 +9,8 @@ from {{ source }} as DBT_INTERNAL_SOURCE where DBT_INTERNAL_SOURCE.{{ columns.dbt_scd_id }}::text = {{ target }}.{{ columns.dbt_scd_id }}::text and DBT_INTERNAL_SOURCE.dbt_change_type::text in ('update'::text, 'delete'::text) - {% if config.get("dbt_valid_to_current_date") %} - and {{ target }}.{{ columns.dbt_valid_to }} = {{ config.get('dbt_valid_to_current_date') }}; + {% if config.get("dbt_valid_to_current") %} + and {{ target }}.{{ columns.dbt_valid_to }} = {{ config.get('dbt_valid_to_current') }}; {% else %} and {{ target }}.{{ columns.dbt_valid_to }} is null; {% endif %} From 9defe6b7c6fa754c0d231cf9607fa4ffea7bdf7f Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Fri, 27 Sep 2024 13:27:49 -0400 Subject: [PATCH 3/4] Check both dbt_valid_to_current and null --- dbt/include/postgres/macros/materializations/snapshot_merge.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt/include/postgres/macros/materializations/snapshot_merge.sql b/dbt/include/postgres/macros/materializations/snapshot_merge.sql index d59517d..0b4deb1 100644 --- a/dbt/include/postgres/macros/materializations/snapshot_merge.sql +++ b/dbt/include/postgres/macros/materializations/snapshot_merge.sql @@ -10,7 +10,7 @@ where DBT_INTERNAL_SOURCE.{{ columns.dbt_scd_id }}::text = {{ target }}.{{ columns.dbt_scd_id }}::text and DBT_INTERNAL_SOURCE.dbt_change_type::text in ('update'::text, 'delete'::text) {% if config.get("dbt_valid_to_current") %} - and {{ target }}.{{ columns.dbt_valid_to }} = {{ config.get('dbt_valid_to_current') }}; + and ({{ target }}.{{ columns.dbt_valid_to }} = {{ config.get('dbt_valid_to_current') }} or {{ target }}.{{ columns.dbt_valid_to }} is null); {% else %} and {{ target }}.{{ columns.dbt_valid_to }} is null; {% endif %} From 5463b9ae084abb53ca4c645dc399422719ad8846 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Fri, 27 Sep 2024 13:37:18 -0400 Subject: [PATCH 4/4] Changie --- .changes/unreleased/Features-20240927-133708.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Features-20240927-133708.yaml diff --git a/.changes/unreleased/Features-20240927-133708.yaml b/.changes/unreleased/Features-20240927-133708.yaml new file mode 100644 index 0000000..b2dba33 --- /dev/null +++ b/.changes/unreleased/Features-20240927-133708.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Enable setting current value of dbt_valid_to +time: 2024-09-27T13:37:08.808843-04:00 +custom: + Author: gshank + Issue: "151"