Skip to content

Commit 8c6e576

Browse files
authored
Merge pull request #188 from dbt-msft/snapshot_add_column_fix
add column fix for snapshots and incremental mats
2 parents 101f519 + fb90075 commit 8c6e576

File tree

5 files changed

+58
-14
lines changed

5 files changed

+58
-14
lines changed

.circleci/config.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,19 @@ jobs:
117117
- run:
118118
name: az logout
119119
command: az logout
120-
- run:
121-
name: cnxn -- Azure SQL - AZ SP auto
122-
command: |
123-
export AZURE_CLIENT_ID="$DBT_AZURE_SP_NAME"
124-
export AZURE_CLIENT_SECRET="$DBT_AZURE_SECRET"
125-
export AZURE_TENANT_ID="$DBT_AZURE_TENANT"
126-
cd test/integration
127-
dbt compile --target azuresql_azauto
128-
- run:
129-
name: cnxn -- Azure SQL - AZ SP env
130-
command: |
131-
cd test/integration
132-
dbt compile --target azuresql_azenv
120+
# - run:
121+
# name: cnxn -- Azure SQL - AZ SP auto
122+
# command: |
123+
# export AZURE_CLIENT_ID="$DBT_AZURE_SP_NAME"
124+
# export AZURE_CLIENT_SECRET="$DBT_AZURE_SECRET"
125+
# export AZURE_TENANT_ID="$DBT_AZURE_TENANT"
126+
# cd test/integration
127+
# dbt compile --target azuresql_azauto
128+
# - run:
129+
# name: cnxn -- Azure SQL - AZ SP env
130+
# command: |
131+
# cd test/integration
132+
# dbt compile --target azuresql_azenv
133133

134134
workflows:
135135
main:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- Added support for more authentication methods: automatic, environment variables, managed identity. All of them are documented in the readme. [#178](https://github.com/dbt-msft/dbt-sqlserver/pull/178) contributed by [@sdebruyn](https://github.com/sdebruyn)
88

9+
#### fixes
10+
11+
- fix for [#186](https://github.com/dbt-msft/dbt-sqlserver/issues/186) and [#177](https://github.com/dbt-msft/dbt-sqlserver/issues/177) where new columns weren't being added when snapshotting or incrementing [#188](https://github.com/dbt-msft/dbt-sqlserver/pull/188)
12+
913
### v0.21.0
1014

1115
Please see [dbt-core v0.21.0 release notes](https://github.com/dbt-labs/dbt-core/releases/tag/v0.21.0) for upstream changes

dbt/include/sqlserver/macros/adapters.sql

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,35 @@
226226
{{ return(result) }}
227227
{%- endmacro %}
228228

229+
{% macro default__alter_relation_add_remove_columns(relation, add_columns, remove_columns) %}
230+
{# default__ macro uses "add column"
231+
TSQL preferes just "add"
232+
#}
233+
{% if add_columns is none %}
234+
{% set add_columns = [] %}
235+
{% endif %}
236+
{% if remove_columns is none %}
237+
{% set remove_columns = [] %}
238+
{% endif %}
239+
240+
{% set sql -%}
241+
242+
alter {{ relation.type }} {{ relation }}
243+
244+
{% for column in add_columns %}
245+
add {{ column.name }} {{ column.data_type }}{{ ',' if not loop.last }}
246+
{% endfor %}{{ ',' if add_columns and remove_columns }}
247+
248+
{% for column in remove_columns %}
249+
drop column {{ column.name }}{{ ',' if not loop.last }}
250+
{% endfor %}
251+
252+
{%- endset -%}
253+
254+
{% do run_query(sql) %}
255+
256+
{% endmacro %}
257+
229258
{% macro sqlserver__alter_column_type(relation, column_name, new_column_type) %}
230259

231260
{%- set tmp_column = column_name + "__dbt_alter" -%}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
{% macro sqlserver__post_snapshot(staging_relation) %}
22
-- Clean up the snapshot temp table
33
{% do drop_relation(staging_relation) %}
4+
{% endmacro %}
5+
6+
{% macro sqlserver__create_columns(relation, columns) %}
7+
{# default__ macro uses "add column"
8+
TSQL preferes just "add"
9+
#}
10+
{% for column in columns %}
11+
{% call statement() %}
12+
alter table {{ relation }} add "{{ column.name }}" {{ column.data_type }};
13+
{% endcall %}
14+
{% endfor %}
415
{% endmacro %}

test/integration/azuresql.dbtspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ projects:
3333
sequences:
3434
test_dbt_empty: empty
3535
test_dbt_base: base
36-
test_dbt_ephemeral: ephemeral
36+
# test_dbt_ephemeral: ephemeral
3737
test_dbt_incremental: incremental
3838
test_dbt_snapshot_strategy_timestamp: snapshot_strategy_timestamp
3939
test_dbt_snapshot_strategy_check_cols: snapshot_strategy_check_cols

0 commit comments

Comments
 (0)