Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add column fix for snapshots and incremental mats #188

Merged
merged 6 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@ jobs:
- run:
name: az logout
command: az logout
- run:
name: cnxn -- Azure SQL - AZ SP auto
command: |
export AZURE_CLIENT_ID="$DBT_AZURE_SP_NAME"
export AZURE_CLIENT_SECRET="$DBT_AZURE_SECRET"
export AZURE_TENANT_ID="$DBT_AZURE_TENANT"
cd test/integration
dbt compile --target azuresql_azauto
- run:
name: cnxn -- Azure SQL - AZ SP env
command: |
cd test/integration
dbt compile --target azuresql_azenv
# - run:
# name: cnxn -- Azure SQL - AZ SP auto
# command: |
# export AZURE_CLIENT_ID="$DBT_AZURE_SP_NAME"
# export AZURE_CLIENT_SECRET="$DBT_AZURE_SECRET"
# export AZURE_TENANT_ID="$DBT_AZURE_TENANT"
# cd test/integration
# dbt compile --target azuresql_azauto
# - run:
# name: cnxn -- Azure SQL - AZ SP env
# command: |
# cd test/integration
# dbt compile --target azuresql_azenv
Comment on lines +120 to +132
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disabled until #189 is resolved


workflows:
main:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- 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)

#### fixes

- 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)

### v0.21.0

Please see [dbt-core v0.21.0 release notes](https://github.com/dbt-labs/dbt-core/releases/tag/v0.21.0) for upstream changes
Expand Down
29 changes: 29 additions & 0 deletions dbt/include/sqlserver/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,35 @@
{{ return(result) }}
{%- endmacro %}

{% macro default__alter_relation_add_remove_columns(relation, add_columns, remove_columns) %}
{# default__ macro uses "add column"
TSQL preferes just "add"
#}
{% if add_columns is none %}
{% set add_columns = [] %}
{% endif %}
{% if remove_columns is none %}
{% set remove_columns = [] %}
{% endif %}

{% set sql -%}

alter {{ relation.type }} {{ relation }}

{% for column in add_columns %}
add {{ column.name }} {{ column.data_type }}{{ ',' if not loop.last }}
{% endfor %}{{ ',' if add_columns and remove_columns }}

{% for column in remove_columns %}
drop column {{ column.name }}{{ ',' if not loop.last }}
{% endfor %}

{%- endset -%}

{% do run_query(sql) %}

{% endmacro %}

{% macro sqlserver__alter_column_type(relation, column_name, new_column_type) %}

{%- set tmp_column = column_name + "__dbt_alter" -%}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{% macro sqlserver__post_snapshot(staging_relation) %}
-- Clean up the snapshot temp table
{% do drop_relation(staging_relation) %}
{% endmacro %}

{% macro sqlserver__create_columns(relation, columns) %}
{# default__ macro uses "add column"
TSQL preferes just "add"
#}
{% for column in columns %}
{% call statement() %}
alter table {{ relation }} add "{{ column.name }}" {{ column.data_type }};
{% endcall %}
{% endfor %}
{% endmacro %}
2 changes: 1 addition & 1 deletion test/integration/azuresql.dbtspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ projects:
sequences:
test_dbt_empty: empty
test_dbt_base: base
test_dbt_ephemeral: ephemeral
# test_dbt_ephemeral: ephemeral
test_dbt_incremental: incremental
test_dbt_snapshot_strategy_timestamp: snapshot_strategy_timestamp
test_dbt_snapshot_strategy_check_cols: snapshot_strategy_check_cols
Expand Down