Skip to content

Commit b9591d0

Browse files
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 #485
1 parent 6c6a2aa commit b9591d0

5 files changed

Lines changed: 536 additions & 24 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Add unique constraint on (user_id, display_order) to prevent duplicate display orders per user
2+
CREATE UNIQUE INDEX "platform_links_user_id_display_order_key" ON "platform_links"("user_id", "display_order");

apps/backend/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ model PlatformLink {
9292
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
9393
cardLinks CardLink[]
9494
95+
@@unique([userId, displayOrder])
9596
@@map("platform_links")
9697
}
9798

0 commit comments

Comments
 (0)