Fix priority shift to update in reverse order for SQLite compatibility

This commit is contained in:
myrmidex 2026-03-19 01:26:58 +01:00
parent 59d6cd7721
commit 2fa31ff74c

View file

@ -39,10 +39,14 @@ public function execute(
// Check if priority already exists and shift others if needed // Check if priority already exists and shift others if needed
$existingBucket = $scenario->buckets()->where('priority', $priority)->first(); $existingBucket = $scenario->buckets()->where('priority', $priority)->first();
if ($existingBucket) { 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() $scenario->buckets()
->where('priority', '>=', $priority) ->where('priority', '>=', $priority)
->increment('priority'); ->orderByDesc('priority')
->each(function ($bucket) {
$bucket->increment('priority');
});
} }
} }