data-dwh-dbt-project/macros/generate_schema_name.sql

21 lines
741 B
MySQL
Raw Permalink Normal View History

2024-05-22 11:42:42 +02:00
/*
This macro is necessary to allow different models to automatically be generated
in schemas different than the default one for the target database.
To understand better, check:
- https://www.youtube.com/watch?v=AvrVQr5FHwk
- https://docs.getdbt.com/docs/build/custom-schemas
*/
2024-01-18 12:20:14 +01:00
{% macro generate_schema_name(custom_schema_name, node) -%}
2025-03-24 11:58:15 +01:00
{%- set default_schema = target.schema -%}
{%- set is_ci_execution = env_var("IS_CI_EXECUTION", "0") | int -%}
{%- set ci_schema_name = env_var("CI_SCHEMA_NAME", "ci_default") -%}
2024-01-18 12:20:14 +01:00
2025-03-24 11:58:15 +01:00
{%- if is_ci_execution == 1 -%} {{ ci_schema_name }}
{%- elif custom_schema_name is none -%} {{ default_schema }}
{%- else -%} {{ custom_schema_name | trim }}
{%- endif -%}
2024-01-18 12:20:14 +01:00
2024-05-22 11:42:42 +02:00
{%- endmacro %}