generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
database.php
46 lines (37 loc) · 1.4 KB
/
database.php
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
<?php
$host = '127.0.0.1';
$db = 'default';
$user = 'root';
$pass = '';
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$dsn = "pgsql:host=$host;port=26257;dbname=$db";
try {
$pdo = new PDO($dsn, $user, $pass, $options);
$pdo->exec(<<<heredoc
DROP DATABASE IF EXISTS forge;
DROP USER IF EXISTS forge;
CREATE DATABASE forge;
CREATE USER forge;
GRANT ALL PRIVILEGES ON DATABASE forge TO forge;
heredoc);
$statements = [
'SET CLUSTER SETTING kv.range_merge.queue_interval = \'50ms\';',
'SET CLUSTER SETTING jobs.registry.interval.gc = \'30s\';',
'SET CLUSTER SETTING jobs.registry.interval.cancel = \'180s\';',
'SET CLUSTER SETTING jobs.retention_time = \'15s\';',
'SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;',
'SET CLUSTER SETTING kv.range_split.by_load_merge_delay = \'5s\';',
'ALTER RANGE default CONFIGURE ZONE USING "gc.ttlseconds" = 600;',
'ALTER DATABASE system CONFIGURE ZONE USING "gc.ttlseconds" = 600;',
];
foreach ($statements as $statement) {
$pdo->exec($statement);
}
} catch (PDOException $exception) {
exit('Failed to creating database: ' . $exception->getMessage() . PHP_EOL);
}
echo 'Database & User created' . PHP_EOL;