Backfill sol_purchases from usdc_purchases#815
Merged
Conversation
Step 1 of the purchases-domain cutover from Python-indexer tables to the Go indexer's sol_* tables. Adds a created_at column to sol_purchases (parity with the legacy table), backfills historical purchases + their splits from usdc_purchases into sol_purchases and sol_payments, adds the v_usdc_purchases compatibility view, and mirrors the notification trigger onto sol_purchases. Readers stay on the legacy table for now; the route swap is a follow-up PR. Also drops a stale block_timestamp column from the sol_purchases entry in sql/01_schema.sql that no migration creates and nothing references. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
raymondjacobson
approved these changes
May 15, 2026
| city character varying, | ||
| region character varying, | ||
| country character varying, | ||
| block_timestamp timestamp with time zone |
Member
There was a problem hiding this comment.
interesting is this not really important for ordering?
Contributor
Author
There was a problem hiding this comment.
it doesn't exist in production
5 tasks
rickyrombo
added a commit
that referenced
this pull request
May 15, 2026
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>
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 1 of the purchases-domain cutover. This PR populates the new Go-indexer tables with the historical data they're missing today, adds the compatibility view + parallel notification trigger, but leaves all readers on the legacy
usdc_purchasestable. The route swap is a separate PR (step 2) that lands after this one is verified on production.The shape mirrors PR #809 (challenges cutover): bounded migration, view-based read translation, parallel trigger that dedupes via shared
group_id.What's in this PR
Schema / migration —
ddl/migrations/0199_backfill_sol_purchases.sqlcreated_at TIMESTAMP DEFAULT NOW()tosol_purchases. Same gap we hit onsol_reward_disbursementsin Switch challenge reads to sol_reward_disbursements #809.usdc_purchasesintosol_purchases.from_accountis resolved to the buyer's USDC user_bank viausdc_user_bank_accountsso the NOT NULL column has a real value.created_aton rows the Go indexer wrote before this migration (theircreated_atwas justNOW()from the default; corrects them from the legacy table where the legacy value is older).usdc_purchases.splitsJSONB into onesol_paymentsrow per element. Element shape is{payout_wallet, amount, percentage, user_id, eth_wallet}peradd_wallet_info_to_splits()in the Python source.sol_purchases_created_at_idxso the route-side default sort bycreated_atdoesn't degrade.View —
ddl/views/v_usdc_purchases.sqlsol_purchases+sol_paymentsin the legacy column shape so step 2's route swap is mostly a one-token rename.seller_user_idis derived from current content ownership (tracks.owner_id/playlists.playlist_owner_id). Note: this is current owner, not snapshotted at purchase time. Legacy was a snapshot — accepting this drift per design discussion.extra_amountis derived asamount - base_pricevia a correlated subquery againsttrack_price_history/album_price_history(block_timestamp <= purchase created_at, ORDER BY DESC LIMIT 1).splitsJSON is aggregated oversol_paymentswith user_id resolved viaCOALESCE(users.spl_usdc_payout_wallet match, sol_claimable_accounts mint=USDC match). Network-cut payments (to the staking bridge wallet) emituser_id: null.vendoris intentionally dropped from the view.is_valid IS TRUEto match the legacy table's semantics (Python only wrote validated purchases).Trigger —
ddl/functions/handle_usdc_purchase.sqlhandle_sol_purchasefunction andon_sol_purchase AFTER INSERT ON sol_purchasestrigger.group_idformat match the legacy trigger byte-for-byte (verified against the existing function body), so during the backfill — where every inserted row fires the new trigger and tries to recreate notifications whosegroup_ids were created by the legacy trigger long ago —ON CONFLICT DO NOTHINGmakes them no-ops.vendorandextra_amountare emitted asnullin the new payload; downstream consumers must tolerate this.Cleanup —
sql/01_schema.sqlblock_timestampcolumn from thesol_purchasestable definition. No migration creates it and nothing in the repo references it; the dump had drifted from reality.What's NOT in this PR
usdc_purchases(v1_users_purchases,v1_users_sales,v1_users_purchasers,v1_explore_best_selling,v1_users_library_*,v1_fan_club_feed,comms_blasts,dbv1/access.go,comms/chat.go, etc.) are unchanged. Until this PR's backfill is verified in production, swapping readers would risk old purchases disappearing.index_payment_routerkeeps writingusdc_purchases(legacy trigger keeps firing on insert). The new trigger dedupes against it viagroup_id.created_at. A small follow-up:solana/indexer/program/payment_router.goshould explicitly writecreated_atso new rows get the on-chain time rather thanNOW()from the column default. Default is correct-enough until then.vendor: nullnotifications we'll need a workaround.Test plan
After this lands, before opening the step-2 PR, verify on a prod replica:
v_usdc_purchasesagainstusdc_purchasesfor a few signatures: samebuyer_user_id, sameamount, comparablesplits[*].user_idandpayout_wallet.sol_purchasesrow matching an existingusdc_purchasesrow in dev; assert no new notification row appears.statement_timeout, nopg_type_typname_nsp_index, nodeadlock detected.go test ./api/...green (no reader changes, no test changes expected).🤖 Generated with Claude Code