Fix priority shift to update in reverse order for SQLite compatibility
This commit is contained in:
parent
59d6cd7721
commit
2fa31ff74c
1 changed files with 6 additions and 2 deletions
|
|
@ -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');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue