diff --git a/src/Schema/Comparator.php b/src/Schema/Comparator.php index 02cd6f81d9..f55156aece 100644 --- a/src/Schema/Comparator.php +++ b/src/Schema/Comparator.php @@ -392,7 +392,7 @@ private function detectRenamedIndexes(array &$addedIndexes, array &$removedIndex } $removedIndex = $removedIndexes[$removedIndexKey]; - $removedIndexName = strtolower($removedIndex->getName()); + $removedIndexName = $removedIndex->getQuotedName($this->platform); $addedIndex = $addedIndexes[$addedIndexKey]; diff --git a/tests/Schema/AbstractComparatorTestCase.php b/tests/Schema/AbstractComparatorTestCase.php index 3ea27ddd98..35e34111e9 100644 --- a/tests/Schema/AbstractComparatorTestCase.php +++ b/tests/Schema/AbstractComparatorTestCase.php @@ -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()