Files
breadcrumb-the-shire/bin/module-migrate.php
fs 141f0a0155 refactor: extract shared code from bin/ scripts and remove legacy scheduler runner
- Extract ModuleManifestLoader for standalone manifest loading (used by
  module-deactivate and ValidateCommand)
- Extract SqlStatementParser, ModuleMigrationRepository, and
  ModuleMigrationService from bin/module-migrate.php to enforce strict
  layering (SQL in repository, orchestration in service)
- Delete bin/scheduler-run.php (fully superseded by bin/console scheduler:run)
- Update docs and test fixtures to reference bin/console

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 13:45:16 +01:00

50 lines
1.5 KiB
PHP

#!/usr/bin/env php
<?php
/**
* Applies pending module migrations for all enabled modules.
*
* Usage: php bin/module-migrate.php
*
* Each module declares a migrations_path in its manifest. SQL files in that
* directory are applied in alphabetical order. Applied files are tracked in the
* module_migrations table to ensure idempotency.
*
* Exit codes:
* 0 — all migrations applied (or nothing to do)
* 1 — error during migration
*/
declare(strict_types=1);
use MintyPHP\App\Module\ModuleRegistry;
use MintyPHP\Repository\Module\ModuleMigrationRepository;
use MintyPHP\Service\Module\ModuleMigrationService;
require_once __DIR__ . '/module-cli-bootstrap.php';
function moduleMigrateRun(): int
{
return moduleCliRunStep('module-migrate', static function (): int {
$lockFile = __DIR__ . '/../storage/runtime/.module-migrate.lock';
return moduleCliWithFileLock(
$lockFile,
'module-migrate: another migration run is in progress, skipping.',
static function (): int {
$service = new ModuleMigrationService(
app(ModuleRegistry::class),
new ModuleMigrationRepository()
);
$result = $service->applyPendingMigrations();
return $result['ok'] ? 0 : 1;
}
);
});
}
if (PHP_SAPI === 'cli' && realpath((string) ($_SERVER['SCRIPT_FILENAME'] ?? '')) === __FILE__) {
fwrite(STDERR, "Hint: prefer `php bin/console module:migrate` instead.\n");
exit(moduleMigrateRun());
}