Skip to content

Commit dc8966c

Browse files
rickyromboclaude
andcommitted
Swap purchase readers from usdc_purchases to v_usdc_purchases
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>
1 parent 1cbd4a6 commit dc8966c

32 files changed

Lines changed: 295 additions & 846 deletions

api/comms/chat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ func getNewBlasts(tx dbv1.DBTX, ctx context.Context, arg getNewBlastsParams) ([]
393393
OR from_user_id IN (
394394
-- customer_audience
395395
SELECT seller_user_id
396-
FROM usdc_purchases p
396+
FROM v_usdc_purchases p
397397
WHERE blast.audience = 'customer_audience'
398398
AND p.seller_user_id = blast.from_user_id
399399
AND p.buyer_user_id = @user_id

api/comms/chat_blast_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -773,16 +773,8 @@ func TestChatBlastPurchasers(t *testing.T) {
773773
"owner_id": 1,
774774
},
775775
},
776-
"usdc_purchases": {
777-
{
778-
"buyer_user_id": 203,
779-
"seller_user_id": 1,
780-
"content_type": "track",
781-
"content_id": 1,
782-
"amount": 5990000, // 5.99USDC in micro-units
783-
"signature": "purchase_sig_123",
784-
"slot": 101,
785-
},
776+
"sol_purchases": {
777+
{"signature": "purchase_sig_123", "instruction_index": 0, "buyer_user_id": 203, "content_type": "track", "content_id": 1, "amount": 5990000, "slot": 101, "is_valid": true},
786778
},
787779
})
788780

api/comms/validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ func hasNewBlastFromUser(pool *dbv1.DBPools, ctx context.Context, userID int32,
623623
-- customer_audience
624624
(blast.audience = 'customer_audience' and exists (
625625
SELECT 1
626-
FROM usdc_purchases p
626+
FROM v_usdc_purchases p
627627
WHERE p.seller_user_id = blast.from_user_id
628628
AND p.buyer_user_id = $1
629629
AND (

api/comms_blasts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (app *ApiServer) getNewBlasts(c *fiber.Ctx) error {
7878
OR from_user_id IN (
7979
-- customer_audience
8080
SELECT seller_user_id
81-
FROM usdc_purchases p
81+
FROM v_usdc_purchases p
8282
WHERE blast.audience = 'customer_audience'
8383
AND p.seller_user_id = blast.from_user_id
8484
AND p.buyer_user_id = @user_id

api/comms_blasts_test.go

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -97,37 +97,10 @@ func TestGetNewBlasts(t *testing.T) {
9797
"child_track_id": 2,
9898
},
9999
},
100-
"usdc_purchases": {
101-
{
102-
"buyer_user_id": 2,
103-
"seller_user_id": 1,
104-
"content_type": "track",
105-
"content_id": 1,
106-
"amount": 1000000, // 1 USDC in micro-units
107-
"created_at": now.Add(-time.Hour * 2), // Purchase before blast
108-
"signature": "purchase_sig_123",
109-
"slot": 101,
110-
},
111-
{
112-
"buyer_user_id": 2,
113-
"seller_user_id": 1,
114-
"content_type": "track",
115-
"content_id": 2,
116-
"amount": 2000000, // 2 USDC in micro-units
117-
"created_at": now.Add(-time.Hour * 2), // Purchase before blast
118-
"signature": "purchase_sig_456",
119-
"slot": 102,
120-
},
121-
{
122-
"buyer_user_id": 3,
123-
"seller_user_id": 1,
124-
"content_type": "track",
125-
"content_id": 1, // User 3 only bought track 1, not track 2
126-
"amount": 500000, // 0.5 USDC in micro-units
127-
"created_at": now.Add(-time.Hour * 2), // Purchase before blast
128-
"signature": "purchase_sig_789",
129-
"slot": 103,
130-
},
100+
"sol_purchases": {
101+
{"signature": "purchase_sig_123", "instruction_index": 0, "buyer_user_id": 2, "content_type": "track", "content_id": 1, "amount": 1000000, "created_at": now.Add(-time.Hour * 2), "slot": 101, "is_valid": true},
102+
{"signature": "purchase_sig_456", "instruction_index": 0, "buyer_user_id": 2, "content_type": "track", "content_id": 2, "amount": 2000000, "created_at": now.Add(-time.Hour * 2), "slot": 102, "is_valid": true},
103+
{"signature": "purchase_sig_789", "instruction_index": 0, "buyer_user_id": 3, "content_type": "track", "content_id": 1, "amount": 500000, "created_at": now.Add(-time.Hour * 2), "slot": 103, "is_valid": true},
131104
},
132105
"artist_coins": {
133106
{
@@ -665,17 +638,8 @@ func TestGetNewBlastsAudienceSpecificFiltering(t *testing.T) {
665638
"updated_at": now.Add(-time.Hour),
666639
},
667640
},
668-
"usdc_purchases": {
669-
{
670-
"buyer_user_id": 2,
671-
"seller_user_id": 1,
672-
"content_type": "track",
673-
"content_id": 1, // User only bought track 1
674-
"amount": 1000000,
675-
"created_at": now.Add(-time.Hour),
676-
"signature": "purchase_sig_123",
677-
"slot": 101,
678-
},
641+
"sol_purchases": {
642+
{"signature": "purchase_sig_123", "instruction_index": 0, "buyer_user_id": 2, "content_type": "track", "content_id": 1, "amount": 1000000, "created_at": now.Add(-time.Hour), "slot": 101, "is_valid": true},
679643
},
680644
"chat_blast": {
681645
{

api/dbv1/access.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (q *Queries) GetPlaylistAccess(
6363
err := q.db.QueryRow(ctx, `
6464
SELECT EXISTS (
6565
SELECT 1
66-
FROM usdc_purchases
66+
FROM v_usdc_purchases
6767
WHERE buyer_user_id = $1
6868
AND content_id = $2
6969
AND content_type = 'album'
@@ -261,7 +261,7 @@ func (q *Queries) GetBulkTrackAccess(
261261
g.Go(func() error {
262262
rows, err := q.db.Query(ctx, `
263263
SELECT content_id
264-
FROM usdc_purchases
264+
FROM v_usdc_purchases
265265
WHERE buyer_user_id = $1
266266
AND content_id = ANY($2)
267267
AND content_type = 'track'
@@ -357,7 +357,7 @@ func (q *Queries) GetBulkTrackAccess(
357357
g.Go(func() error {
358358
rows, err := q.db.Query(ctx, `
359359
SELECT content_id
360-
FROM usdc_purchases
360+
FROM v_usdc_purchases
361361
WHERE buyer_user_id = $1
362362
AND content_id = ANY($2)
363363
AND content_type = 'album'
@@ -390,7 +390,7 @@ func (q *Queries) GetBulkTrackAccess(
390390
g.Go(func() error {
391391
rows, err := q.db.Query(ctx, `
392392
SELECT up.content_id
393-
FROM usdc_purchases up
393+
FROM v_usdc_purchases up
394394
JOIN jsonb_each_text($2) AS prev_playlists(playlist_id, removal_time)
395395
ON up.content_id = prev_playlists.playlist_id::integer
396396
WHERE up.buyer_user_id = $1

api/server_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ func testAppWithFixtures(t *testing.T) *ApiServer {
102102
database.SeedTable(app.pool.Replicas[0], "track_trending_scores", testdata.TrackTrendingScoresFixtures)
103103
database.SeedTable(app.pool.Replicas[0], "trending_results", testdata.TrendingResultsFixtures)
104104
database.SeedTable(app.pool.Replicas[0], "track_routes", testdata.TrackRoutesFixtures)
105-
database.SeedTable(app.pool.Replicas[0], "usdc_purchases", testdata.UsdcPurchasesFixtures)
105+
database.SeedTable(app.pool.Replicas[0], "sol_purchases", testdata.SolPurchasesFixtures)
106+
database.SeedTable(app.pool.Replicas[0], "sol_payments", testdata.SolPaymentsFixtures)
106107
database.SeedTable(app.pool.Replicas[0], "usdc_transactions_history", testdata.UsdcTransactionsHistoryFixtures)
107108
database.SeedTable(app.pool.Replicas[0], "user_bank_accounts", testdata.UserBankAccountsFixtures)
108109
database.SeedTable(app.pool.Replicas[0], "user_challenges", testdata.UserChallengesFixtures)
Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,30 @@
11
package testdata
22

3-
var UsdcPurchasesFixtures = []map[string]any{
3+
// SolPurchasesFixtures + SolPaymentsFixtures populate the new tables backing
4+
// v_usdc_purchases. Maintained alongside the legacy UsdcPurchasesFixtures
5+
// during the purchases-cutover transition.
6+
var SolPurchasesFixtures = []map[string]any{
47
{
5-
"signature": "a",
6-
"buyer_user_id": 11,
7-
"seller_user_id": 3,
8-
"content_id": 303,
9-
"content_type": "track",
10-
"amount": 135,
11-
"splits": []map[string]any{
12-
{
13-
"amount": 135000000,
14-
"user_id": 3,
15-
"eth_wallet": "0x123",
16-
"percentage": 100,
17-
},
18-
},
8+
"signature": "a",
9+
"instruction_index": 0,
10+
"buyer_user_id": 11,
11+
"content_id": 303,
12+
"content_type": "track",
13+
"amount": 135,
14+
"is_valid": true,
1915
},
2016
{
21-
"signature": "b",
22-
"buyer_user_id": 11,
23-
"seller_user_id": 3,
24-
"content_id": 4,
25-
"content_type": "album",
26-
"amount": 135,
27-
"splits": []map[string]any{
28-
{
29-
"amount": 135000000,
30-
"user_id": 3,
31-
"eth_wallet": "0x123",
32-
"percentage": 100,
33-
},
34-
},
17+
"signature": "b",
18+
"instruction_index": 0,
19+
"buyer_user_id": 11,
20+
"content_id": 4,
21+
"content_type": "album",
22+
"amount": 135,
23+
"is_valid": true,
3524
},
3625
}
3726

38-
// signature,buyer_user_id,seller_user_id,content_id,content_type,amount,splits
39-
// a,11,3,303,track,135,"[{""amount"": 135000000, ""user_id"": 3, ""eth_wallet"": ""0x123"", ""percentage"": 100}]"
40-
// b,11,3,4,album,135,"[{""amount"": 135000000, ""user_id"": 3, ""eth_wallet"": ""0x123"", ""percentage"": 100}]"
27+
var SolPaymentsFixtures = []map[string]any{
28+
{"signature": "a", "instruction_index": 0, "route_index": 0, "to_account": "0x123", "amount": 135000000, "slot": 101},
29+
{"signature": "b", "instruction_index": 0, "route_index": 0, "to_account": "0x123", "amount": 135000000, "slot": 101},
30+
}

api/v1_explore_best_selling.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (app *ApiServer) v1ExploreBestSelling(c *fiber.Ctx) error {
4242
sql := `
4343
WITH ranked_sales AS (
4444
SELECT content_id, content_type, COUNT(*) AS sales_count
45-
FROM usdc_purchases
45+
FROM v_usdc_purchases
4646
WHERE ` + strings.Join(filters, " AND ") + `
4747
GROUP BY content_id, content_type
4848
),

0 commit comments

Comments
 (0)