Commit 63abd33
fix(purchases): default extra_amount to 0 when price_history is missing (#820)
## 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: <full amount>\` for
content without price history
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent e3eb44f commit 63abd33
2 files changed
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9644 | 9644 | | |
9645 | 9645 | | |
9646 | 9646 | | |
9647 | | - | |
| 9647 | + | |
9648 | 9648 | | |
9649 | 9649 | | |
9650 | 9650 | | |
| |||
0 commit comments