fix(purchases): default extra_amount to 0 when price_history is missing#820
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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
🤖 Generated with Claude Code