Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Command/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
'<info>migrations status -c secondary</info>',
'<info>migrations status -c secondary -f json</info>',
'<info>migrations status --cleanup</info>',
'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',
Expand All @@ -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,
]);
Expand Down Expand Up @@ -123,6 +123,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
}

$migrations = $manager->printStatus($format);
$tableName = $manager->getSchemaTableName();

switch ($format) {
case 'json':
Expand All @@ -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;
}

Expand All @@ -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 <info>%s</info>', $tableName));
$io->out('');

if ($migrations) {
$rows = [];
$rows[] = ['Status', 'Migration ID', 'Migration Name'];
Expand Down
15 changes: 13 additions & 2 deletions src/Db/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
8 changes: 8 additions & 0 deletions src/Db/Adapter/AdapterWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,12 @@ public function getIo(): ?ConsoleIo
{
return $this->getAdapter()->getIo();
}

/**
* @inheritDoc
*/
public function getSchemaTableName(): string
{
return $this->getAdapter()->getSchemaTableName();
}
}
4 changes: 2 additions & 2 deletions src/Db/Adapter/MigrationsTableStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/Db/Adapter/UnifiedMigrationsTableStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 17 additions & 3 deletions src/Migration/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])) {
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase/Command/StatusCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down