Skip to content

Commit 11d2284

Browse files
rickyromboclaude
andcommitted
fix(purchases): default extra_amount to 0 when price_history is missing
If no track_price_history / album_price_history row applies to a purchase, the view currently returns extra_amount = sp.amount because the COALESCE falls back to 0 and (sp.amount - 0) = sp.amount. Cases this hits: - Content deleted before its price was ever indexed - Backfilled historical purchases whose content predates price_history tracking - Test environments that don't fixture price_history Change the fallback to sp.amount so the subtraction nets to 0 — matches "we don't know the base price, don't claim there was a tip." Production purchases via the Go indexer always have price_history coverage (the indexer validates against it), so this only affects the fallback path. This was a follow-up commit on the PR #815 branch that didn't make it into the squash-merge. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent e3eb44f commit 11d2284

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

ddl/views/v_usdc_purchases.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ SELECT
3434
LIMIT 1
3535
)
3636
END,
37-
0
37+
sp.amount -- no price_history match -> treat full amount as base price (extra_amount = 0)
3838
),
3939
0
4040
) AS extra_amount,

sql/01_schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9644,7 +9644,7 @@ CREATE VIEW public.v_usdc_purchases AS
96449644
WHERE ((aph.playlist_id = sp.content_id) AND (aph.block_timestamp <= sp.created_at))
96459645
ORDER BY aph.block_timestamp DESC
96469646
LIMIT 1)
9647-
END, (0)::bigint)), (0)::bigint) AS extra_amount,
9647+
END, sp.amount)), (0)::bigint) AS extra_amount,
96489648
(sp.access_type)::public.usdc_purchase_access_type AS access,
96499649
sp.city,
96509650
sp.region,

0 commit comments

Comments
 (0)