1
0

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>
This commit is contained in:
2026-03-22 13:45:16 +01:00
parent e06e5bde03
commit 141f0a0155
14 changed files with 487 additions and 300 deletions

View File

@@ -0,0 +1,75 @@
<?php
namespace MintyPHP\Repository\Module;
use MintyPHP\DB;
/**
* Manages the module_migrations tracking table.
*
* All SQL for module migration tracking lives here (strict layering).
*/
final class ModuleMigrationRepository implements ModuleMigrationRepositoryInterface
{
public function ensureTrackingTable(): void
{
DB::query(
'CREATE TABLE IF NOT EXISTS `module_migrations` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`module_id` VARCHAR(64) NOT NULL,
`filename` VARCHAR(255) NOT NULL,
`applied_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `uq_module_migration` (`module_id`, `filename`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci'
);
}
/**
* @return array<string, true> Filenames already applied, keyed by filename
*/
public function getAppliedFilenames(string $moduleId): array
{
$applied = [];
$rows = DB::select('SELECT filename FROM module_migrations WHERE module_id = ?', $moduleId);
foreach ((array) $rows as $row) {
if (!is_array($row)) {
continue;
}
$filename = trim((string) (($row['module_migrations']['filename'] ?? $row['filename'] ?? '')));
if ($filename !== '') {
$applied[$filename] = true;
}
}
return $applied;
}
public function recordApplied(string $moduleId, string $filename): void
{
DB::query(
'INSERT INTO module_migrations (module_id, filename) VALUES (?, ?)',
$moduleId,
$filename
);
}
public function beginTransaction(): void
{
DB::query('START TRANSACTION');
}
public function commit(): void
{
DB::query('COMMIT');
}
public function rollback(): void
{
DB::query('ROLLBACK');
}
public function executeStatement(string $sql): void
{
DB::query($sql);
}
}