PostgreSQL Support (#4486)
Co-authored-by: Matthew Penner <matthew@pterodactyl.io>
This commit is contained in:
parent
21613fa602
commit
3bf5a71802
223 changed files with 912 additions and 1052 deletions
|
@ -40,14 +40,14 @@ class AllocationRepository extends EloquentRepository implements AllocationRepos
|
|||
*/
|
||||
protected function getDiscardableDedicatedAllocations(array $nodes = []): array
|
||||
{
|
||||
$query = Allocation::query()->selectRaw('CONCAT_WS("-", node_id, ip) as result');
|
||||
$query = Allocation::query()->selectRaw('CONCAT_WS(\'-\', node_id, ip) as result');
|
||||
|
||||
if (!empty($nodes)) {
|
||||
$query->whereIn('node_id', $nodes);
|
||||
}
|
||||
|
||||
return $query->whereNotNull('server_id')
|
||||
->groupByRaw('CONCAT(node_id, ip)')
|
||||
->groupByRaw('result')
|
||||
->get()
|
||||
->pluck('result')
|
||||
->toArray();
|
||||
|
@ -89,7 +89,7 @@ class AllocationRepository extends EloquentRepository implements AllocationRepos
|
|||
|
||||
if (!empty($discard)) {
|
||||
$query->whereNotIn(
|
||||
$this->getBuilder()->raw('CONCAT_WS("-", node_id, ip)'),
|
||||
$this->getBuilder()->raw('CONCAT_WS(\'-\', node_id, ip)'),
|
||||
$discard
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use PDO;
|
||||
use RuntimeException;
|
||||
use Illuminate\Http\Request;
|
||||
use Webmozart\Assert\Assert;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Pterodactyl\Repositories\Repository;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
@ -271,7 +274,17 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
|
|||
return sprintf('(%s)', $grammar->parameterize($record));
|
||||
})->implode(', ');
|
||||
|
||||
$statement = "insert ignore into $table ($columns) values $parameters";
|
||||
$driver = DB::getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||
switch ($driver) {
|
||||
case 'mysql':
|
||||
$statement = "insert ignore into $table ($columns) values $parameters";
|
||||
break;
|
||||
case 'pgsql':
|
||||
$statement = "insert into $table ($columns) values $parameters on conflict do nothing";
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unsupported database driver \"$driver\" for insert ignore.");
|
||||
}
|
||||
|
||||
return $this->getBuilder()->getConnection()->statement($statement, $bindings);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
|
|||
public function getUsageStats(Node $node): array
|
||||
{
|
||||
$stats = $this->getBuilder()
|
||||
->selectRaw('IFNULL(SUM(servers.memory), 0) as sum_memory, IFNULL(SUM(servers.disk), 0) as sum_disk')
|
||||
->selectRaw('COALESCE(SUM(servers.memory), 0) as sum_memory, COALESCE(SUM(servers.disk), 0) as sum_disk')
|
||||
->join('servers', 'servers.node_id', '=', 'nodes.id')
|
||||
->where('node_id', '=', $node->id)
|
||||
->first();
|
||||
|
@ -54,7 +54,7 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
|
|||
public function getUsageStatsRaw(Node $node): array
|
||||
{
|
||||
$stats = $this->getBuilder()->select(
|
||||
$this->getBuilder()->raw('IFNULL(SUM(servers.memory), 0) as sum_memory, IFNULL(SUM(servers.disk), 0) as sum_disk')
|
||||
$this->getBuilder()->raw('COALESCE(SUM(servers.memory), 0) as sum_memory, COALESCE(SUM(servers.disk), 0) as sum_disk')
|
||||
)->join('servers', 'servers.node_id', '=', 'nodes.id')->where('node_id', $node->id)->first();
|
||||
|
||||
return collect(['disk' => $stats->sum_disk, 'memory' => $stats->sum_memory])->mapWithKeys(function ($value, $key) use ($node) {
|
||||
|
@ -143,7 +143,7 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
|
|||
{
|
||||
$instance = $this->getBuilder()
|
||||
->select(['nodes.id', 'nodes.fqdn', 'nodes.scheme', 'nodes.daemon_token', 'nodes.daemonListen', 'nodes.memory', 'nodes.disk', 'nodes.memory_overallocate', 'nodes.disk_overallocate'])
|
||||
->selectRaw('IFNULL(SUM(servers.memory), 0) as sum_memory, IFNULL(SUM(servers.disk), 0) as sum_disk')
|
||||
->selectRaw('COALESCE(SUM(servers.memory), 0) as sum_memory, COALESCE(SUM(servers.disk), 0) as sum_disk')
|
||||
->leftJoin('servers', 'servers.node_id', '=', 'nodes.id')
|
||||
->where('nodes.id', $node_id);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue