Skip to content

fix(purchases): default extra_amount to 0 when price_history is missing#820

Merged
rickyrombo merged 1 commit into
mainfrom
mp/fix-v-usdc-purchases-extra-amount
May 18, 2026
Merged

fix(purchases): default extra_amount to 0 when price_history is missing#820
rickyrombo merged 1 commit into
mainfrom
mp/fix-v-usdc-purchases-extra-amount

Conversation

@rickyrombo
Copy link
Copy Markdown
Contributor

Summary

Companion to #819. The same PR #815 branch had a third follow-up commit that didn't make it into the squash-merge — this is it.

The view's `extra_amount` computation is `sp.amount - COALESCE(<price_history_lookup>, 0)`. When the price-history lookup returns NULL (no matching row applicable at purchase time), the fallback to `0` makes the subtraction return `sp.amount` itself, i.e. the entire purchase amount is reported as a "tip."

Cases this hits in practice:

  • 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

Production purchases written by the Go indexer always have price_history coverage (the indexer validates against it before writing), so this only affects the fallback path — but the fallback path is wrong as-shipped.

Change `COALESCE(..., 0)` to `COALESCE(..., sp.amount)` so the subtraction nets to 0 when we don't know the base price. Matches the legacy semantic of "no tip declared."

Test plan

  • On a prod replica: `SELECT signature, amount, extra_amount FROM v_usdc_purchases WHERE extra_amount = amount LIMIT 10` — should be empty (or much smaller) after the fix
  • `/v1/users/{id}/purchases` for a historical user shows `extra_amount: "0"` instead of `extra_amount: ` for content without price history

🤖 Generated with Claude Code

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>
@rickyrombo rickyrombo merged commit 63abd33 into main May 18, 2026
3 of 4 checks passed
@rickyrombo rickyrombo deleted the mp/fix-v-usdc-purchases-extra-amount branch May 18, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant