Commit b9591d0
committed
fix(platform-links): prevent duplicate displayOrder via unique constraint and retry
Concurrent createPlatformLink calls both read the same max(displayOrder)
and insert the same value, corrupting link ordering for the user.
- Add @@unique([userId, displayOrder]) to PlatformLink schema with migration
- Wrap createPlatformLink in a retry loop (max 5 attempts) that re-reads
max and retries on P2002 unique constraint violations
- Reorder uses two-phase transaction (temp offset then final values) to
avoid constraint conflicts when adjacent positions swap
- Add platform-link-ordering.test.ts covering concurrency, retry, two-phase
reorder, ordering integrity, and regression scenarios
Closes #4851 parent 6c6a2aa commit b9591d0
5 files changed
Lines changed: 536 additions & 24 deletions
File tree
- apps/backend
- prisma
- migrations/20260612000000_platform_link_unique_display_order
- src
- __tests__
- services
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
| |||
0 commit comments