add user migration

This commit is contained in:
Yisroel Baum 2026-05-17 21:50:24 +03:00
parent 50814ffd60
commit 6fbc1fb4f5
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
5 changed files with 113 additions and 1 deletions

46
backend/bin/migrate Executable file
View file

@ -0,0 +1,46 @@
#!/usr/bin/env php
<?php
use App\Database\Migration;
(static function (): void {
$root = dirname(__DIR__);
require $root . '/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable($root);
$dotenv->safeLoad();
require $root . '/config/database.php';
$migrationsDir = $root . '/database/migrations';
$files = glob($migrationsDir . '/*.php');
if ($files === false || $files === []) {
echo "No migration files found.\n";
exit(0);
}
sort($files);
foreach ($files as $file) {
$className = require $file;
if (! class_exists($className)) {
echo "Migration file {$file} did not define class {$className}\n";
exit(1);
}
$migration = new $className();
if (! $migration instanceof Migration) {
echo "Class {$className} must extend " . Migration::class . "\n";
exit(1);
}
echo "Running {$className}...\n";
$migration->up();
}
echo "Done.\n";
})();