Skip to content

Commit 4154352

Browse files
committed
Fixed macro oracle__alter_relation_add_remove_columns
1 parent 6891a1f commit 4154352

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

dbt/include/oracle/macros/columns.sql

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,29 @@
2222
{% if remove_columns is none %}
2323
{% set remove_columns = [] %}
2424
{% endif %}
25-
26-
{% set sql -%}
27-
28-
alter {{ relation.type }} {{ relation }}
29-
30-
{% for column in add_columns %}
31-
add {{ column.name }} {{ column.data_type }}{{ ',' if not loop.last }}
32-
{% endfor %}{{ ',' if add_columns and remove_columns }}
33-
34-
{% for column in remove_columns %}
35-
drop column {{ column.name }}{{ ',' if not loop.last }}
36-
{% endfor %}
37-
38-
{%- endset -%}
39-
40-
{% do run_query(sql) %}
25+
{# To avoid ORA-12987: cannot combine drop column with other operations, we execute 2 different SQL for add and drop respectively #}
26+
27+
{% if add_columns|length > 0 %}
28+
{% set add_sql %}
29+
ALTER {{ relation.type }} {{ relation }}
30+
ADD (
31+
{% for column in add_columns %}
32+
{{ column.name }} {{ column.data_type }}{{ ',' if not loop.last }}
33+
{% endfor %}
34+
)
35+
{% endset %}
36+
{% do run_query(add_sql)%}
37+
{% endif %}
38+
39+
{% if remove_columns|length > 0 %}
40+
{% set remove_sql %}
41+
ALTER {{ relation.type }} {{ relation }}
42+
DROP (
43+
{% for column in remove_columns %}
44+
{{ column.name }}{{ ',' if not loop.last }}
45+
{% endfor %}
46+
) CASCADE CONSTRAINTS
47+
{% endset %}
48+
{% do run_query(remove_sql)%}
49+
{% endif %}
4150
{% endmacro %}

dbt_adbs_test_project/models/demo/promotion_costs_for_direct_sales_channel_incr_merge_unique_keys.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{{config(materialized='incremental',
2-
on_schema_change='sync_all_columns',
2+
on_schema_change='append_new_columns',
33
unique_key=['prod_id', 'quantity_sold', 'time_id', 'promo_name'])}}
44
WITH direct_sales_promo_cost AS (
55
SELECT s.prod_id,
66
s.quantity_sold,
77
s.amount_sold,
88
s.time_id,
9+
s.cust_id,
910
c.channel_desc,
1011
p.promo_name,
1112
p.promo_cost

dbt_adbs_test_project/packages.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
packages:
22
- package: dbt-labs/dbt_utils
33
version: 0.8.6
4-
- git: https://github.com/Snowflake-Labs/dbt_constraints.git
5-
revision: dbt-oracle-support
4+
- package: Snowflake-Labs/dbt_constraints
5+
version: [">=0.4.0", "<0.5.0"]

0 commit comments

Comments
 (0)