cakephp / cakephp/phinx

Renaming tables not compatible with --dry-run

Open
#1,711 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
PHP
Stars
4.5k
Forks
884
PR merge metrics
No merged PRs in 30d

Description

When using --dry-run, renaming tables causes Phinx to get confused with names and it's unable to generate the SQL commands. When just running the migrations, it works fine.

I've included example SQL to create a table, a simple migration, and the output when running phinx. I have cut repeated and unnecessary lines from the output, but the pertinent stuff is there.

CREATE TABLE `foo` (
  `old` int(11) unsigned NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`old`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
$foo = $this->table('foo');
$foo->rename('foo2');
$foo->renameColumn('old', 'new');
$foo->update();
trekkeruk: phinx migrate --dry-run
 == 20200303143632 Test: migrating
START TRANSACTION;
ALTER TABLE `foo` CHANGE COLUMN `old` `new` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '';
RENAME TABLE `foo` TO `foo2`;
COMMIT;
INSERT INTO `phinxlog` (`version`, `migration_name`, `start_time`, `end_time`, `breakpoint`) VALUES ('20200303143632', 'Welfare', '2020-03-03 16:39:36', '
2020-03-03 16:39:36', 0);
 == 20200303143632 Test: migrated 0.0186s

All Done. Took 0.0535s

trekkeruk: phinx migrate
 == 20200303143632 Test: migrating
 == 20200303143632 Test: migrated 0.0348s
All Done. Took 0.0630s

trekkeruk: phinx rollback --dry-run
 == 20200303143632 Test: reverting
START TRANSACTION;
RENAME TABLE `foo2` TO `foo`;

In PdoAdapter.php line 212:
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'website.foo' doesn't exist

trekkeruk: phinx rollback
 == 20200303143632 Test: reverting
 == 20200303143632 Test: reverted 0.0379s

All Done. Took 0.0625s

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the shown table and migration using phinx migrate and rollback with --dry-run, then inspect PdoAdapter.php around the reported line 212 and the dry-run migration path. Done means both dry-run commands generate valid SQL without table-name confusion or execution errors, while normal migrations continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, php
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.