-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a schema check before privilege dependent ddl in Snowflake (#215)
- Loading branch information
1 parent
1873d87
commit f4536ba
Showing
1 changed file
with
32 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,32 @@ | ||
{% macro snowflake__create_external_schema(source_node) %} | ||
|
||
{% set schema_exists_query %} | ||
show terse schemas like '{{ source_node.schema }}' in database {{ source_node.database }} limit 1; | ||
{% endset %} | ||
{% if execute %} | ||
{% set schema_exists = run_query(schema_exists_query)|length > 0 %} | ||
{% else %} | ||
{% set schema_exists = false %} | ||
{% endif %} | ||
|
||
{% if schema_exists %} | ||
{% set ddl %} | ||
select 'Schema {{ source_node.schema }} exists' from dual; | ||
{% endset %} | ||
{% else %} | ||
{% set fqn %} | ||
{% if source_node.database %} | ||
{{ source_node.database }}.{{ source_node.schema }} | ||
{% else %} | ||
{{ source_node.schema }} | ||
{% endif %} | ||
{% endset %} | ||
|
||
{% set ddl %} | ||
create schema if not exists {{ fqn }}; | ||
{% endset %} | ||
{% endif %} | ||
|
||
{% do return(ddl) %} | ||
|
||
{% endmacro %} |