Skip to content

Commit

Permalink
fix: snapshots failing because of wrong mysql colum quoting (#171)
Browse files Browse the repository at this point in the history
* fix: snapshots failing because of wrong mysql colum quoting

* adding create columns for three DBs

* update changelogs

* Fix create_columns macro invocation to be more general.

---------

Co-authored-by: Matthew Wallace <[email protected]>
  • Loading branch information
outinim and mwallace582 authored May 27, 2024
1 parent ddac484 commit e609d4d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Support dbt v1.5 ([#145](https://github.com/dbeatty10/dbt-mysql/issues/145))
- Support connecting via UNIX sockets ([#164](https://github.com/dbeatty10/dbt-mysql/issues/164))
- Support Black & MyPy pre-commit hooks ([#138](https://github.com/dbeatty10/dbt-mysql/issues/138))
- Support dbt snapshots if table DDL is evolving ([#171](https://github.com/dbeatty10/dbt-mysql/pull/171))

### Fixes
- Fix incremental composite keys ([#144](https://github.com/dbeatty10/dbt-mysql/issues/144))
Expand Down
11 changes: 11 additions & 0 deletions dbt/include/mariadb/macros/materializations/snapshot/snapshot.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{#
Add new columns to the table if applicable
#}

{% macro mariadb__create_columns(relation, columns) %}
{% for column in columns %}
{% call statement() %}
alter table {{ relation }} add column {{ column.quoted() }} {{ column.data_type }};
{% endcall %}
{% endfor %}
{% endmacro %}

{% macro mariadb__snapshot_string_as_time(timestamp) -%}
{%- set result = "str_to_date('" ~ timestamp ~ "', '%Y-%m-%d %T')" -%}
Expand Down
11 changes: 11 additions & 0 deletions dbt/include/mysql/macros/materializations/snapshot/snapshot.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{#
Add new columns to the table if applicable
#}

{% macro mysql__create_columns(relation, columns) %}
{% for column in columns %}
{% call statement() %}
alter table {{ relation }} add column {{ column.quoted() }} {{ column.data_type }};
{% endcall %}
{% endfor %}
{% endmacro %}

{% macro mysql__snapshot_string_as_time(timestamp) -%}
{%- set result = "str_to_date('" ~ timestamp ~ "', '%Y-%m-%d %T')" -%}
Expand Down
11 changes: 11 additions & 0 deletions dbt/include/mysql5/macros/materializations/snapshot/snapshot.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{#
Add new columns to the table if applicable
#}

{% macro mysql5__create_columns(relation, columns) %}
{% for column in columns %}
{% call statement() %}
alter table {{ relation }} add column {{ column.quoted() }} {{ column.data_type }};
{% endcall %}
{% endfor %}
{% endmacro %}

{% macro mysql5__snapshot_string_as_time(timestamp) -%}
{%- set result = "str_to_date('" ~ timestamp ~ "', '%Y-%m-%d %T')" -%}
Expand Down

0 comments on commit e609d4d

Please sign in to comment.