diff --git a/src/Console/Commands/MigrateCommand.php b/src/Console/Commands/MigrateCommand.php index a5a82d4..768abbd 100644 --- a/src/Console/Commands/MigrateCommand.php +++ b/src/Console/Commands/MigrateCommand.php @@ -15,18 +15,21 @@ class MigrateCommand implements CommandInterface { } public function dispatch(CommandArgs $args): void { + if($args->getArg(0) === 'rollback') { + echo 'Migration rollback is gone.' . PHP_EOL; + return; + } + touch(MSZ_ROOT . '/.migrating'); chmod(MSZ_ROOT . '/.migrating', 0777); - echo "Creating migration manager.." . PHP_EOL; - $migrationManager = new DatabaseMigrationManager(DB::getPDO(), MSZ_ROOT . '/database'); - $migrationManager->setLogger(function ($log) { - echo $log . PHP_EOL; - }); + try { + echo "Creating migration manager.." . PHP_EOL; + $migrationManager = new DatabaseMigrationManager(DB::getPDO(), MSZ_ROOT . '/database'); + $migrationManager->setLogger(function ($log) { + echo $log . PHP_EOL; + }); - if($args->getArg(0) === 'rollback') { - echo 'Migration rollback is gone.' . PHP_EOL; - } else { $migrationManager->migrate(); $errors = $migrationManager->getErrors(); @@ -39,8 +42,8 @@ class MigrateCommand implements CommandInterface { foreach($errors as $error) echo $error . PHP_EOL; } + } finally { + unlink(MSZ_ROOT . '/.migrating'); } - - unlink(MSZ_ROOT . '/.migrating'); } }