From dbecade13cc1c6236842acf389b0dc0c33c75d8d Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 23 Feb 2024 17:08:58 +0100 Subject: [PATCH] cast balance amounts to numeric --- models/staging/stripe/schema.yml | 6 +++--- .../stripe/stg_stripe__balance_transactions.sql | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/models/staging/stripe/schema.yml b/models/staging/stripe/schema.yml index 7bfa529..f57f465 100644 --- a/models/staging/stripe/schema.yml +++ b/models/staging/stripe/schema.yml @@ -12,16 +12,16 @@ models: data_type: character varying description: "{{ doc('generic_id_desc') }}" - name: fee - data_type: bigint + data_type: numeric description: "Fees paid for this transaction. Represented as a positive integer when assessed." - name: net - data_type: bigint + data_type: numeric description: "Net impact to a Stripe balance. A positive value represents incrementing a Stripe balance, and a negative value decrementing a Stripe balance. You can calculate the net impact of a transaction on a balance by amount - fee" - name: type data_type: character varying description: "Transaction type: adjustment, advance, advance_funding, anticipation_repayment, application_fee, application_fee_refund, charge, climate_order_purchase, climate_order_refund, connect_collection_transfer, contribution, issuing_authorization_hold, issuing_authorization_release, issuing_dispute, issuing_transaction, obligation_outbound, obligation_reversal_inbound, payment, payment_failure_refund, payment_network_reserve_hold, payment_network_reserve_release, payment_refund, payment_reversal, payment_unreconciled, payout, payout_cancel, payout_failure, refund, refund_failure, reserve_transaction, reserved_funds, stripe_fee, stripe_fx_fee, tax_fee, topup, topup_reversal, transfer, transfer_cancel, transfer_failure, or transfer_refund. Learn more about balance transaction types and what they represent. To classify transactions for accounting purposes, consider reporting_category instead." - name: amount - data_type: bigint + data_type: numeric description: "Gross amount of this transaction. A positive value represents funds charged to another party, and a negative value represents funds sent to another party." - name: object data_type: character varying diff --git a/models/staging/stripe/stg_stripe__balance_transactions.sql b/models/staging/stripe/stg_stripe__balance_transactions.sql index bdb352c..ec2ffc4 100644 --- a/models/staging/stripe/stg_stripe__balance_transactions.sql +++ b/models/staging/stripe/stg_stripe__balance_transactions.sql @@ -6,10 +6,19 @@ with stg_stripe__balance_transactions as ( select {{ adapter.quote("id") }}, - {{ adapter.quote("fee") }} / (10 ^ cur.decimal_positions) as fee, - {{ adapter.quote("net") }} / (10 ^ cur.decimal_positions) as net, + cast( + {{ adapter.quote("fee") }} + / (10 ^ cur.decimal_positions) as numeric(19, 4) + ) as fee, + cast( + {{ adapter.quote("net") }} + / (10 ^ cur.decimal_positions) as numeric(19, 4) + ) as net, {{ adapter.quote("type") }}, - {{ adapter.quote("amount") }} / (10 ^ cur.decimal_positions) as amount, + cast( + {{ adapter.quote("amount") }} + / (10 ^ cur.decimal_positions) as numeric(19, 4) + ) as amount, {{ adapter.quote("object") }}, {{ adapter.quote("source") }}, {{ adapter.quote("status") }},