Skip to content

Commit 3a0fe2e

Browse files
dereuromarkclaude
andcommitted
Support unified cake_migrations table
Check Migrations.legacyTables config to use the correct table name. When set to false, use the new 'cake_migrations' table instead of 'phinxlog'. See: cakephp/migrations#965 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent edd963a commit 3a0fe2e

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/Controller/MigrationsController.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace TestHelper\Controller;
44

5+
use Cake\Core\Configure;
56
use Cake\Datasource\ConnectionManager;
67
use Cake\Event\EventInterface;
78
use SebastianBergmann\Diff\Differ;
@@ -103,7 +104,7 @@ public function snapshot() {
103104
if ($code === 0) {
104105
/** @var \Cake\Database\Connection $connection */
105106
$connection = ConnectionManager::get('default');
106-
$connection->execute('DELETE FROM phinxlog WHERE `migration_name` = "Tmp";')->closeCursor();
107+
$connection->execute('DELETE FROM ' . $this->getMigrationsTable() . ' WHERE `migration_name` = "Tmp";')->closeCursor();
107108

108109
$this->Flash->success('Tmp Migration file created');
109110

@@ -237,7 +238,7 @@ public function confirm() {
237238

238239
/** @var \Cake\Database\Connection $connection */
239240
$connection = ConnectionManager::get('default');
240-
$connection->execute('DELETE FROM phinxlog WHERE 1=1')->closeCursor();
241+
$connection->execute('DELETE FROM ' . $this->getMigrationsTable() . ' WHERE 1=1')->closeCursor();
241242

242243
$command = 'bin/cake migrations mark_migrated';
243244
exec('cd ' . ROOT . ' && ' . $command, $output, $code);
@@ -267,4 +268,15 @@ public function confirm() {
267268
public function cleanup() {
268269
}
269270

271+
/**
272+
* @return string
273+
*/
274+
protected function getMigrationsTable(): string {
275+
if (Configure::read('Migrations.legacyTables') === false) {
276+
return 'cake_migrations';
277+
}
278+
279+
return 'phinxlog';
280+
}
281+
270282
}

0 commit comments

Comments
 (0)