Commit 6190f64
authored
fix(migrations): use ALTER TABLE DISABLE TRIGGER instead of SET session_replication_role (#831)
## Summary
- Replaces `SET LOCAL session_replication_role = replica` with `ALTER
TABLE sol_reward_disbursements DISABLE TRIGGER
on_sol_reward_disbursement` (and a matching `ENABLE TRIGGER` after the
INSERT) in `0201_backfill_missing_reward_disbursements.sql`.
## Why
The migration Job in prod hit:
```
ERROR: permission denied to set parameter "session_replication_role"
```
`session_replication_role` requires a true Postgres superuser. CloudSQL
doesn't expose one — the `cloudsqlsuperuser` role the migration runs as
can do most operations but specifically not this one.
`ALTER TABLE ... DISABLE TRIGGER` only needs table-owner privilege
(which the migration role has) and is rolled back with the surrounding
transaction on failure, so the trigger's enable state is preserved if
anything goes wrong before COMMIT.
Targeting the specific trigger by name (rather than `DISABLE TRIGGER
USER`) keeps the change surgical — unrelated triggers (none in practice
on this table, but defensive) are untouched.
## Test plan
- [ ] Roll the new image; the migration Job should run through without
the permission error.
- [ ] Confirm `on_sol_reward_disbursement` is `tgenabled = 'O'`
(enabled) after the migration completes:
```sql
SELECT tgname, tgenabled FROM pg_trigger
WHERE tgname = 'on_sol_reward_disbursement';
```
- [ ] Confirm no rogue `challenge_reward` notifications were created
from this backfill:
```sql
SELECT COUNT(*) FROM notification
WHERE type = 'challenge_reward' AND timestamp > NOW() - INTERVAL '1
hour';
```
Expected: small (only from concurrent live writes that fired the trigger
normally), not ~29k.
🤖 Generated with [Claude Code](https://claude.com/claude-code)1 parent 05f5548 commit 6190f64
1 file changed
Lines changed: 14 additions & 8 deletions
Lines changed: 14 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
| |||
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
| 94 | + | |
| 95 | + | |
90 | 96 | | |
0 commit comments