From e82a3b838c225898a5a051ecb86f7fbb0cc376f3 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Tue, 30 Apr 2024 00:00:03 +0200 Subject: [PATCH] update AllocationSelectionService --- .../Deployment/AllocationSelectionService.php | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/app/Services/Deployment/AllocationSelectionService.php b/app/Services/Deployment/AllocationSelectionService.php index 6076a65c3..bec6dbcf1 100644 --- a/app/Services/Deployment/AllocationSelectionService.php +++ b/app/Services/Deployment/AllocationSelectionService.php @@ -6,6 +6,7 @@ use App\Models\Allocation; use App\Exceptions\DisplayException; use App\Services\Allocations\AssignmentService; use App\Exceptions\Service\Deployment\NoViableAllocationException; +use Illuminate\Support\Facades\DB; class AllocationSelectionService { @@ -121,10 +122,17 @@ class AllocationSelectionService $discard = $this->getDiscardableDedicatedAllocations($nodes); if (!empty($discard)) { - $query->whereNotIn( - Allocation::query()->raw('CONCAT_WS("-", node_id, ip)'), - $discard - ); + if (DB::getDriverName() === 'sqlite') { + $query->whereNotIn( + Allocation::query()->raw('node_id || "-" || ip'), + $discard + ); + } else { + $query->whereNotIn( + Allocation::query()->raw('CONCAT_WS("-", node_id, ip)'), + $discard + ); + } } } @@ -141,6 +149,20 @@ class AllocationSelectionService */ private function getDiscardableDedicatedAllocations(array $nodes = []): array { + if (DB::getDriverName() === 'sqlite') { + $query = Allocation::query()->selectRaw('(node_id || "-" || ip) as result'); + + if (!empty($nodes)) { + $query->whereIn('node_id', $nodes); + } + + return $query->whereNotNull('server_id') + ->groupByRaw('node_id || ip') + ->get() + ->pluck('result') + ->toArray(); + } + $query = Allocation::query()->selectRaw('CONCAT_WS("-", node_id, ip) as result'); if (!empty($nodes)) {