From 4491ccebd6ce20b60286c9a553effce01aef3db7 Mon Sep 17 00:00:00 2001 From: Marcus Pasell <3690498+rickyrombo@users.noreply.github.com> Date: Thu, 28 May 2026 23:15:46 -0700 Subject: [PATCH] chore(api): drop the unused v_challenge_disbursements view All API reads have been migrated off v_challenge_disbursements (#872), so the compatibility view has no remaining consumers. Drop it via migration 0212, remove the ddl/views definition, and update the schema dump. Deploy ordering: merge/migrate this only after #872's binary is rolled out, so no running code references the dropped view. Note: the removed ddl/views file still carried the pre-0204 case-sensitive join and, because views/ applies after migrations/, was silently reverting the 0204 LOWER(users.wallet) fix. Dropping it removes that footgun. Co-Authored-By: Claude Opus 4.8 --- .../0212_drop_v_challenge_disbursements.sql | 16 +++++++++++++ ddl/views/v_challenge_disbursements.sql | 16 ------------- sql/01_schema.sql | 23 ------------------- sql/03_migration_tracker.sql | 1 + 4 files changed, 17 insertions(+), 39 deletions(-) create mode 100644 ddl/migrations/0212_drop_v_challenge_disbursements.sql delete mode 100644 ddl/views/v_challenge_disbursements.sql diff --git a/ddl/migrations/0212_drop_v_challenge_disbursements.sql b/ddl/migrations/0212_drop_v_challenge_disbursements.sql new file mode 100644 index 00000000..72adb339 --- /dev/null +++ b/ddl/migrations/0212_drop_v_challenge_disbursements.sql @@ -0,0 +1,16 @@ +-- Drop the v_challenge_disbursements compatibility view. +-- +-- The view exposed sol_reward_disbursements in the legacy challenge_disbursements +-- column shape and resolved user_id from recipient_eth_address via users.wallet. +-- Two problems made it a poor fit for most callers: +-- 1. It INNER JOINs users on the recipient wallet, so any disbursement whose +-- recipient does not resolve to a current user is silently dropped. Callers +-- that only ask "has this (challenge_id, specifier) been disbursed?" then +-- wrongly treat a paid reward as still-claimable. +-- 2. Only one caller (the disbursements admin listing) actually needs the +-- user_id resolution, and it now inlines the users join. +-- +-- All callers have been migrated (see preceding PR), so the view has no +-- remaining consumers. This migration must run only after that binary is +-- deployed. +DROP VIEW IF EXISTS v_challenge_disbursements; diff --git a/ddl/views/v_challenge_disbursements.sql b/ddl/views/v_challenge_disbursements.sql deleted file mode 100644 index 6bb478d8..00000000 --- a/ddl/views/v_challenge_disbursements.sql +++ /dev/null @@ -1,16 +0,0 @@ -DROP VIEW IF EXISTS v_challenge_disbursements; -CREATE VIEW v_challenge_disbursements AS - SELECT - rd.challenge_id, - rd.specifier, - rd.amount::text AS amount, - rd.signature, - rd.slot, - rd.created_at, - users.user_id - FROM sol_reward_disbursements rd - JOIN users - ON LOWER(users.wallet) = rd.recipient_eth_address - AND users.is_current = TRUE; - -COMMENT ON VIEW v_challenge_disbursements IS 'Compatibility view that exposes sol_reward_disbursements in the column shape the API routes used to read from challenge_disbursements. Resolves user_id via the indexer-populated recipient_eth_address (see migration 0172).'; diff --git a/sql/01_schema.sql b/sql/01_schema.sql index 281dadfb..dfb89eff 100644 --- a/sql/01_schema.sql +++ b/sql/01_schema.sql @@ -10585,29 +10585,6 @@ CREATE TABLE public.user_tips ( ); --- --- Name: v_challenge_disbursements; Type: VIEW; Schema: public; Owner: - --- - -CREATE VIEW public.v_challenge_disbursements AS - SELECT rd.challenge_id, - rd.specifier, - (rd.amount)::text AS amount, - rd.signature, - rd.slot, - rd.created_at, - users.user_id - FROM (public.sol_reward_disbursements rd - JOIN public.users ON (((lower((users.wallet)::text) = rd.recipient_eth_address) AND (users.is_current = true)))); - - --- --- Name: VIEW v_challenge_disbursements; Type: COMMENT; Schema: public; Owner: - --- - -COMMENT ON VIEW public.v_challenge_disbursements IS 'Compatibility view that exposes sol_reward_disbursements in the column shape the API routes used to read from challenge_disbursements. Resolves user_id via the indexer-populated recipient_eth_address (see migration 0172).'; - - -- -- Name: v_token_transactions_history; Type: VIEW; Schema: public; Owner: - -- diff --git a/sql/03_migration_tracker.sql b/sql/03_migration_tracker.sql index 306f8e49..ad0171a7 100644 --- a/sql/03_migration_tracker.sql +++ b/sql/03_migration_tracker.sql @@ -161,6 +161,7 @@ migrations/0208_seed_challenge_checkpoints.sql ed11876806de4dd1d80b389894b4db45 migrations/0209_user_events_blocknumber_idx.sql 19ed339385266f28e83399125b6593df 2026-05-29 19:30:00.000000+00 migrations/0210_notification_cooldown_partial_gin.sql 7156a9b6e236e17acef7d6b91cb1291b 2026-05-29 19:30:00.100000+00 migrations/0211_seed_phase_3_user_event_checkpoints.sql e37093a8ba1d1a4a3bcca7f98b612be2 2026-05-29 19:30:00.200000+00 +migrations/0212_drop_v_challenge_disbursements.sql 90097355681a3a9b3cde2586511f0f16 2026-05-29 23:22:07.541889+00 \.