Skip to content

Commit 3b8df88

Browse files
fivetran-savagerasinmuhammedfivetran-data-model-bot
authored
Release branch/v1.10.0 (#158)
* partition rolling totals in stripe__daily_overview by account_id and source_relation * join balance transactions and failed charges on the account, and put source_relation in the daily surrogate key * feature/add_historic_pricing_to_mrr_report * Update CHANGELOG.md * Generate dbt docs via GitHub Actions * update_partition_macro * Generate dbt docs via GitHub Actions * add_contributor * update_changelog --------- Co-authored-by: Muhammed Rasin O M <rasinbinabdulla@gmail.com> Co-authored-by: fivetran-data-model-bot <fivetran-data-model-bot@users.noreply.github.com>
1 parent 5159f92 commit 3b8df88

18 files changed

Lines changed: 127 additions & 64 deletions

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# dbt_stripe v1.10.0
2+
3+
[PR #158](https://github.com/fivetran/dbt_stripe/pull/158) includes the following updates:
4+
5+
## Schema/Data Change
6+
**5 total changes • 4 possible breaking changes**
7+
8+
| Data Model(s) | Change type | Old | New | Notes |
9+
| ------------- | ----------- | --- | --- | ----- |
10+
| `stripe__daily_overview` | Changed field (**breaking change**) | surrogate key hashed on `account_id` and `date_day`. | surrogate key hashed on `source_relation`, `account_id`, and `date_day`. | Two unioned connectors that share an account ID and a date previously produced the same key. |
11+
| `stripe__daily_overview` | Possible changed data (possible breaking change)| Each `rolling_*` column accumulated across all accounts. | Each `rolling_*` column is the running total of its own `account_id` and `source_relation`. | Only affects destinations with more than one account or more than one unioned connector. Single-account output is unchanged. See [#155](https://github.com/fivetran/dbt_stripe/issues/155). |
12+
| `stripe__daily_overview`<br>`int_stripe__account_daily` | Changed join (possible breaking change) | Balance transactions and failed charges join to the date spine on the date and `source_relation` only, so every account counts every other account's activity as its own. | Both joins also match on the account. | Only affects destinations with more than one account. Transactions with no `connected_account_id` still count toward every account; see the [DECISIONLOG](https://github.com/fivetran/dbt_stripe/blob/main/DECISIONLOG.md#daily-overview-attribution-for-transactions-without-a-connected-account) for why. Single-account output is unchanged. |
13+
| `stripe__subscription_item_mrr_report` | Changed model (possible breaking change) | Historical months apply the item's current `price_plan` unit amount. | Historical months apply the `unit_amount_excluding_tax` from the invoice line that billed them, carried forward across gap months. | MRR now reflects a price change from the month it took effect instead of applying today's price across all history, so historical `month_contract_mrr`, `month_discount_applied`, `month_billed_mrr`, and `contract_mrr_type` values change. Months with no invoiced unit amount still use the live `price_plan` unit amount. See the [DECISIONLOG](https://github.com/fivetran/dbt_stripe/blob/main/DECISIONLOG.md#mrr-history-anchored-to-each-subscription-items-creation-date). |
14+
| `stg_stripe__invoice_line_item` | New field | | `unit_amount_excluding_tax` | |
15+
16+
## Contributors
17+
- [@rasinmuhammed](https://github.com/rasinmuhammed) ([PR #156](https://github.com/fivetran/dbt_stripe/pull/156))
18+
119
# dbt_stripe v1.9.0
220

321
[PR #153](https://github.com/fivetran/dbt_stripe/pull/153) includes the following updates:

DECISIONLOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
## Daily Overview Attribution for Transactions Without a Connected Account
2+
3+
The `stripe__daily_overview` model attributes each balance transaction and failed charge to the account named in its `connected_account_id`. When that field is null, the transaction counts toward every account on the destination.
4+
5+
Stripe populates `connected_account_id` only for Connect activity tied to a connected account, so a null means the activity belongs to the platform account. The `account` source table gives us no reliable way to identify that platform account, so we do not guess. For a single-account destination this is correct, since every transaction is null. For a Connect destination, each connected account's own activity is attributed only to it, but platform activity still counts toward every account and can overstate those totals. If this affects your reporting, please open a [feature request](https://github.com/fivetran/dbt_stripe/issues/new?template=feature-request.yml).
6+
17
## MRR History Anchored to Each Subscription Item's Creation Date
28

39
The `stripe__subscription_item_mrr_report` model anchors each item's MRR timeline to that item's `created_at`, reporting MRR from when the item was added through the current month.
410

511
Because `subscription_item` retains only the current state of each item, we reconstruct historical quantity from `invoice_line_item`, which records the quantity actually billed for each period. For each month, we use the quantity from the most recent invoice line whose period overlaps that month (proration adjustment lines excluded); the current month uses the live `subscription_item` quantity. This lets the report surface real `expansion` and `contraction` between months rather than back-projecting today's quantity across all history.
612

7-
Because this model depends on `invoice_line_item` for historical quantity, it requires `stripe__using_invoices` (enabled by default) and does not build when that variable is disabled. Stripe generates an invoice each billing period, so gaps are not expected, but when a month has no invoice line we carry the most recent prior invoiced quantity forward rather than snapping to today's quantity (which would invent phantom changes in the gap). A month falls back to the current `subscription_item` quantity only when no earlier invoice exists (months before the first invoice). Prices are not back-filled — historical months apply the item's current price.
13+
Because this model depends on `invoice_line_item` for historical quantity, it requires `stripe__using_invoices` (enabled by default) and does not build when that variable is disabled. Stripe generates an invoice each billing period, so gaps are not expected, but when a month has no invoice line we carry the most recent prior invoiced quantity forward rather than snapping to today's quantity (which would invent phantom changes in the gap). A month falls back to the current `subscription_item` quantity only when no earlier invoice exists (months before the first invoice).
14+
15+
Price is reconstructed the same way. Each month uses the most recent invoiced `unit_amount_excluding_tax`, carried forward across gap months, so a price change is reflected from the month it took effect rather than applied backwards across all history. The current month uses the live `price_plan` unit amount. A month falls back to the live `price_plan` unit amount when no earlier invoice line carries a unit amount, which includes invoices synced before Stripe began populating the field.
16+
17+
Price and quantity carry forward independently, so each month uses the most recent value available for each. When an invoice line records one but not the other, a month can take its price and its quantity from different invoice lines. Where both are present, which is the normal case, both come from the same line.
818

919
## MRR Timeline Uses an End-of-Month Snapshot
1020

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Include the following stripe package version in your `packages.yml` file:
8080
```yaml
8181
packages:
8282
- package: fivetran/stripe
83-
version: [">=1.9.0", "<1.10.0"]
83+
version: [">=1.10.0", "<1.11.0"]
8484
```
8585
> All required sources and staging models are now bundled into this transformation package. Do not include `fivetran/stripe_source` in your `packages.yml` since this package has been deprecated.
8686

dbt_project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
config-version: 2
22
name: 'stripe'
33

4-
version: '1.9.0'
4+
version: '1.10.0'
55
require-dbt-version: [">=1.3.0", "<3.0.0"]
66

77
models:

docs/catalog.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/manifest.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

integration_tests/dbt_project.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ config-version: 2
22

33
name: 'stripe_integration_tests'
44

5-
version: '1.9.0'
5+
version: '1.10.0'
66

77
profile: 'integration_tests'
88

@@ -127,6 +127,7 @@ seeds:
127127
+column_types:
128128
_fivetran_synced: timestamp
129129
invoice_id: "{{ 'varchar(500)' if target.type in ('redshift','postgres') else 'string'}}"
130+
unit_amount_excluding_tax: "{{ 'varchar(100)' if target.type in ('redshift','postgres') else 'string'}}"
130131
payment_intent_data:
131132
+column_types:
132133
_fivetran_synced: timestamp
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
id,invoice_id,_fivetran_synced,amount,currency,description,discountable,livemode,period_end,period_start,plan_id,proration,quantity,subscription_id,subscription_item_id,type,unique_id,metadata
2-
ad1111,ab1111,2021-02-18 14:16:37,21,usd,description_here,FALSE,TRUE,2021-02-19 14:16:37,2021-02-18 14:16:37,sg555,TRUE,5,sdgfs4536,sdm99,,gg665,{}
3-
ba222,bd665,2021-02-18 14:16:37,65,usd,description_here,TRUE,TRUE,2021-02-19 14:16:37,2021-02-18 14:16:37,sdgf5575,FALSE,4,sfjytkyu876,sdgjk5489,,dsgjnik978,"{""external_id"":""1111111-2222-3333-4444-55555555""}"
4-
ba3333,cde3453,2021-02-18 14:16:37,100,usd,description_here,FALSE,TRUE,2021-02-19 14:16:37,2021-02-18 14:16:37,adsdgf5575,TRUE,0,sdgfs4536,greiot45,,briieugh4939,{}
1+
id,invoice_id,_fivetran_synced,amount,currency,description,discountable,livemode,period_end,period_start,plan_id,proration,quantity,subscription_id,subscription_item_id,type,unique_id,metadata,unit_amount_excluding_tax
2+
ad1111,ab1111,2021-02-18 14:16:37,21,usd,description_here,FALSE,TRUE,2021-02-19 14:16:37,2021-02-18 14:16:37,sg555,TRUE,5,sdgfs4536,sdm99,,gg665,{},4.2
3+
ba222,bd665,2021-02-18 14:16:37,65,usd,description_here,TRUE,TRUE,2021-02-19 14:16:37,2021-02-18 14:16:37,sdgf5575,FALSE,4,sfjytkyu876,sdgjk5489,,dsgjnik978,"{""external_id"":""1111111-2222-3333-4444-55555555""}",16.25
4+
ba3333,cde3453,2021-02-18 14:16:37,100,usd,description_here,FALSE,TRUE,2021-02-19 14:16:37,2021-02-18 14:16:37,adsdgf5575,TRUE,0,sdgfs4536,greiot45,,briieugh4939,{},100

macros/staging/get_invoice_line_item_columns.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
{"name": "subscription_id", "datatype": dbt.type_string()},
2121
{"name": "subscription_item_id", "datatype": dbt.type_string()},
2222
{"name": "type", "datatype": dbt.type_string()},
23-
{"name": "unique_id", "datatype": dbt.type_string()}
23+
{"name": "unique_id", "datatype": dbt.type_string()},
24+
{"name": "unit_amount_excluding_tax", "datatype": dbt.type_string()}
2425
] %}
2526

2627
{{ return(columns) }}

models/intermediate/int_stripe__account_daily.sql

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,25 @@ with date_spine as (
6464
left join balance_transaction
6565
on cast({{ dbt.date_trunc('day', 'balance_transaction.date') }} as date) = date_spine.date_day
6666
and balance_transaction.source_relation = date_spine.source_relation
67+
and coalesce(balance_transaction.connected_account_id, date_spine.account_id) = date_spine.account_id
6768
group by 1,2,3
6869

6970
), daily_failed_charges as (
7071

7172
select
72-
{{ date_timezone('created_at') }} as date,
73-
source_relation,
74-
count(*) as total_daily_failed_charge_count,
75-
sum(amount) as total_daily_failed_charge_amount
76-
from incomplete_charges
77-
group by 1,2
73+
date_spine.date_day,
74+
date_spine.account_id,
75+
date_spine.source_relation,
76+
sum(case when incomplete_charges.created_at is not null
77+
then 1
78+
else 0 end) as total_daily_failed_charge_count,
79+
sum(incomplete_charges.amount) as total_daily_failed_charge_amount
80+
from date_spine
81+
left join incomplete_charges
82+
on cast({{ date_timezone('incomplete_charges.created_at') }} as date) = date_spine.date_day
83+
and incomplete_charges.source_relation = date_spine.source_relation
84+
and coalesce(incomplete_charges.connected_account_id, date_spine.account_id) = date_spine.account_id
85+
group by 1,2,3
7886
)
7987

8088
select
@@ -99,5 +107,6 @@ select
99107

100108
from daily_account_balance_transactions
101109
left join daily_failed_charges
102-
on daily_account_balance_transactions.date_day = daily_failed_charges.date
110+
on daily_account_balance_transactions.date_day = daily_failed_charges.date_day
111+
and daily_account_balance_transactions.account_id = daily_failed_charges.account_id
103112
and daily_account_balance_transactions.source_relation = daily_failed_charges.source_relation

0 commit comments

Comments
 (0)