forked from Montreal-Analytics/dbt-snowflake-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclone_schema.sql
22 lines (14 loc) · 864 Bytes
/
clone_schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{% macro clone_schema(source_schema, destination_schema, source_database=target.database, destination_database=target.database) %}
{% if source_schema and destination_schema %}
{{ (log("Cloning existing schema " ~ source_database ~ "." ~ source_schema ~
" into schema " ~ destination_database ~ "." ~ destination_schema, info=True)) }}
{% call statement('clone_schema', fetch_result=True, auto_begin=False) -%}
CREATE OR REPLACE SCHEMA {{ destination_database }}.{{ destination_schema }}
CLONE {{ source_database }}.{{ source_schema }}
{%- endcall %}
{%- set result = load_result('clone_schema') -%}
{{ log(result['data'][0][0], info=True)}}
{% else %}
{{ exceptions.raise_compiler_error("Invalid arguments. Missing source schema and/or destination schema") }}
{% endif %}
{% endmacro %}