Skip to content

Commit 47f960d

Browse files
authored
Show migration table name in status command output (#978)
Display which migration tracking table is being used (cake_migrations or phinxlog) in the status command output. This helps users understand which table format they are using during upgrades. Also updates help text to use generic 'migration tracking table' instead of 'phinxlog' since the table name varies based on configuration.
1 parent 79f7554 commit 47f960d

File tree

7 files changed

+53
-13
lines changed

7 files changed

+53
-13
lines changed

src/Command/StatusCommand.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
6464
'<info>migrations status -c secondary</info>',
6565
'<info>migrations status -c secondary -f json</info>',
6666
'<info>migrations status --cleanup</info>',
67-
'Remove *MISSING* migrations from the phinxlog table',
67+
'Remove *MISSING* migrations from the migration tracking table',
6868
])->addOption('plugin', [
6969
'short' => 'p',
7070
'help' => 'The plugin to run migrations for',
@@ -82,7 +82,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
8282
'choices' => ['text', 'json'],
8383
'default' => 'text',
8484
])->addOption('cleanup', [
85-
'help' => 'Remove MISSING migrations from the phinxlog table',
85+
'help' => 'Remove MISSING migrations from the migration tracking table',
8686
'boolean' => true,
8787
'default' => false,
8888
]);
@@ -123,6 +123,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
123123
}
124124

125125
$migrations = $manager->printStatus($format);
126+
$tableName = $manager->getSchemaTableName();
126127

127128
switch ($format) {
128129
case 'json':
@@ -134,7 +135,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
134135
$io->out($migrationString);
135136
break;
136137
default:
137-
$this->display($migrations, $io);
138+
$this->display($migrations, $io, $tableName);
138139
break;
139140
}
140141

@@ -146,10 +147,14 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
146147
*
147148
* @param array $migrations
148149
* @param \Cake\Console\ConsoleIo $io The console io
150+
* @param string $tableName The migration tracking table name
149151
* @return void
150152
*/
151-
protected function display(array $migrations, ConsoleIo $io): void
153+
protected function display(array $migrations, ConsoleIo $io, string $tableName): void
152154
{
155+
$io->out(sprintf('using migration table <info>%s</info>', $tableName));
156+
$io->out('');
157+
153158
if ($migrations) {
154159
$rows = [];
155160
$rows[] = ['Status', 'Migration ID', 'Migration Name'];

src/Db/Adapter/AdapterInterface.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,9 @@ public function createDatabase(string $name, array $options = []): void;
651651
public function hasDatabase(string $name): bool;
652652

653653
/**
654-
* Cleanup missing migrations from the phinxlog table
654+
* Cleanup missing migrations from the migration tracking table.
655655
*
656-
* Removes entries from the phinxlog table for migrations that no longer exist
656+
* Removes entries from the migrations table for migrations that no longer exist
657657
* in the migrations directory (marked as MISSING in status output).
658658
*
659659
* @return void
@@ -715,4 +715,15 @@ public function getIo(): ?ConsoleIo;
715715
* @return \Cake\Database\Connection The connection
716716
*/
717717
public function getConnection(): Connection;
718+
719+
/**
720+
* Gets the schema table name.
721+
*
722+
* Returns the table name used for migration tracking based on configuration:
723+
* - 'cake_migrations' for unified mode
724+
* - 'phinxlog' or '{plugin}_phinxlog' for legacy mode
725+
*
726+
* @return string The migration tracking table name
727+
*/
728+
public function getSchemaTableName(): string;
718729
}

src/Db/Adapter/AdapterWrapper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,4 +572,12 @@ public function getIo(): ?ConsoleIo
572572
{
573573
return $this->getAdapter()->getIo();
574574
}
575+
576+
/**
577+
* @inheritDoc
578+
*/
579+
public function getSchemaTableName(): string
580+
{
581+
return $this->getAdapter()->getSchemaTableName();
582+
}
575583
}

src/Db/Adapter/MigrationsTableStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public function getVersions(array $orderBy): SelectQuery
6060
}
6161

6262
/**
63-
* Cleanup missing migrations from the phinxlog table
63+
* Cleanup missing migrations from the migration tracking table.
6464
*
65-
* Removes entries from the phinxlog table for migrations that no longer exist
65+
* Removes entries from the migrations table for migrations that no longer exist
6666
* in the migrations directory (marked as MISSING in status output).
6767
*
6868
* @param array $missingVersions The list of missing migration versions.

src/Db/Adapter/UnifiedMigrationsTableStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public function __construct(
4747
}
4848

4949
/**
50-
* Cleanup missing migrations from the phinxlog table
50+
* Cleanup missing migrations from the migration tracking table.
5151
*
52-
* Removes entries from the phinxlog table for migrations that no longer exist
52+
* Removes entries from the migrations table for migrations that no longer exist
5353
* in the migrations directory (marked as MISSING in status output).
5454
*
5555
* @param array $missingVersions The list of missing migration versions.

src/Migration/Manager.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,9 +1331,23 @@ public function resetSeeds(): void
13311331
}
13321332

13331333
/**
1334-
* Cleanup missing migrations from the phinxlog table
1334+
* Gets the schema table name being used for migration tracking.
13351335
*
1336-
* Removes entries from the phinxlog table for migrations that no longer exist
1336+
* Returns the actual table name based on current configuration:
1337+
* - 'cake_migrations' for unified mode
1338+
* - 'phinxlog' or '{plugin}_phinxlog' for legacy mode
1339+
*
1340+
* @return string The migration tracking table name
1341+
*/
1342+
public function getSchemaTableName(): string
1343+
{
1344+
return $this->getEnvironment()->getAdapter()->getSchemaTableName();
1345+
}
1346+
1347+
/**
1348+
* Cleanup missing migrations from the migration tracking table.
1349+
*
1350+
* Removes entries from the migrations table for migrations that no longer exist
13371351
* in the migrations directory (marked as MISSING in status output).
13381352
*
13391353
* @return int The number of missing migrations removed
@@ -1345,7 +1359,7 @@ public function cleanupMissingMigrations(): int
13451359
$versions = $env->getVersionLog();
13461360
$adapter = $env->getAdapter();
13471361

1348-
// Find missing migrations (those in phinxlog but not in filesystem)
1362+
// Find missing migrations (those in migration table but not in filesystem)
13491363
$missingVersions = [];
13501364
foreach ($versions as $versionId => $versionInfo) {
13511365
if (!isset($defaultMigrations[$versionId])) {

tests/TestCase/Command/StatusCommandTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public function testExecuteSimple(): void
2828
{
2929
$this->exec('migrations status -c test');
3030
$this->assertExitSuccess();
31+
// Check for table name info
32+
$this->assertOutputContains('using migration table');
3133
// Check for headers
3234
$this->assertOutputContains('Status');
3335
$this->assertOutputContains('Migration ID');

0 commit comments

Comments
 (0)