From 61d38308005719f70f281eb7aae6245485cc4a87 Mon Sep 17 00:00:00 2001 From: Marcus Pasell <3690498+rickyrombo@users.noreply.github.com> Date: Thu, 23 Apr 2026 15:28:06 -0700 Subject: [PATCH 1/2] Fix primary key column order in test schema to match production Put entity ID columns first and txhash last in all composite primary keys, matching the production DP schema. Mismatched PK column order causes the btree index to be useless for entity lookups in tests, masking performance issues that wouldn't appear in production. Tables fixed: users, tracks, playlists, follows, saves, reposts, developer_apps, grants, subscriptions, dashboard_wallet_users Co-Authored-By: Claude Opus 4.6 --- sql/01_schema.sql | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sql/01_schema.sql b/sql/01_schema.sql index d2e4cd6e..4924ce1e 100644 --- a/sql/01_schema.sql +++ b/sql/01_schema.sql @@ -9914,7 +9914,7 @@ ALTER TABLE ONLY public.countries -- ALTER TABLE ONLY public.dashboard_wallet_users - ADD CONSTRAINT dashboard_wallet_users_pkey PRIMARY KEY (wallet); + ADD CONSTRAINT dashboard_wallet_users_pkey PRIMARY KEY (user_id, wallet); -- @@ -9930,7 +9930,7 @@ ALTER TABLE ONLY public.delist_status_cursor -- ALTER TABLE ONLY public.developer_apps - ADD CONSTRAINT developer_apps_pkey PRIMARY KEY (txhash, address); + ADD CONSTRAINT developer_apps_pkey PRIMARY KEY (address, txhash); -- @@ -9986,7 +9986,7 @@ ALTER TABLE ONLY public.events -- ALTER TABLE ONLY public.follows - ADD CONSTRAINT follows_pkey PRIMARY KEY (followee_user_id, txhash, follower_user_id); + ADD CONSTRAINT follows_pkey PRIMARY KEY (follower_user_id, followee_user_id, txhash); -- @@ -9994,7 +9994,7 @@ ALTER TABLE ONLY public.follows -- ALTER TABLE ONLY public.grants - ADD CONSTRAINT grants_pkey PRIMARY KEY (user_id, txhash, grantee_address); + ADD CONSTRAINT grants_pkey PRIMARY KEY (grantee_address, user_id, txhash); -- @@ -10138,7 +10138,7 @@ ALTER TABLE ONLY public.playlist_trending_scores -- ALTER TABLE ONLY public.playlists - ADD CONSTRAINT playlists_pkey PRIMARY KEY (txhash, playlist_id); + ADD CONSTRAINT playlists_pkey PRIMARY KEY (playlist_id, txhash); -- @@ -10210,7 +10210,7 @@ ALTER TABLE ONLY public.reported_comments -- ALTER TABLE ONLY public.reposts - ADD CONSTRAINT reposts_pkey PRIMARY KEY (txhash, user_id, repost_item_id, repost_type); + ADD CONSTRAINT reposts_pkey PRIMARY KEY (user_id, repost_item_id, repost_type, txhash); -- @@ -10282,7 +10282,7 @@ ALTER TABLE ONLY public.rpclog -- ALTER TABLE ONLY public.saves - ADD CONSTRAINT saves_pkey PRIMARY KEY (save_item_id, user_id, txhash, save_type); + ADD CONSTRAINT saves_pkey PRIMARY KEY (user_id, save_item_id, save_type, txhash); -- @@ -10570,7 +10570,7 @@ ALTER TABLE ONLY public.stems -- ALTER TABLE ONLY public.subscriptions - ADD CONSTRAINT subscriptions_pkey PRIMARY KEY (txhash, user_id, subscriber_id); + ADD CONSTRAINT subscriptions_pkey PRIMARY KEY (subscriber_id, user_id, txhash); -- @@ -10626,7 +10626,7 @@ ALTER TABLE ONLY public.track_trending_scores -- ALTER TABLE ONLY public.tracks - ADD CONSTRAINT tracks_pkey PRIMARY KEY (txhash, track_id); + ADD CONSTRAINT tracks_pkey PRIMARY KEY (track_id, txhash); -- @@ -10810,7 +10810,7 @@ ALTER TABLE ONLY public.user_tips -- ALTER TABLE ONLY public.users - ADD CONSTRAINT users_pkey PRIMARY KEY (txhash, user_id); + ADD CONSTRAINT users_pkey PRIMARY KEY (user_id, txhash); -- From 3d0d7049df1da8800fa7ed2b5da3a86ecc0e8365 Mon Sep 17 00:00:00 2001 From: Marcus Pasell <3690498+rickyrombo@users.noreply.github.com> Date: Thu, 23 Apr 2026 17:53:39 -0700 Subject: [PATCH 2/2] Revert dashboard_wallet_users PK to (wallet) to match production Production was updated to use PRIMARY KEY (wallet) with a separate index on user_id. Co-Authored-By: Claude Opus 4.6 --- sql/01_schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/01_schema.sql b/sql/01_schema.sql index 4924ce1e..b67440ca 100644 --- a/sql/01_schema.sql +++ b/sql/01_schema.sql @@ -9914,7 +9914,7 @@ ALTER TABLE ONLY public.countries -- ALTER TABLE ONLY public.dashboard_wallet_users - ADD CONSTRAINT dashboard_wallet_users_pkey PRIMARY KEY (user_id, wallet); + ADD CONSTRAINT dashboard_wallet_users_pkey PRIMARY KEY (wallet); --