fix(purchases): expose updated_at on v_usdc_purchases view#819
Merged
Conversation
v1_users_purchases.go SELECTs purchases_with_content.updated_at through
a CTE wrapping v_usdc_purchases. The view never exposed updated_at,
which crashes the /v1/users/{id}/purchases page with:
ERROR: column purchases_with_content.updated_at does not exist
(SQLSTATE 42703)
Alias sp.created_at as updated_at to keep the legacy API contract
intact. The legacy usdc_purchases table set both columns to
CURRENT_TIMESTAMP at insert and never updated rows, so
created_at = updated_at in practice.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 tasks
rickyrombo
added a commit
that referenced
this pull request
May 18, 2026
…ng (#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>
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
Hotfix for a regression introduced by #816. `/v1/users/{id}/purchases` crashes with:
```
ERROR: column purchases_with_content.updated_at does not exist (SQLSTATE 42703)
```
`api/v1_users_purchases.go:123` selects `purchases_with_content.updated_at` through a CTE wrapping `v_usdc_purchases`, but the view never exposed `updated_at`.
Fix: alias `sp.created_at` as `updated_at` in the view. The legacy `usdc_purchases` table set both columns to `CURRENT_TIMESTAMP` at insert and never updated rows, so `created_at = updated_at` in practice — the alias keeps the API contract intact.
I had this fix as a follow-up commit on the PR #815 branch ("Expose updated_at on v_usdc_purchases view") but it didn't make it into the squash-merge.
Test plan
🤖 Generated with Claude Code