Paradime Turbo CI Schema Cleanup
Overview
Configure the drop_turbo_ci_schema macro
drop_turbo_ci_schema macro{# Deletes BigQuery datasets created by Paradime Turbo CI #}
{% macro drop_turbo_ci_schema(dryrun=True) %}
{# Get project ID from BigQuery connection config based on the target used to executed the macro #}
{%- set default_database = target.database -%}
{# Set schema pattern to match with schemas created by Paradime Turbo CI #}
{%- set paradime_turbo_ci_schema = 'paradime_turbo_ci%' -%}
{#
IMPORTANT: Set your BigQuery region here based on your configuration
Common region options include:
- us (United States)
- eu (European Union)
- asia-east1 (Taiwan)
- asia-northeast1 (Tokyo)
- asia-southeast1 (Singapore)
- australia-southeast1 (Sydney)
- europe-west1 (Belgium)
- europe-west2 (London)
- europe-west3 (Frankfurt)
- northamerica-northeast1 (Montreal)
- southamerica-east1 (São Paulo)
For a complete list of regions, see: https://cloud.google.com/bigquery/docs/locations
#}
{%- set region = 'us' -%}
{# Query to generate DROP commands for matching schemas #}
{% set cleanup_query %}
WITH TURBO_CI_DROP_SCHEMA AS (
SELECT
catalog_name,
schema_name
FROM {{default_database}}.`region-{{region}}`.INFORMATION_SCHEMA.SCHEMATA
WHERE schema_name LIKE '{{ paradime_turbo_ci_schema }}'
)
SELECT
'DROP SCHEMA ' || '`' || catalog_name || '.' || schema_name || '`' || ' CASCADE' || ';' as DROP_COMMANDS
FROM
TURBO_CI_DROP_SCHEMA
{% endset %}
{# Get list of DROP commands to execute #}
{% set drop_commands = run_query(cleanup_query).columns[0].values() %}
{# Execute or print DROP commands based on dryrun parameter #}
{% if drop_commands %}
{% if dryrun | as_bool == False %}
{% do log('Executing DROP commands...', True) %}
{% else %}
{% do log('Printing DROP commands...', True) %}
{% endif %}
{% for drop_command in drop_commands %}
{% do log(drop_command, True) %}
{% if dryrun | as_bool == False %}
{% do run_query(drop_command) %}
{% endif %}
{% endfor %}
{% else %}
{% do log('No relations to clean.', True) %}
{% endif %}
{%- endmacro -%}Usage
Arguments
Configure a Bolt Schedule
Schedule Settings
Setting
Value
Explanation
Command Settings
Trigger Type
Notification Settings
Last updated
Was this helpful?