diff --git a/app/Actions/CreateBucketAction.php b/app/Actions/CreateBucketAction.php index 8a09cf7..18ff266 100644 --- a/app/Actions/CreateBucketAction.php +++ b/app/Actions/CreateBucketAction.php @@ -39,10 +39,14 @@ public function execute( // Check if priority already exists and shift others if needed $existingBucket = $scenario->buckets()->where('priority', $priority)->first(); if ($existingBucket) { - // Shift priorities to make room + // Shift priorities in reverse order to avoid unique constraint violations + // (SQLite checks constraints per-row during bulk updates) $scenario->buckets() ->where('priority', '>=', $priority) - ->increment('priority'); + ->orderByDesc('priority') + ->each(function ($bucket) { + $bucket->increment('priority'); + }); } }