Skip to content

Commit

Permalink
adding create columns for three DBs
Browse files Browse the repository at this point in the history
  • Loading branch information
outinim committed Apr 7, 2024
1 parent e1aa8c2 commit 021e256
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.

This file was deleted.

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 Expand Up @@ -59,7 +70,7 @@
| rejectattr('name', 'equalto', 'DBT_UNIQUE_KEY')
| list %}

{% do create_columns(target_relation, missing_columns) %}
{% do mariadb__create_columns(target_relation, missing_columns) %}

{% set source_columns = adapter.get_columns_in_relation(staging_table)
| rejectattr('name', 'equalto', 'dbt_change_type')
Expand Down
13 changes: 12 additions & 1 deletion 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 Expand Up @@ -59,7 +70,7 @@
| rejectattr('name', 'equalto', 'DBT_UNIQUE_KEY')
| list %}

{% do create_columns(target_relation, missing_columns) %}
{% do mysql__create_columns(target_relation, missing_columns) %}

{% set source_columns = adapter.get_columns_in_relation(staging_table)
| rejectattr('name', 'equalto', 'dbt_change_type')
Expand Down
13 changes: 12 additions & 1 deletion 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 Expand Up @@ -59,7 +70,7 @@
| rejectattr('name', 'equalto', 'DBT_UNIQUE_KEY')
| list %}

{% do create_columns(target_relation, missing_columns) %}
{% do mysql5__create_columns(target_relation, missing_columns) %}

{% set source_columns = adapter.get_columns_in_relation(staging_table)
| rejectattr('name', 'equalto', 'dbt_change_type')
Expand Down

0 comments on commit 021e256

Please sign in to comment.