mince/tools/migrate

35 lines
931 B
Text
Raw Permalink Normal View History

2023-08-16 21:18:12 +00:00
#!/usr/bin/env php
<?php
2024-10-05 14:48:18 +00:00
use Index\Db\Migration\{DbMigrationManager,FsDbMigrationRepo};
2023-08-16 21:18:12 +00:00
require_once __DIR__ . '/../mince.php';
try {
touch(MCR_ROOT . '/.migrating');
chmod(MCR_ROOT . '/.migrating', 0777);
echo 'Creating migration manager...' . PHP_EOL;
$manager = new DbMigrationManager($db);
echo 'Preparing to run migrations...' . PHP_EOL;
$manager->init();
echo 'Creating migration repository...' . PHP_EOL;
$repo = new FsDbMigrationRepo(MCR_DIR_MIG);
echo 'Running migrations...' . PHP_EOL;
$completed = $manager->processMigrations($repo);
if(empty($completed)) {
echo 'There were no migrations to run!' . PHP_EOL;
} else {
echo 'The following migrations have been completed:' . PHP_EOL;
foreach($completed as $migration)
echo ' - ' . $migration . PHP_EOL;
}
echo PHP_EOL;
} finally {
unlink(MCR_ROOT . '/.migrating');
}