Implement full migration running logic
[MAILPOET-4466]
This commit is contained in:
@ -11,17 +11,43 @@ class Migrator {
|
||||
/** @var Repository */
|
||||
private $repository;
|
||||
|
||||
/** @var Runner */
|
||||
private $runner;
|
||||
|
||||
/** @var Store */
|
||||
private $store;
|
||||
|
||||
public function __construct(
|
||||
Repository $repository,
|
||||
Runner $runner,
|
||||
Store $store
|
||||
) {
|
||||
$this->repository = $repository;
|
||||
$this->runner = $runner;
|
||||
$this->store = $store;
|
||||
}
|
||||
|
||||
public function run(): void {
|
||||
$this->store->ensureMigrationsTable();
|
||||
$migrations = $this->getStatus();
|
||||
|
||||
// do not try to run migrations if any are running or failed
|
||||
foreach ($migrations as $migration) {
|
||||
if ($migration['status'] === self::MIGRATION_STATUS_STARTED) {
|
||||
throw MigratorException::runningMigrationsExist();
|
||||
}
|
||||
if ($migration['status'] === self::MIGRATION_STATUS_FAILED) {
|
||||
throw MigratorException::failedMigrationsExist();
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($migrations as $migration) {
|
||||
if ($migration['status'] === self::MIGRATION_STATUS_NEW) {
|
||||
$this->runner->runMigration($migration['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @return array{name: string, status: string, started_at: string|null, completed_at: string|null, error: string|null}[] */
|
||||
public function getStatus(): array {
|
||||
$defined = $this->repository->loadAll();
|
||||
|
Reference in New Issue
Block a user