-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathschema_exists.sql
More file actions
39 lines (34 loc) · 1.41 KB
/
schema_exists.sql
File metadata and controls
39 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{% macro schema_exists(database, schema) %}
{% do return(adapter.dispatch("schema_exists", "elementary")(database, schema)) %}
{% endmacro %}
{% macro snowflake__schema_exists(database, schema) %}
{% set database_sql %}
show databases like '{{ database }}'
{% endset %}
{% set database_exists = elementary.run_query(database_sql)|length > 0 %}
{% if not database_exists %}
{% do return(false) %}
{% endif %}
{% do return(adapter.check_schema_exists(database, schema)) %}
{% endmacro %}
{% macro postgres__schema_exists(database, schema) %}
{% if database != target.database %}
{# Cross db operations not supported in postgres #}
{% do return(false) %}
{% endif %}
{% do return(adapter.check_schema_exists(database, schema)) %}
{% endmacro %}
{% macro bigquery__schema_exists(database, schema) %}
{% if database != target.project %}
{# Cannot check for non-existing database in bigquery through sql (only api), assume it exists #}
{% do return(true) %}
{% endif %}
{% do return(adapter.check_schema_exists(database, schema)) %}
{% endmacro %}
{% macro clickhouse__schema_exists(database, schema) %}
{% set result = run_query("SELECT 1 FROM system.databases WHERE name = '" ~ schema ~ "' LIMIT 1") %}
{% do return(result | length > 0) %}
{% endmacro %}
{% macro default__schema_exists(database, schema) %}
{% do return(adapter.check_schema_exists(database, schema)) %}
{% endmacro %}