refactor(cli)!: hard-cut legacy scripts and standardize console runtime
- remove legacy bin/module-*.php and bin/doctor.php entry scripts - move module/doctor execution into class-based runners under lib/Console - add stable JSON output for doctor and module:sync - introduce bin/dev for init/up/down/logs/console/qa workflow - update DI wiring, phpstan scan config, tests, and docs to new CLI contract
This commit is contained in:
@@ -24,20 +24,21 @@ final class ModuleMigrationService
|
||||
/**
|
||||
* Apply all pending module migrations.
|
||||
*
|
||||
* @return array{ok: bool, applied: int}
|
||||
* @return array{ok: bool, applied: int, skipped_empty: int, modules_enabled: int}
|
||||
*/
|
||||
public function applyPendingMigrations(): array
|
||||
{
|
||||
$modules = $this->registry->getModules();
|
||||
$modulesEnabled = count($modules);
|
||||
|
||||
if (count($modules) === 0) {
|
||||
fwrite(STDOUT, "module-migrate: no modules enabled, nothing to do.\n");
|
||||
return ['ok' => true, 'applied' => 0];
|
||||
if ($modulesEnabled === 0) {
|
||||
return ['ok' => true, 'applied' => 0, 'skipped_empty' => 0, 'modules_enabled' => 0];
|
||||
}
|
||||
|
||||
$this->repository->ensureTrackingTable();
|
||||
|
||||
$totalApplied = 0;
|
||||
$skippedEmpty = 0;
|
||||
|
||||
foreach ($modules as $manifest) {
|
||||
$migrationsPath = $manifest->migrationsPath;
|
||||
@@ -61,12 +62,10 @@ final class ModuleMigrationService
|
||||
|
||||
$sql = file_get_contents($file);
|
||||
if ($sql === false || trim($sql) === '') {
|
||||
fwrite(STDERR, sprintf("module-migrate: WARNING skipping empty file %s/%s\n", $manifest->id, $filename));
|
||||
$skippedEmpty++;
|
||||
continue;
|
||||
}
|
||||
|
||||
fwrite(STDOUT, sprintf("module-migrate: applying %s/%s ... ", $manifest->id, $filename));
|
||||
|
||||
$this->repository->beginTransaction();
|
||||
try {
|
||||
$statements = SqlStatementParser::splitStatements($sql);
|
||||
@@ -85,17 +84,15 @@ final class ModuleMigrationService
|
||||
);
|
||||
}
|
||||
|
||||
fwrite(STDOUT, "OK\n");
|
||||
$totalApplied++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($totalApplied === 0) {
|
||||
fwrite(STDOUT, "module-migrate: all modules up to date, 0 new migrations.\n");
|
||||
} else {
|
||||
fwrite(STDOUT, sprintf("module-migrate: applied %d migration(s).\n", $totalApplied));
|
||||
}
|
||||
|
||||
return ['ok' => true, 'applied' => $totalApplied];
|
||||
return [
|
||||
'ok' => true,
|
||||
'applied' => $totalApplied,
|
||||
'skipped_empty' => $skippedEmpty,
|
||||
'modules_enabled' => $modulesEnabled,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user