Added migrations script
This commit is contained in:
34
scripts/migrations.php
Normal file
34
scripts/migrations.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Medoo\Medoo;
|
||||
|
||||
$dbFile = __DIR__ . '/../database/app.sqlite';
|
||||
if (!file_exists($dbFile)) {
|
||||
if (!is_dir(dirname($dbFile))) {
|
||||
mkdir(dirname($dbFile), 0755, true);
|
||||
}
|
||||
touch($dbFile);
|
||||
chmod($dbFile, 0664);
|
||||
}
|
||||
|
||||
$database = new Medoo([
|
||||
'database_type' => 'sqlite',
|
||||
'database_file' => $dbFile,
|
||||
]);
|
||||
|
||||
// schéma minimal — CREATE TABLE IF NOT EXISTS est idempotent
|
||||
$database->query(
|
||||
<<<'SQL'
|
||||
CREATE TABLE IF NOT EXISTS post (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
content TEXT NOT NULL
|
||||
);
|
||||
SQL
|
||||
);
|
||||
|
||||
echo "Migrations applied (minimal).\n";
|
||||
Reference in New Issue
Block a user