Commit 7f4104b
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 fe45ee6 commit 7f4104b
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 | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
0 commit comments