forked from vitodeploy/vito
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgresql.php
More file actions
84 lines (67 loc) · 1.91 KB
/
Copy pathPostgresql.php
File metadata and controls
84 lines (67 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace App\Services\Database;
use App\DTOs\ServiceLog;
use App\Models\DatabaseUser;
use App\Models\Server;
use App\Services\HasLogs;
use Illuminate\Contracts\View\View;
class Postgresql extends AbstractDatabase implements HasLogs
{
protected array $systemDbs = ['template0', 'template1', 'postgres'];
/**
* @var string[]
*/
protected array $systemUsers = ['postgres'];
protected string $defaultCharset = 'UTF8';
protected int $headerLines = 2;
protected string $separator = '|';
protected bool $removeLastRow = true;
public function usesHost(): bool
{
return false;
}
public function databaseUserExists(Server $server, string $username, string $host, ?DatabaseUser $ignore = null): bool
{
return $server->databaseUsers()
->where('username', $username)
->when($ignore, fn ($query) => $query->whereKeyNot($ignore->id))
->exists();
}
public static function id(): string
{
return 'postgresql';
}
public static function type(): string
{
return 'database';
}
public function unit(): string
{
return 'postgresql';
}
protected function installScript(): View
{
return view($this->getScriptView('install'), [
'version' => $this->service->version,
]);
}
public function version(): string
{
$version = $this->service->server->ssh()->exec(
'psql --version | grep -oE \'[0-9]+\.[0-9]+(\.[0-9]+)?\' | head -n 1'
);
return trim($version);
}
public function logs(): array
{
return [
new ServiceLog(
key: 'postgresql:journal',
serviceLabel: 'PostgreSQL',
label: 'Service journal',
source: ServiceLog::SOURCE_JOURNAL,
target: 'postgresql.service',
),
];
}
}