diff --git a/CHANGELOG.md b/CHANGELOG.md index 171278a9..8a589a84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v.0.21 + +### Fixes + +- Resolves bug for running incremental models where the macro `alter_column_type` had incorrect syntax + ## v.0.20.0 ### Features diff --git a/dbt/include/synapse/macros/adapters.sql b/dbt/include/synapse/macros/adapters.sql index d46d7c74..07c64150 100644 --- a/dbt/include/synapse/macros/adapters.sql +++ b/dbt/include/synapse/macros/adapters.sql @@ -71,7 +71,7 @@ {# TODO instead of deleting it... #} {% macro synapse__rename_relation(from_relation, to_relation) -%} {% call statement('rename_relation') -%} - + rename object {{ from_relation.include(database=False) }} to {{ to_relation.identifier }} {%- endcall %} {% endmacro %} @@ -158,3 +158,18 @@ {% set table = load_result('get_columns_in_relation').table %} {{ return(sql_convert_columns_in_relation(table)) }} {% endmacro %} + +{% macro synapse__alter_column_type(relation, column_name, new_column_type) %} + + {%- set tmp_column = column_name + "__dbt_alter" -%} + + {% call statement('alter_column_type') -%} + + alter {{ relation.type }} {{ relation }} add {{ tmp_column }} {{ new_column_type }}; + update {{ relation }} set {{ tmp_column }} = {{ column_name }}; + alter {{ relation.type }} {{ relation }} drop column {{ column_name }}; + exec sp_rename '{{ relation | replace('"', '') }}.{{ tmp_column }}', '{{ column_name }}', 'column' + + {%- endcall -%} + +{% endmacro %}