|
|
|
@ -6,10 +6,10 @@
|
|
|
|
|
function get_database(): PDO {
|
|
|
|
|
// defined by profiles.
|
|
|
|
|
global $data_source_name;
|
|
|
|
|
// The presence of the .guard file says that the database has already been initialized.
|
|
|
|
|
$database_exists = file_exists(__DIR__ . "/.guard");
|
|
|
|
|
$pdo = new PDO($data_source_name, DATABASE_USER, DATABASE_PASSWORD);
|
|
|
|
|
|
|
|
|
|
$database_exists = $pdo->query("SELECT COUNT(*) FROM sqlite_master WHERE type = 'table'")->fetchColumn() > 0;
|
|
|
|
|
|
|
|
|
|
if ($database_exists) {
|
|
|
|
|
return $pdo;
|
|
|
|
|
}
|
|
|
|
@ -18,19 +18,10 @@ function get_database(): PDO {
|
|
|
|
|
if (preg_match("/.*\.sql$/i", $file)) {
|
|
|
|
|
$content = file_get_contents(__DIR__ . "/" . $file);
|
|
|
|
|
|
|
|
|
|
foreach (preg_split("/;\s*/", $content) as $req) {
|
|
|
|
|
if ($req === "")
|
|
|
|
|
break;
|
|
|
|
|
$pdo->query($req);
|
|
|
|
|
}
|
|
|
|
|
$pdo->exec($content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//FIXME Server will need to explicitly set permissions to the `sql` folder
|
|
|
|
|
// in order for the touch to work
|
|
|
|
|
//
|
|
|
|
|
// Workaround in CI by setting permissions to 777 to the folder
|
|
|
|
|
touch(__DIR__ . "/.guard");
|
|
|
|
|
|
|
|
|
|
return $pdo;
|
|
|
|
|
}
|
|
|
|
|