From af1e0361589e44f36785dc95012ad2490f9affa3 Mon Sep 17 00:00:00 2001 From: Marcus Pasell <3690498+rickyrombo@users.noreply.github.com> Date: Tue, 19 May 2026 10:22:39 -0700 Subject: [PATCH] fix(migrations): use ALTER TABLE DISABLE TRIGGER instead of SET session_replication_role MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous version of 0201 used `SET LOCAL session_replication_role = replica` to skip the on_sol_reward_disbursement trigger during the backfill. That parameter requires a true superuser, which CloudSQL doesn't expose — `cloudsqlsuperuser` (which the migration role is in) can't set it, producing: ERROR: permission denied to set parameter "session_replication_role" Switch to `ALTER TABLE ... DISABLE TRIGGER on_sol_reward_disbursement` + re-enable after the INSERT. Both DDL statements only require table- owner privilege (which the migration role has) and are rolled back with the transaction on failure, so the trigger state is preserved if anything goes wrong. Targets the specific trigger by name rather than DISABLE TRIGGER USER so unrelated triggers (none in practice on this table, but defensive) aren't affected. --- ..._backfill_missing_reward_disbursements.sql | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ddl/migrations/0201_backfill_missing_reward_disbursements.sql b/ddl/migrations/0201_backfill_missing_reward_disbursements.sql index 39a5d2b6..189626ec 100644 --- a/ddl/migrations/0201_backfill_missing_reward_disbursements.sql +++ b/ddl/migrations/0201_backfill_missing_reward_disbursements.sql @@ -42,14 +42,18 @@ CREATE INDEX IF NOT EXISTS sol_claimable_accounts_eth_mint_slot_idx ON sol_claimable_accounts (ethereum_address, mint, slot DESC); --- Skip the on_sol_reward_disbursement trigger for this transaction. The --- trigger fires per-row to create challenge_reward notifications and a --- pg_notify announcement for the Python ChallengeEventBus. For a one-shot --- backfill of months-old disbursements, those notifications would be --- both noisy (~29k user-facing pushes for historical rewards) and slow --- (extra SELECTs and an INSERT per row). SET LOCAL scopes this to the --- transaction so concurrent indexer writes still fire the trigger normally. -SET LOCAL session_replication_role = replica; +-- Disable the on_sol_reward_disbursement trigger for the duration of the +-- backfill. The trigger fires per-row to create challenge_reward +-- notifications and a pg_notify announcement for the Python +-- ChallengeEventBus. For a one-shot backfill of months-old disbursements, +-- those notifications would be both noisy (~29k user-facing pushes for +-- historical rewards) and slow (extra SELECTs and an INSERT per row). +-- +-- ALTER TABLE ... DISABLE TRIGGER is rolled back with the transaction if +-- the INSERT fails, so the trigger state is preserved on error. CloudSQL +-- doesn't permit `SET session_replication_role` (requires true superuser), +-- so this is the available mechanism here. +ALTER TABLE sol_reward_disbursements DISABLE TRIGGER on_sol_reward_disbursement; -- Pre-compute the current AUDIO claimable account per wallet in one indexed -- scan rather than re-running the LATERAL subquery per challenge_disbursements @@ -87,4 +91,6 @@ JOIN user_banks ub WHERE rd.signature IS NULL ON CONFLICT (signature, instruction_index) DO NOTHING; +ALTER TABLE sol_reward_disbursements ENABLE TRIGGER on_sol_reward_disbursement; + COMMIT;