Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private function detectRenamedIndexes(array &$addedIndexes, array &$removedIndex
}

$removedIndex = $removedIndexes[$removedIndexKey];
$removedIndexName = strtolower($removedIndex->getName());

@morozov morozov Aug 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array key is an identifier name, not SQL. For the comparator to work correctly with various case/quotedness names, it should do it consistently across the board, not in a single place. Depending on the blast radius, the proper fix belongs to a minor or most like new major release.

$removedIndexName = $removedIndex->getQuotedName($this->platform);

$addedIndex = $addedIndexes[$addedIndexKey];

Expand Down
51 changes: 51 additions & 0 deletions tests/Schema/AbstractComparatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,57 @@ public function testDetectRenameIndex(): void
self::assertEquals('idx_bar', $renamedIndexes['idx_foo']->getObjectName()->toString());
}

/**
* A quoted index name carries case-sensitivity and quoting information that must be preserved
* when it becomes the array key of a renamed index, so that platforms which need to emit an
* explicitly quoted identifier for the old name (e.g. Oracle's ALTER INDEX ... RENAME TO) can
* still tell the name was quoted.
*/
public function testDetectRenameIndexPreservesQuoting(): void
{
$prototype = Table::editor()
->setUnquotedName('foo')
->setColumns(
Column::editor()
->setUnquotedName('foo')
->setTypeName(Types::INTEGER)
->create(),
)
->create();

$table1 = $prototype->edit()
->addIndex(
Index::editor()
->setQuotedName('Idx_Foo')
->setUnquotedColumnNames('foo')
->create(),
)
->create();

$table2 = $prototype->edit()
->addIndex(
Index::editor()
->setUnquotedName('idx_bar')
->setUnquotedColumnNames('foo')
->create(),
)
->create();

$tableDiff = $this->comparator->compareTables($table1, $table2);

self::assertCount(0, $tableDiff->getDroppedIndexes());

$renamedIndexes = $tableDiff->getRenamedIndexes();
self::assertCount(1, $renamedIndexes);

// The old index name must still be recognizable as quoted (wrapped in the platform's
// quote characters) and must preserve the original case, regardless of which character
// the platform uses for quoting (e.g. "Idx_Foo", `Idx_Foo` or [Idx_Foo]).
$oldIndexName = current(array_keys($renamedIndexes));
self::assertMatchesRegularExpression('/^(["`]Idx_Foo["`]|\[Idx_Foo])$/', $oldIndexName);
self::assertEquals('idx_bar', $renamedIndexes[$oldIndexName]->getObjectName()->toString());
}

public function testDetectRenameIndexDisabled(): void
{
$prototype = Table::editor()
Expand Down