diff --git a/macros/get_discount_application_columns.sql b/macros/get_discount_application_columns.sql new file mode 100644 index 0000000..e04ca47 --- /dev/null +++ b/macros/get_discount_application_columns.sql @@ -0,0 +1,22 @@ +{% macro get_discount_application_columns() %} + +{% set columns = [ + {"name": "index", "datatype": dbt.type_string()}, + {"name": "order_id", "datatype": dbt.type_string}, + {"name": "_fivetran_synced", "datatype": dbt.type_timestamp()}, + {"name": "allocation_method", "datatype": dbt.type_string}, + {"name": "code", "datatype": dbt.type_string}, + {"name": "description", "datatype": dbt.type_string}, + {"name": "target_selection", "datatype": dbt.type_string}, + {"name": "target_type", "datatype": dbt.type_string}, + {"name": "title", "datatype": dbt.type_string}, + {"name": "type", "datatype": dbt.type_string}, + {"name": "value", "datatype": dbt.type_numeric}, + {"name": "value_type", "datatype": dbt.type_string} +] %} + +{{ fivetran_utils.add_pass_through_columns(columns, var('customer_pass_through_columns')) }} + +{{ return(columns) }} + +{% endmacro %} diff --git a/models/stg_shopify.yml b/models/stg_shopify.yml index c33cd76..bc72b26 100644 --- a/models/stg_shopify.yml +++ b/models/stg_shopify.yml @@ -1705,3 +1705,12 @@ models: - name: order_line_id - name: source_relation - name: amount + + - name: stg_shopify__discount_application + description: discount_application + columns: + - name: order_id + - name: source_relation + - name: value + - name: value_type, + - name: target_type diff --git a/models/stg_shopify__discount_application.sql b/models/stg_shopify__discount_application.sql new file mode 100644 index 0000000..ab71110 --- /dev/null +++ b/models/stg_shopify__discount_application.sql @@ -0,0 +1,41 @@ +with base as ( + + select * + from {{ ref('stg_shopify__discount_application_tmp') }} + +), + +fields as ( + + select + + {{ + fivetran_utils.fill_staging_columns( + source_columns=adapter.get_columns_in_relation(ref('stg_shopify__discount_application_tmp')), + staging_columns=get_discount_application_columns() + ) + }} + + {{ fivetran_utils.source_relation( + union_schema_variable='shopify_union_schemas', + union_database_variable='shopify_union_databases') + }} + + from base + +), + +final as ( + + select + order_id, + source_relation, + value, + value_type, + target_type + from fields + +) + +select * +from final diff --git a/models/tmp/stg_shopify__discount_application_tmp.sql b/models/tmp/stg_shopify__discount_application_tmp.sql new file mode 100644 index 0000000..10399e7 --- /dev/null +++ b/models/tmp/stg_shopify__discount_application_tmp.sql @@ -0,0 +1,12 @@ +{{ + fivetran_utils.union_data( + table_identifier='discount_application', + database_variable='shopify_database', + schema_variable='shopify_schema', + default_database=target.database, + default_schema='shopify', + default_variable='discount_applicaton_source', + union_schema_variable='shopify_union_schemas', + union_database_variable='shopify_union_databases' + ) +}}