Skip to content

Commit

Permalink
Merge pull request #2022 from cakephp/mpeveler/bugfix-rename-table-pr…
Browse files Browse the repository at this point in the history
…efix

Fix renaming table not using prefix/suffix on new name
  • Loading branch information
dereuromark committed Oct 12, 2021
2 parents 05c67ce + f8f281d commit dd3fc7f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Phinx/Db/Adapter/TablePrefixAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public function executeActions(Table $table, array $actions)
break;

case $action instanceof RenameTable:
$actions[$k] = new RenameTable($adapterTable, $action->getNewName());
$actions[$k] = new RenameTable($adapterTable, $this->getAdapterTableName($action->getNewName()));
break;

case $action instanceof ChangePrimaryKey:
Expand Down
17 changes: 12 additions & 5 deletions tests/Phinx/Db/Adapter/TablePrefixAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public function actionsProvider()
[new DropTable($table)],
[RemoveColumn::build($table, 'acolumn')],
[RenameColumn::build($table, 'acolumn', 'another')],
[new RenameTable($table, 'new_name')],
[new RenameTable($table, 'new_name'), true],
[new ChangePrimaryKey($table, 'column1')],
[new ChangeComment($table, 'comment1')],
];
Expand All @@ -412,10 +412,17 @@ public function testExecuteActions($action, $checkReferecedTable = false)
$this->assertEquals('pre_my_test_suf', $newActions[0]->getTable()->getName());

if ($checkReferecedTable) {
$this->assertEquals(
'pre_another_table_suf',
$newActions[0]->getForeignKey()->getReferencedTable()->getName()
);
if ($action instanceof AddForeignKey) {
$this->assertEquals(
'pre_another_table_suf',
$newActions[0]->getForeignKey()->getReferencedTable()->getName()
);
} elseif ($action instanceof RenameTable) {
$this->assertEquals(
'pre_new_name_suf',
$newActions[0]->getNewName()
);
}
}
}));

Expand Down

0 comments on commit dd3fc7f

Please sign in to comment.