databases()->lockForUpdate()->count() >= $server->database_limit, DisplayException::class, 'Cannot create additional databases on this server: limit has been reached.'); $hosts = DatabaseHost::query()->get()->toBase(); throw_if($hosts->isEmpty(), NoSuitableDatabaseHostException::class); $nodeHosts = $hosts->where('node_id', $server->node_id)->toBase(); throw_if($nodeHosts->isEmpty() && ! config('pterodactyl.client_features.databases.allow_random'), NoSuitableDatabaseHostException::class); $hostId = $data['database_host_id'] ?? null; return $this->createDatabase->create($server, [ 'database_host_id' => $hostId ? (int) $hostId : ($nodeHosts->isEmpty() ? $hosts->random()->id : $nodeHosts->random()->id), 'database' => DatabaseName::generateUnique($data['database'], $server->id), 'remote' => $data['remote'], 'max_connections' => $data['max_connections'] ?? null, ]); }); } }