|
8 | 8 | ) %} |
9 | 9 | {% endmacro %} |
10 | 10 |
|
| 11 | +{% macro drop_test_schemas(num_workers=8) %} |
| 12 | + {# |
| 13 | + Drop every schema that a CI test run may have created. |
| 14 | + This covers the base schema (no xdist suffix) as well as |
| 15 | + each pytest-xdist worker schema (_gw0 … _gw<N-1>). |
| 16 | + Called from the workflow with `if: always()` so that schemas |
| 17 | + are cleaned up even when the pytest process is cancelled or |
| 18 | + crashes before its own teardown runs. |
| 19 | + #} |
| 20 | + {% set database = elementary.target_database() %} |
| 21 | + {% set base_schema = target.schema %} |
| 22 | + {% set suffixes = [""] %} |
| 23 | + {% for i in range(num_workers) %} {% do suffixes.append("_gw" ~ i) %} {% endfor %} |
| 24 | + |
| 25 | + {% for suffix in suffixes %} |
| 26 | + {% set test_schema = base_schema ~ suffix %} |
| 27 | + {% set elementary_schema = base_schema ~ "_elementary" ~ suffix %} |
| 28 | + {% do log( |
| 29 | + "Dropping schemas: " ~ test_schema ~ ", " ~ elementary_schema, |
| 30 | + info=true, |
| 31 | + ) %} |
| 32 | + {% do elementary_tests.edr_drop_schema(database, elementary_schema) %} |
| 33 | + {% do elementary_tests.edr_drop_schema(database, test_schema) %} |
| 34 | + {% endfor %} |
| 35 | +{% endmacro %} |
| 36 | + |
11 | 37 | {% macro edr_drop_schema(database_name, schema_name) %} |
12 | 38 | {% do return( |
13 | 39 | adapter.dispatch("edr_drop_schema", "elementary_tests")( |
|
34 | 60 | {% do run_query("DROP DATABASE IF EXISTS `" ~ safe_schema ~ "` CASCADE") %} |
35 | 61 | {% endmacro %} |
36 | 62 |
|
| 63 | +{% macro athena__edr_drop_schema(database_name, schema_name) %} |
| 64 | + {# |
| 65 | + Athena's SQL `DROP SCHEMA … CASCADE` can fail when the schema |
| 66 | + contains Iceberg tables. Work around this by first dropping every |
| 67 | + relation individually (the adapter handles Iceberg vs Hive |
| 68 | + differences in its drop_relation implementation) and then removing |
| 69 | + the now-empty schema. |
| 70 | + #} |
| 71 | + {% set schema_relation = api.Relation.create( |
| 72 | + database=database_name, schema=schema_name |
| 73 | + ) %} |
| 74 | + {% set relations = adapter.list_relations_without_caching(schema_relation) %} |
| 75 | + {% for relation in relations %} |
| 76 | + {% do adapter.drop_relation(relation) %} |
| 77 | + {% endfor %} |
| 78 | + {% do dbt.drop_schema(schema_relation) %} |
| 79 | +{% endmacro %} |
| 80 | +
|
37 | 81 | {% macro duckdb__edr_drop_schema(database_name, schema_name) %} |
38 | 82 | {% do run_query("DROP SCHEMA IF EXISTS " ~ schema_name ~ " CASCADE") %} |
39 | 83 | {% do adapter.commit() %} |
|
0 commit comments