-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathschema_exists.sql
More file actions
31 lines (26 loc) · 1.48 KB
/
schema_exists.sql
File metadata and controls
31 lines (26 loc) · 1.48 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
{#
Per-adapter schema existence check, scoped to a given database.
Uses SQL queries instead of adapter.check_schema_exists() because that
method is not available in dbt's run-operation context
(RuntimeDatabaseWrapper does not expose it).
#}
{% macro edr_schema_exists(database, schema_name) %}
{% do return(adapter.dispatch('edr_schema_exists', 'elementary_tests')(database, schema_name)) %}
{% endmacro %}
{% macro default__edr_schema_exists(database, schema_name) %}
{% set safe_db = database | replace("'", "''") %}
{% set safe_schema = schema_name | replace("'", "''") %}
{% set result = run_query("SELECT schema_name FROM information_schema.schemata WHERE lower(catalog_name) = lower('" ~ safe_db ~ "') AND lower(schema_name) = lower('" ~ safe_schema ~ "')") %}
{% do return(result | length > 0) %}
{% endmacro %}
{% macro bigquery__edr_schema_exists(database, schema_name) %}
{% set safe_db = database | replace("`", "\`") %}
{% set safe_schema = schema_name | replace("'", "''") %}
{% set result = run_query("SELECT schema_name FROM `" ~ safe_db ~ "`.INFORMATION_SCHEMA.SCHEMATA WHERE lower(schema_name) = lower('" ~ safe_schema ~ "')") %}
{% do return(result | length > 0) %}
{% endmacro %}
{% macro clickhouse__edr_schema_exists(database, schema_name) %}
{% set safe_schema = schema_name | replace("'", "''") %}
{% set result = run_query("SELECT 1 FROM system.databases WHERE name = '" ~ safe_schema ~ "' LIMIT 1") %}
{% do return(result | length > 0) %}
{% endmacro %}