Skip to content

Commit

Permalink
Feature/drop relation/ct 2581 (dbt-labs#7626)
Browse files Browse the repository at this point in the history
* changie
* move drop_relation macros into their own file, add scenarios for table, view, and materialized view
  • Loading branch information
mikealfare authored May 15, 2023
1 parent 8f998c2 commit 47e7b1c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20230515-122304.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: Update drop_relation macro to allow for configuration of drop statement separately
from object name
time: 2023-05-15T12:23:04.177141-04:00
custom:
Author: mikealfare
Issue: "7625"
44 changes: 44 additions & 0 deletions core/dbt/include/global_project/macros/adapters/drop_relation.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% macro drop_relation(relation) -%}
{{ return(adapter.dispatch('drop_relation', 'dbt')(relation)) }}
{% endmacro %}

{% macro default__drop_relation(relation) -%}
{% call statement('drop_relation', auto_begin=False) -%}
{%- if relation.is_table -%}
{{- drop_table(relation) -}}
{%- elif relation.is_view -%}
{{- drop_view(relation) -}}
{%- elif relation.is_materialized_view -%}
{{- drop_materialized_view(relation) -}}
{%- else -%}
drop {{ relation.type }} if exists {{ relation }} cascade
{%- endif -%}
{%- endcall %}
{% endmacro %}


{% macro drop_table(relation) -%}
{{ return(adapter.dispatch('drop_table', 'dbt')(relation)) }}
{%- endmacro %}

{% macro default__drop_table(relation) -%}
drop table if exists {{ relation }} cascade
{%- endmacro %}


{% macro drop_view(relation) -%}
{{ return(adapter.dispatch('drop_view', 'dbt')(relation)) }}
{%- endmacro %}

{% macro default__drop_view(relation) -%}
drop view if exists {{ relation }} cascade
{%- endmacro %}


{% macro drop_materialized_view(relation) -%}
{{ return(adapter.dispatch('drop_materialized_view', 'dbt')(relation)) }}
{%- endmacro %}

{% macro default__drop_materialized_view(relation) -%}
drop materialized view if exists {{ relation }} cascade
{%- endmacro %}
10 changes: 0 additions & 10 deletions core/dbt/include/global_project/macros/adapters/relation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@
{{ return(backup_relation) }}
{% endmacro %}

{% macro drop_relation(relation) -%}
{{ return(adapter.dispatch('drop_relation', 'dbt')(relation)) }}
{% endmacro %}

{% macro default__drop_relation(relation) -%}
{% call statement('drop_relation', auto_begin=False) -%}
drop {{ relation.type }} if exists {{ relation }} cascade
{%- endcall %}
{% endmacro %}


{% macro truncate_relation(relation) -%}
{{ return(adapter.dispatch('truncate_relation', 'dbt')(relation)) }}
Expand Down

0 comments on commit 47e7b1c

Please sign in to comment.