added project level variable and associated IF statements to on-run-start macros to default UDF/SP updates to False (#30)

This commit is contained in:
drethereum 2022-11-14 12:24:26 -07:00 committed by GitHub
parent db858c5b28
commit cfa49518ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 11 deletions

View File

@ -35,7 +35,17 @@ avalanche:
query_tag: <TAG>
```
### Variables
To control the creation of UDF or SP macros with dbt run:
* UPDATE_UDFS_AND_SPS
When True, executes all macros included in the on-run-start hooks within dbt_project.yml on model run as normal
When False, none of the on-run-start macros are executed on model run
Default values are False
* Usage:
dbt run --var '{"UPDATE_UDFS_AND_SPS":True}' -m ...
### Resources:
- Learn more about dbt [in the docs](https://docs.getdbt.com/docs/introduction)

View File

@ -40,3 +40,4 @@ on-run-start:
vars:
"dbt_date:time_zone": GMT
UPDATE_UDFS_AND_SPS: False

View File

@ -1,6 +1,8 @@
{% macro create_sps() %}
{% if target.database == 'AVALANCHE' %}
CREATE schema IF NOT EXISTS _internal;
{{ sp_create_prod_clone('_internal') }};
{% if var("UPDATE_UDFS_AND_SPS") %}
{% if target.database == 'AVALANCHE' %}
CREATE schema IF NOT EXISTS _internal;
{{ sp_create_prod_clone('_internal') }};
{% endif %}
{% endif %}
{% endmacro %}

View File

@ -1,11 +1,13 @@
{% macro create_udfs() %}
{% set sql %}
CREATE schema if NOT EXISTS silver;
{{ create_js_hex_to_int() }};
{{ create_udf_hex_to_int(
schema = "public"
) }}
{% if var("UPDATE_UDFS_AND_SPS") %}
{% set sql %}
CREATE schema if NOT EXISTS silver;
{{ create_js_hex_to_int() }};
{{ create_udf_hex_to_int(
schema = "public"
) }}
{% endset %}
{% do run_query(sql) %}
{% endset %}
{% do run_query(sql) %}
{% endif %}
{% endmacro %}