diff --git a/.changes/unreleased/Features-20240903-160221.yaml b/.changes/unreleased/Features-20240903-160221.yaml new file mode 100644 index 0000000..8409e24 --- /dev/null +++ b/.changes/unreleased/Features-20240903-160221.yaml @@ -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" diff --git a/dbt/include/postgres/macros/materializations/snapshot_merge.sql b/dbt/include/postgres/macros/materializations/snapshot_merge.sql index 807c70b..894ea4b 100644 --- a/dbt/include/postgres/macros/materializations/snapshot_merge.sql +++ b/dbt/include/postgres/macros/materializations/snapshot_merge.sql @@ -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 -%} diff --git a/pyproject.toml b/pyproject.toml index e6848a4..726dc64 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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