diff --git a/macros/generate_stripe_sources_unioned_select.sql b/macros/generate_stripe_sources_unioned_select.sql new file mode 100644 index 0000000..d2803c3 --- /dev/null +++ b/macros/generate_stripe_sources_unioned_select.sql @@ -0,0 +1,15 @@ +/* +This macro runs for every country code and: + - Reads from the right source (stripe_) + - Adds a column identifying the source account with a string like "stripe__account" +*/ +{% macro generate_stripe_sources_unioned_select(source_table) -%} + {% set countries = ["us", "uk"] %} + {% for country in countries %} + select *, 'stripe_{{ country }}_account' as stripe_source_account + from {{ source("stripe_" ~ country, source_table) }} + {% if not loop.last -%} + union all + {%- endif %} + {% endfor %} +{%- endmacro %} diff --git a/models/staging/stripe/stg_stripe__balance_transactions.sql b/models/staging/stripe/stg_stripe__balance_transactions.sql index da82a35..e435206 100644 --- a/models/staging/stripe/stg_stripe__balance_transactions.sql +++ b/models/staging/stripe/stg_stripe__balance_transactions.sql @@ -1,19 +1,6 @@ with raw_balance_transactions as ( - /* - This macro runs for every country code and: - - Reads from the right source (stripe_) - - Adds a column identifying the source account with a string like "stripe__account" - */ - {% set countries = ["us", "uk"] %} - - {% for country in countries %} - select *, 'stripe_{{ country }}_account' as stripe_source_account - from {{ source("stripe_" ~ country, "balance_transactions") }} - {% if not loop.last -%} - union all - {%- endif %} - {% endfor %} + {{ generate_stripe_sources_unioned_select("balance_transactions") }} ), stg_seed__currencies as (select * from {{ ref("stg_seed__currencies") }}), stg_stripe__balance_transactions as (