-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add drop_schema_named * give drop_schema_named a default
- Loading branch information
1 parent
931b2db
commit 6871fc4
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Add drop_schema_named macro | ||
time: 2023-10-17T14:36:20.612289-07:00 | ||
custom: | ||
Author: colin-rogers-dbt | ||
Issue: "8025" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% macro drop_schema_named(schema_name) %} | ||
{{ return(adapter.dispatch('drop_schema_named', 'dbt') (schema_name)) }} | ||
{% endmacro %} | ||
|
||
{% macro default__drop_schema_named(schema_name) %} | ||
{% set schema_relation = api.Relation.create(schema=schema_name) %} | ||
{{ adapter.drop_schema(schema_relation) }} | ||
{% endmacro %} |
35 changes: 35 additions & 0 deletions
35
tests/adapter/dbt/tests/adapter/relations/test_dropping_schema_named.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
|
||
from dbt.tests.util import run_dbt, get_connection | ||
|
||
|
||
class BaseDropSchemaNamed: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"model_a.sql": "select 1 as id", | ||
} | ||
|
||
def test_dropped_schema_named_drops_expected_schema(self, project): | ||
|
||
results = run_dbt(["run"]) | ||
assert len(results) == 1 | ||
|
||
run_dbt( | ||
[ | ||
"run-operation", | ||
"drop_schema_named", | ||
"--args", | ||
f"{{schema_name: {project.test_schema} }}", | ||
] | ||
) | ||
|
||
adapter = project.adapter | ||
with get_connection(adapter): | ||
schemas = adapter.list_schemas(project.database) | ||
|
||
assert project.test_schema not in schemas | ||
|
||
|
||
class TestDropSchemaNamed(BaseDropSchemaNamed): | ||
pass |