diff --git a/src/Command/StatusCommand.php b/src/Command/StatusCommand.php index 1c773436..b8489746 100644 --- a/src/Command/StatusCommand.php +++ b/src/Command/StatusCommand.php @@ -64,7 +64,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar 'migrations status -c secondary', 'migrations status -c secondary -f json', 'migrations status --cleanup', - 'Remove *MISSING* migrations from the phinxlog table', + 'Remove *MISSING* migrations from the migration tracking table', ])->addOption('plugin', [ 'short' => 'p', 'help' => 'The plugin to run migrations for', @@ -82,7 +82,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar 'choices' => ['text', 'json'], 'default' => 'text', ])->addOption('cleanup', [ - 'help' => 'Remove MISSING migrations from the phinxlog table', + 'help' => 'Remove MISSING migrations from the migration tracking table', 'boolean' => true, 'default' => false, ]); @@ -123,6 +123,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int } $migrations = $manager->printStatus($format); + $tableName = $manager->getSchemaTableName(); switch ($format) { case 'json': @@ -134,7 +135,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int $io->out($migrationString); break; default: - $this->display($migrations, $io); + $this->display($migrations, $io, $tableName); break; } @@ -146,10 +147,14 @@ public function execute(Arguments $args, ConsoleIo $io): ?int * * @param array $migrations * @param \Cake\Console\ConsoleIo $io The console io + * @param string $tableName The migration tracking table name * @return void */ - protected function display(array $migrations, ConsoleIo $io): void + protected function display(array $migrations, ConsoleIo $io, string $tableName): void { + $io->out(sprintf('using migration table %s', $tableName)); + $io->out(''); + if ($migrations) { $rows = []; $rows[] = ['Status', 'Migration ID', 'Migration Name']; diff --git a/src/Db/Adapter/AdapterInterface.php b/src/Db/Adapter/AdapterInterface.php index 8ada1014..c44af6cd 100644 --- a/src/Db/Adapter/AdapterInterface.php +++ b/src/Db/Adapter/AdapterInterface.php @@ -651,9 +651,9 @@ public function createDatabase(string $name, array $options = []): void; public function hasDatabase(string $name): bool; /** - * Cleanup missing migrations from the phinxlog table + * Cleanup missing migrations from the migration tracking table. * - * Removes entries from the phinxlog table for migrations that no longer exist + * Removes entries from the migrations table for migrations that no longer exist * in the migrations directory (marked as MISSING in status output). * * @return void @@ -715,4 +715,15 @@ public function getIo(): ?ConsoleIo; * @return \Cake\Database\Connection The connection */ public function getConnection(): Connection; + + /** + * Gets the schema table name. + * + * Returns the table name used for migration tracking based on configuration: + * - 'cake_migrations' for unified mode + * - 'phinxlog' or '{plugin}_phinxlog' for legacy mode + * + * @return string The migration tracking table name + */ + public function getSchemaTableName(): string; } diff --git a/src/Db/Adapter/AdapterWrapper.php b/src/Db/Adapter/AdapterWrapper.php index dba0f368..75ee7199 100644 --- a/src/Db/Adapter/AdapterWrapper.php +++ b/src/Db/Adapter/AdapterWrapper.php @@ -572,4 +572,12 @@ public function getIo(): ?ConsoleIo { return $this->getAdapter()->getIo(); } + + /** + * @inheritDoc + */ + public function getSchemaTableName(): string + { + return $this->getAdapter()->getSchemaTableName(); + } } diff --git a/src/Db/Adapter/MigrationsTableStorage.php b/src/Db/Adapter/MigrationsTableStorage.php index e67c40bd..a859d262 100644 --- a/src/Db/Adapter/MigrationsTableStorage.php +++ b/src/Db/Adapter/MigrationsTableStorage.php @@ -60,9 +60,9 @@ public function getVersions(array $orderBy): SelectQuery } /** - * Cleanup missing migrations from the phinxlog table + * Cleanup missing migrations from the migration tracking table. * - * Removes entries from the phinxlog table for migrations that no longer exist + * Removes entries from the migrations table for migrations that no longer exist * in the migrations directory (marked as MISSING in status output). * * @param array $missingVersions The list of missing migration versions. diff --git a/src/Db/Adapter/UnifiedMigrationsTableStorage.php b/src/Db/Adapter/UnifiedMigrationsTableStorage.php index 2562247d..fab2cf68 100644 --- a/src/Db/Adapter/UnifiedMigrationsTableStorage.php +++ b/src/Db/Adapter/UnifiedMigrationsTableStorage.php @@ -47,9 +47,9 @@ public function __construct( } /** - * Cleanup missing migrations from the phinxlog table + * Cleanup missing migrations from the migration tracking table. * - * Removes entries from the phinxlog table for migrations that no longer exist + * Removes entries from the migrations table for migrations that no longer exist * in the migrations directory (marked as MISSING in status output). * * @param array $missingVersions The list of missing migration versions. diff --git a/src/Migration/Manager.php b/src/Migration/Manager.php index 96785b15..bb32ce69 100644 --- a/src/Migration/Manager.php +++ b/src/Migration/Manager.php @@ -1331,9 +1331,23 @@ public function resetSeeds(): void } /** - * Cleanup missing migrations from the phinxlog table + * Gets the schema table name being used for migration tracking. * - * Removes entries from the phinxlog table for migrations that no longer exist + * Returns the actual table name based on current configuration: + * - 'cake_migrations' for unified mode + * - 'phinxlog' or '{plugin}_phinxlog' for legacy mode + * + * @return string The migration tracking table name + */ + public function getSchemaTableName(): string + { + return $this->getEnvironment()->getAdapter()->getSchemaTableName(); + } + + /** + * Cleanup missing migrations from the migration tracking table. + * + * Removes entries from the migrations table for migrations that no longer exist * in the migrations directory (marked as MISSING in status output). * * @return int The number of missing migrations removed @@ -1345,7 +1359,7 @@ public function cleanupMissingMigrations(): int $versions = $env->getVersionLog(); $adapter = $env->getAdapter(); - // Find missing migrations (those in phinxlog but not in filesystem) + // Find missing migrations (those in migration table but not in filesystem) $missingVersions = []; foreach ($versions as $versionId => $versionInfo) { if (!isset($defaultMigrations[$versionId])) { diff --git a/tests/TestCase/Command/StatusCommandTest.php b/tests/TestCase/Command/StatusCommandTest.php index e342d6d4..48acaf22 100644 --- a/tests/TestCase/Command/StatusCommandTest.php +++ b/tests/TestCase/Command/StatusCommandTest.php @@ -28,6 +28,8 @@ public function testExecuteSimple(): void { $this->exec('migrations status -c test'); $this->assertExitSuccess(); + // Check for table name info + $this->assertOutputContains('using migration table'); // Check for headers $this->assertOutputContains('Status'); $this->assertOutputContains('Migration ID');