Swap purchase readers from usdc_purchases to v_usdc_purchases#816
Merged
Conversation
Step 2 of the purchases-domain cutover. Now that #815 (step 1) has backfilled sol_purchases and added the compatibility view, all ~17 Go API routes that joined usdc_purchases swap over to v_usdc_purchases. Code changes are minimal — table-name renames in route SQL. The view absorbs the schema differences (sol_purchases + sol_payments + users + tracks/playlists -> legacy column shape). Test fixtures are rewritten: callers seed sol_purchases + sol_payments instead of usdc_purchases. Drops fixture columns the view derives (seller_user_id, extra_amount, splits). For tests that assert on splits user_id, the seller's spl_usdc_payout_wallet is set so the view's lookup resolves. For tests that assert on non-zero extra_amount, a track_price_history row is seeded so the view's amount - base_price computation produces the expected value. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
3464333 to
dc8966c
Compare
raymondjacobson
approved these changes
May 18, 2026
2 tasks
rickyrombo
added a commit
that referenced
this pull request
May 18, 2026
## 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 - [ ] \`/v1/users/{id}/purchases\` returns 200 again - [ ] \`/v1/users/{id}/sales\` (which also selects \`updated_at\` in \`v1_users_sales.go:94\`) returns 200 🤖 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
Step 2 of the purchases-domain cutover. Depends on #815 (backfill + view + trigger).
All ~17 Go API routes that joined
usdc_purchasesswap tov_usdc_purchases. Once #815 lands first, this PR's base auto-updates tomainand only this diff remains.Code changes are mostly one-token table-name renames in route SQL — the view absorbs schema differences. Test fixtures are rewritten to seed
sol_purchases+sol_paymentsinstead ofusdc_purchases.Route changes (17 files)
v_usdc_purchasesswapped in forusdc_purchasesin:api/v1_users_purchases.go,_count.go,_download.goapi/v1_users_sales.go,_count.go,_aggregate.go,_download.goapi/v1_users_purchasers.go,_count.goapi/v1_explore_best_selling.goapi/v1_users_library_tracks.go,v1_users_library_playlists.goapi/comms_blasts.go,api/comms/chat.go,api/comms/validator.goapi/dbv1/access.goTest fixture changes (15 files)
Each test that fixtured
usdc_purchasesnow seedssol_purchases+ (when splits matter)sol_payments+ (when extra_amount matters)track_price_history/album_price_history. Dropped columns the view derives (seller_user_id,extra_amount,splits,access).For tests that assert on
splits[*].user_id, the seller'susers.spl_usdc_payout_walletis set to match the correspondingsol_payments.to_accountso the view's resolution chain produces the expected user_id.The global
testdata.UsdcPurchasesFixtures(consumed bytestAppWithFixtures) is replaced withSolPurchasesFixtures+SolPaymentsFixtures, andserver_test.go:105seeds both.database/seed.gogainsbaseRowentries forsol_purchases,sol_payments, andalbum_price_history.Test plan
go build ./...clean (verified locally)go vet ./...clean (verified locally)go test ./api/...green against a running test postgresSELECT * FROM v_usdc_purchases LIMIT 10returns plausible rows after Backfill sol_purchases from usdc_purchases #815 is deployed/v1/users/{id}/purchases,/sales,/purchasers,/sales/aggregate/v1/users/{id}/purchases/download/{json,csv},/sales/download/{json,csv}/v1/explore/best-selling/v1/full/users/{id}/library/tracks?type=purchase,/library/{albums,playlists}?type=purchasecustomer_audienceNot in this PR
index_payment_routerkeeps writingusdc_purchases(the legacy notification trigger also keeps firing, dedupes via sharedgroup_idwith the new trigger from Backfill sol_purchases from usdc_purchases #815).vendoris dropped from notifications (frontends must toleratenull).seller_user_idis now the current content owner, not snapshotted at purchase time. Acceptable per design discussion.🤖 Generated with Claude Code