1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Console\Commands;
7
8use Illuminate\Console\Command;
9use PDO;
10
11class DbCreate extends Command
12{
13 protected $signature = 'db:create';
14
15 protected $description = 'Create empty databases';
16
17 public function handle()
18 {
19 $defaultConnection = $GLOBALS['cfg']['database']['connections']['mysql'];
20
21 $dsn = isset($defaultConnection['unix_socket'])
22 ? "mysql:unix_socket={$defaultConnection['unix_socket']}"
23 : "mysql:host={$defaultConnection['host']};port={$defaultConnection['port']}";
24
25 $pdo = new PDO($dsn, $defaultConnection['username'], $defaultConnection['password']);
26
27 foreach ($GLOBALS['cfg']['database']['connections'] as $connection) {
28 $db = $connection['database'];
29
30 $this->info("Creating database '{$db}'");
31 $pdo->exec("CREATE DATABASE IF NOT EXISTS {$db} DEFAULT CHARSET utf8mb4");
32 }
33 }
34}