Skip to content

Commit

Permalink
Add drop_schema_named macro (#8868)
Browse files Browse the repository at this point in the history
* add drop_schema_named

* give drop_schema_named a default
  • Loading branch information
colin-rogers-dbt authored Nov 8, 2023
1 parent 931b2db commit 6871fc4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20231017-143620.yaml
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"
8 changes: 8 additions & 0 deletions core/dbt/include/global_project/macros/relations/schema.sql
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 %}
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

0 comments on commit 6871fc4

Please sign in to comment.