Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit d69a12f

Browse files
authored
Allow configuring snapshot table column names (#145)
1 parent a676c4e commit d69a12f

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Features
2+
body: Allow configuring snapshot column names
3+
time: 2024-09-03T16:02:21.069085-04:00
4+
custom:
5+
Author: gshank
6+
Issue: "144"

dbt/include/postgres/macros/materializations/snapshot_merge.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
{% macro postgres__snapshot_merge_sql(target, source, insert_cols) -%}
33
{%- set insert_cols_csv = insert_cols | join(', ') -%}
44

5+
{%- set columns = config.get("snapshot_table_column_names") or get_snapshot_table_column_names() -%}
6+
57
update {{ target }}
6-
set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to
8+
set {{ columns.dbt_valid_to }} = DBT_INTERNAL_SOURCE.{{ columns.dbt_valid_to }}
79
from {{ source }} as DBT_INTERNAL_SOURCE
8-
where DBT_INTERNAL_SOURCE.dbt_scd_id::text = {{ target }}.dbt_scd_id::text
10+
where DBT_INTERNAL_SOURCE.{{ columns.dbt_scd_id }}::text = {{ target }}.{{ columns.dbt_scd_id }}::text
911
and DBT_INTERNAL_SOURCE.dbt_change_type::text in ('update'::text, 'delete'::text)
10-
and {{ target }}.dbt_valid_to is null;
12+
and {{ target }}.{{ columns.dbt_valid_to }} is null;
1113

1214
insert into {{ target }} ({{ insert_cols_csv }})
1315
select {% for column in insert_cols -%}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ classifiers = [
2525
]
2626
dependencies = [
2727
"psycopg2-binary>=2.9,<3.0",
28-
"dbt-adapters>=1.1.1,<2.0",
28+
"dbt-adapters>=1.7.0,<2.0",
2929
# add dbt-core to ensure backwards compatibility of installation, this is not a functional dependency
3030
"dbt-core>=1.8.0",
3131
# installed via dbt-adapters but used directly

0 commit comments

Comments
 (0)