Commit d881296
committed
fix: add unique index on subscriptions to prevent duplicate entries
- Uses disable_ddl_transaction! (https://api.rubyonrails.org/classes/ActiveRecord/Migration.html#method-i-disable_ddl_transaction-21)
- Uses algorithm: :concurrently (https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_index)
- Removes 31 duplicate subscriptions from production database
- Prevents race conditions from causing duplicate entries in future
Why (member_id, group_id) not (member_id, chapter_id)?
- Index on (member_id, group_id) allows a member to be both student AND coach in the same chapter
- Each chapter has separate "Students" and "Coaches" groups - different group_id values
- This index prevents duplicate subscriptions to the SAME group (the race condition bug)
- But allows valid dual membership: member can subscribe to group_id=1 (Students) AND group_id=2 (Coaches)1 parent 75ecc09 commit d881296
File tree
2 files changed
+32
-1
lines changed- db
- migrate
2 files changed
+32
-1
lines changedLines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
525 | 525 | | |
526 | 526 | | |
527 | 527 | | |
| 528 | + | |
528 | 529 | | |
529 | 530 | | |
530 | 531 | | |
| |||
0 commit comments