-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathclear_env.sql
More file actions
84 lines (76 loc) · 3.18 KB
/
clear_env.sql
File metadata and controls
84 lines (76 loc) · 3.18 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{% macro clear_env() %}
{% set database_name, schema_name = elementary.get_package_database_and_schema(
"elementary"
) %}
{% do elementary_tests.edr_drop_schema(database_name, schema_name) %}
{% do elementary_tests.edr_drop_schema(
elementary.target_database(), generate_schema_name()
) %}
{% endmacro %}
{% macro drop_test_schemas(num_workers=8) %}
{#
Drop every schema that a CI test run may have created.
This covers the base schema (no xdist suffix) as well as
each pytest-xdist worker schema (_gw0 … _gw<N-1>).
Called from the workflow with `if: always()` so that schemas
are cleaned up even when the pytest process is cancelled or
crashes before its own teardown runs.
#}
{% set database = elementary.target_database() %}
{% set base_schema = target.schema %}
{% set suffixes = [""] %}
{% for i in range(num_workers) %} {% do suffixes.append("_gw" ~ i) %} {% endfor %}
{% for suffix in suffixes %}
{% set test_schema = base_schema ~ suffix %}
{% set elementary_schema = base_schema ~ "_elementary" ~ suffix %}
{% do log(
"Dropping schemas: " ~ test_schema ~ ", " ~ elementary_schema,
info=true,
) %}
{% do elementary_tests.edr_drop_schema(database, elementary_schema) %}
{% do elementary_tests.edr_drop_schema(database, test_schema) %}
{% endfor %}
{% endmacro %}
{% macro edr_drop_schema(database_name, schema_name) %}
{% do return(
adapter.dispatch("edr_drop_schema", "elementary_tests")(
database_name, schema_name
)
) %}
{% endmacro %}
{% macro default__edr_drop_schema(database_name, schema_name) %}
{% set schema_relation = api.Relation.create(
database=database_name, schema=schema_name
) %}
{% do dbt.drop_schema(schema_relation) %}
{% do adapter.commit() %}
{% endmacro %}
{% macro clickhouse__edr_drop_schema(database_name, schema_name) %}
{% do run_query("DROP DATABASE IF EXISTS " ~ schema_name) %}
{% do adapter.commit() %}
{% endmacro %}
{% macro spark__edr_drop_schema(database_name, schema_name) %}
{% set safe_schema = schema_name | replace("`", "``") %}
{% do run_query("DROP DATABASE IF EXISTS `" ~ safe_schema ~ "` CASCADE") %}
{% endmacro %}
{% macro athena__edr_drop_schema(database_name, schema_name) %}
{#
Athena's SQL `DROP SCHEMA … CASCADE` can fail when the schema
contains Iceberg tables. Work around this by first dropping every
relation individually (the adapter handles Iceberg vs Hive
differences in its drop_relation implementation) and then removing
the now-empty schema.
#}
{% set schema_relation = api.Relation.create(
database=database_name, schema=schema_name
) %}
{% set relations = adapter.list_relations_without_caching(schema_relation) %}
{% for relation in relations %}
{% do adapter.drop_relation(relation) %}
{% endfor %}
{% do dbt.drop_schema(schema_relation) %}
{% endmacro %}
{% macro duckdb__edr_drop_schema(database_name, schema_name) %}
{% do run_query("DROP SCHEMA IF EXISTS " ~ schema_name ~ " CASCADE") %}
{% do adapter.commit() %}
{% endmacro %}