Skip to content

Commit

Permalink
Allow configuring snapshot table column names (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank authored Sep 20, 2024
1 parent a676c4e commit d69a12f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20240903-160221.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Allow configuring snapshot column names
time: 2024-09-03T16:02:21.069085-04:00
custom:
Author: gshank
Issue: "144"
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
{% macro postgres__snapshot_merge_sql(target, source, insert_cols) -%}
{%- set insert_cols_csv = insert_cols | join(', ') -%}

{%- set columns = config.get("snapshot_table_column_names") or get_snapshot_table_column_names() -%}

update {{ target }}
set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to
set {{ columns.dbt_valid_to }} = DBT_INTERNAL_SOURCE.{{ columns.dbt_valid_to }}
from {{ source }} as DBT_INTERNAL_SOURCE
where DBT_INTERNAL_SOURCE.dbt_scd_id::text = {{ target }}.dbt_scd_id::text
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 }}.dbt_valid_to is null;
and {{ target }}.{{ columns.dbt_valid_to }} is null;

insert into {{ target }} ({{ insert_cols_csv }})
select {% for column in insert_cols -%}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ classifiers = [
]
dependencies = [
"psycopg2-binary>=2.9,<3.0",
"dbt-adapters>=1.1.1,<2.0",
"dbt-adapters>=1.7.0,<2.0",
# add dbt-core to ensure backwards compatibility of installation, this is not a functional dependency
"dbt-core>=1.8.0",
# installed via dbt-adapters but used directly
Expand Down

0 comments on commit d69a12f

Please sign in to comment.