flashii/eeprom
Archived
3
0
Fork 1
This repository has been archived on 2025-03-27. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
eeprom/tools/migrate

37 lines
985 B
Text
Raw Normal View History

2023-10-31 19:54:54 +00:00
#!/usr/bin/env php
<?php
require_once __DIR__ . '/../eeprom.php';
2025-03-22 20:08:22 +00:00
$lockPath = $eeprom->dbCtx->getMigrateLockPath();
2024-12-23 00:52:14 +00:00
if(is_file($lockPath))
die('A migration script is already running.' . PHP_EOL);
2023-10-31 19:54:54 +00:00
2024-12-23 00:52:14 +00:00
touch($lockPath);
try {
2023-10-31 19:54:54 +00:00
echo 'Creating migration manager...' . PHP_EOL;
2025-03-22 20:08:22 +00:00
$manager = $eeprom->dbCtx->createMigrationManager();
2023-10-31 19:54:54 +00:00
echo 'Preparing to run migrations...' . PHP_EOL;
$manager->init();
echo 'Creating migration repository...' . PHP_EOL;
2025-03-22 20:08:22 +00:00
$repo = $eeprom->dbCtx->createMigrationRepo();
2023-10-31 19:54:54 +00:00
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;
2025-01-03 03:46:13 +00:00
} catch(Exception $ex) {
var_dump($ex);
2023-10-31 19:54:54 +00:00
} finally {
2024-12-23 00:52:14 +00:00
unlink($lockPath);
2023-10-31 19:54:54 +00:00
}