Add repo hygiene rules and ignore secrets
This commit is contained in:
29
server/db/migrate.php
Normal file
29
server/db/migrate.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Database\ConnectionFactory;
|
||||
use Dotenv\Dotenv;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$repoRoot = dirname(__DIR__, 2);
|
||||
if (file_exists($repoRoot . '/.env')) {
|
||||
$dotenv = Dotenv::createImmutable($repoRoot);
|
||||
$dotenv->safeLoad();
|
||||
}
|
||||
|
||||
$pdo = ConnectionFactory::create();
|
||||
|
||||
$migrationsDir = __DIR__ . '/migrations';
|
||||
$files = glob($migrationsDir . '/*.sql');
|
||||
sort($files);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$sql = file_get_contents($file);
|
||||
if ($sql === false) {
|
||||
throw new RuntimeException("Migration nicht lesbar: {$file}");
|
||||
}
|
||||
$pdo->exec($sql);
|
||||
echo "OK: " . basename($file) . PHP_EOL;
|
||||
}
|
||||
Reference in New Issue
Block a user