Description
When a column with an index is being added in a separate migration, this will, when being rolled back, cause an error when the column is being dropped, as the fix from #2040 will try to re-add the index for which the referenced column(s) doesn't exist anymore.
I mistakenly assumed that reversed plans would drop indices before removing columns, however while the inverted commands do indeed generate index drops for the to be removed columns, these index drops are being filtered out by the plans conflict resolution:
phinx/src/Phinx/Db/Plan/Plan.php
Lines 193 to 204 in 3cfd71a
The error can be reproduced using these two migrations, where table creation comes first, and then table alteration. Rolling back the alteration migration will trigger the error.
== 20221014120113 RollbackFailureAlter: reverting
In PdoAdapter.php line 192:
SQLSTATE[HY000]: General error: 1 no such column: foo_id
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class RollbackFailureCreate extends AbstractMigration
{
public function change()
{
$this
->table('test')
->create();
}
}
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class RollbackFailureAlter extends AbstractMigration
{
public function change()
{
$this
->table('test')
->addColumn('foo_id', 'integer')
->addIndex(['foo_id'], ['name' => 'FOO_ID_IDX'])
->update();
}
}