Skip to content

Commit d2cf3e1

Browse files
committed
cleanup macro and add test
1 parent efe1bcb commit d2cf3e1

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

dbt/include/sqlserver/macros/adapters/schema.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{% macro sqlserver__create_schema(relation) -%}
2-
{% auth = config.get("auth") %}
2+
{% auth = config.get("schema_authorization") %}
33
{% call statement('create_schema') -%}
44
USE [{{ relation.database }}];
5-
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = '{{ relation.without_identifier().schema }}')
5+
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = '{{ relation.schema }}')
66
BEGIN
7-
EXEC('CREATE SCHEMA [{{ relation.without_identifier().schema }}] {%- if auth -%} AUTHORIZATION: [{{auth}}]')
7+
EXEC('CREATE SCHEMA [{{ relation.schema }}] {% if schema_authorization %} AUTHORIZATION: [{{ schema_authorization }}] {% endif %}')
88
END
99
{% endcall %}
1010
{% endmacro %}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pytest
2+
from dbt.tests.util import run_dbt
3+
4+
5+
class TestSchemaCreation:
6+
@pytest.fixture(scope="class")
7+
def project_config_update(self):
8+
return {"name": "schema_tests"}
9+
10+
@pytest.fixture(scope="class")
11+
def models(self):
12+
return {
13+
"dummy.sql": "select 1 as id",
14+
"dummy_with_auth.sql": """
15+
{{ config(schema_authorization=env_var('DBT_TEST_USER_1')) }}
16+
select 1 as id
17+
""",
18+
}
19+
20+
def test_schema_creation(self, project):
21+
res = run_dbt(["run", "-s", "dummy"])
22+
assert len(res) == 1
23+
24+
def test_schema_creation_with_auth(self, project):
25+
res = run_dbt(["run", "-s", "dummy_with_auth"])
26+
assert len(res) == 1

0 commit comments

Comments
 (0)