run-migrations.php
Pfad: run-migrations.php
Ext: php
Größe: 1312 Bytes
Geändert: 2026-07-16T17:17:36+02:00
Frühere Version vom 2026-07-16T17:17:36+02:00 · zur aktuellen Fassung
<?php
declare(strict_types=1);
use Demo\Autoloader;
use Demo\Infrastructure\Config\CredentialsProvider;
use Demo\Infrastructure\Persistence\MigrationRunner;
use Demo\Infrastructure\Persistence\PdoConnectionFactory;
require __DIR__ . '/src/Autoloader.php';
(new Autoloader(__DIR__ . '/src'))->register();
if (PHP_SAPI !== 'cli') {
fwrite(STDERR, "Nur CLI-Aufruf erlaubt\n");
exit(2);
}
$baseline = null;
foreach (array_slice($argv, 1) as $argument) {
if (preg_match('/^--baseline=(\d{1,4})$/', $argument, $match) === 1) {
$baseline = (int) $match[1];
continue;
}
fwrite(STDERR, "Unbekanntes Argument: {$argument}\n");
exit(2);
}
try {
$credentialsDir = getenv('APP_CREDENTIALS_DIR') ?: __DIR__ . '/credentials';
$credentials = (new CredentialsProvider($credentialsDir))->database();
$pdo = (new PdoConnectionFactory($credentials))->create();
$runner = new MigrationRunner($pdo, __DIR__ . '/migrations', getenv('USER') ?: 'migration-cli');
$result = $runner->run($baseline);
fwrite(STDOUT, json_encode(['ok' => true, 'changes' => $result], JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . "\n");
} catch (Throwable $error) {
fwrite(STDERR, json_encode(['ok' => false, 'error' => $error->getMessage()], JSON_THROW_ON_ERROR) . "\n");
exit(1);
}