Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cascade to drop mv #904

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20240906-102642.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: Support DROP CASCADE for materialized views; fixes bug that occurs when running
dbt on materialized views that reference other materialized views
time: 2024-09-06T10:26:42.501014-04:00
custom:
Author: mikealfare
Issue: "642"
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% macro redshift__drop_materialized_view(relation) -%}
drop materialized view if exists {{ relation }}
drop materialized view if exists {{ relation }} cascade
{%- endmacro %}
1 change: 1 addition & 0 deletions tests/functional/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# provides namespacing for test discovery
1 change: 1 addition & 0 deletions tests/functional/adapter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# provides namespacing for test discovery
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# provides namespacing for test discovery
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
This test addresses this bug: https://github.com/dbt-labs/dbt-redshift/issues/642

Redshift did not initially support DROP CASCADE for materialized views,
or at least did not document that they did. Now that they do, we should
use DROP CASCADE instead of DROP.
"""

from dbt.tests.util import run_dbt
import pytest


SEED = """
id
1
""".strip()


PARENT_MATERIALIZED_VIEW = """
{{ config(
materialized='materialized_view',
on_configuration_change='apply',
) }}

select * from {{ ref('my_seed') }}
"""


CHILD_MATERIALIZED_VIEW = """
{{ config(
materialized='materialized_view',
on_configuration_change='apply',
) }}

select * from {{ ref('parent_mv') }}
"""


@pytest.fixture(scope="class")
def seeds():
return {"my_seed.csv": SEED}


@pytest.fixture(scope="class")
def models():
return {
"parent_mv.sql": PARENT_MATERIALIZED_VIEW,
"child_mv.sql": CHILD_MATERIALIZED_VIEW,
}


def test_drop_cascade(project):
run_dbt(["seed"])
run_dbt(["run"])
# this originally raised an error when it should not have
run_dbt(["run", "--full-refresh"])
Loading