Skip to content

Swap purchase readers from usdc_purchases to v_usdc_purchases#816

Open
rickyrombo wants to merge 1 commit into
mainfrom
mp/purchases-swap-reads-to-view
Open

Swap purchase readers from usdc_purchases to v_usdc_purchases#816
rickyrombo wants to merge 1 commit into
mainfrom
mp/purchases-swap-reads-to-view

Conversation

@rickyrombo
Copy link
Copy Markdown
Contributor

Summary

Step 2 of the purchases-domain cutover. Depends on #815 (backfill + view + trigger).

All ~17 Go API routes that joined usdc_purchases swap to v_usdc_purchases. Once #815 lands first, this PR's base auto-updates to main and 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_payments instead of usdc_purchases.

Route changes (17 files)

v_usdc_purchases swapped in for usdc_purchases in:

  • api/v1_users_purchases.go, _count.go, _download.go
  • api/v1_users_sales.go, _count.go, _aggregate.go, _download.go
  • api/v1_users_purchasers.go, _count.go
  • api/v1_explore_best_selling.go
  • api/v1_users_library_tracks.go, v1_users_library_playlists.go
  • api/comms_blasts.go, api/comms/chat.go, api/comms/validator.go
  • api/dbv1/access.go

Test fixture changes (15 files)

Each test that fixtured usdc_purchases now seeds sol_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's users.spl_usdc_payout_wallet is set to match the corresponding sol_payments.to_account so the view's resolution chain produces the expected user_id.

The global testdata.UsdcPurchasesFixtures (consumed by testAppWithFixtures) is replaced with SolPurchasesFixtures + SolPaymentsFixtures, and server_test.go:105 seeds both.

database/seed.go gains baseRow entries for sol_purchases, sol_payments, and album_price_history.

Test plan

  • go build ./... clean (verified locally)
  • go vet ./... clean (verified locally)
  • go test ./api/... green against a running test postgres
  • Spot-check a prod replica: SELECT * FROM v_usdc_purchases LIMIT 10 returns plausible rows after Backfill sol_purchases from usdc_purchases #815 is deployed
  • Smoke-check the affected endpoints in dev:
    • /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=purchase
    • Chat blasts with customer_audience

Not in this PR

  • Python index_payment_router keeps writing usdc_purchases (the legacy notification trigger also keeps firing, dedupes via shared group_id with the new trigger from Backfill sol_purchases from usdc_purchases #815).
  • vendor is dropped from notifications (frontends must tolerate null).
  • seller_user_id is now the current content owner, not snapshotted at purchase time. Acceptable per design discussion.

🤖 Generated with Claude Code

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>
@rickyrombo rickyrombo force-pushed the mp/purchases-swap-reads-to-view branch from 3464333 to dc8966c Compare May 15, 2026 23:36
@rickyrombo rickyrombo changed the base branch from mp/purchases-backfill-sol-purchases to main May 15, 2026 23:36
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