From 11d228448528dedae648085b6ca3120413185574 Mon Sep 17 00:00:00 2001 From: Marcus Pasell <3690498+rickyrombo@users.noreply.github.com> Date: Mon, 18 May 2026 09:19:35 -0700 Subject: [PATCH] fix(purchases): default extra_amount to 0 when price_history is missing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- ddl/views/v_usdc_purchases.sql | 2 +- sql/01_schema.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ddl/views/v_usdc_purchases.sql b/ddl/views/v_usdc_purchases.sql index f01eee93..81437e91 100644 --- a/ddl/views/v_usdc_purchases.sql +++ b/ddl/views/v_usdc_purchases.sql @@ -34,7 +34,7 @@ SELECT LIMIT 1 ) END, - 0 + sp.amount -- no price_history match -> treat full amount as base price (extra_amount = 0) ), 0 ) AS extra_amount, diff --git a/sql/01_schema.sql b/sql/01_schema.sql index 9e5df03a..0f0ef316 100644 --- a/sql/01_schema.sql +++ b/sql/01_schema.sql @@ -9644,7 +9644,7 @@ CREATE VIEW public.v_usdc_purchases AS WHERE ((aph.playlist_id = sp.content_id) AND (aph.block_timestamp <= sp.created_at)) ORDER BY aph.block_timestamp DESC LIMIT 1) - END, (0)::bigint)), (0)::bigint) AS extra_amount, + END, sp.amount)), (0)::bigint) AS extra_amount, (sp.access_type)::public.usdc_purchase_access_type AS access, sp.city, sp.region,