From ccc3d3bef6fa20a8eedc5fb40eb1cf5a45ff93b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Fri, 20 Jan 2017 13:26:57 +0100 Subject: [PATCH] fixes #2508: pass through index options when renaming index on table --- lib/Doctrine/DBAL/Schema/Table.php | 4 +-- .../Doctrine/Tests/DBAL/Schema/TableTest.php | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 70157769839..e44a16119c1 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -253,10 +253,10 @@ public function renameIndex($oldIndexName, $newIndexName = null) unset($this->_indexes[$oldIndexName]); if ($oldIndex->isUnique()) { - return $this->addUniqueIndex($oldIndex->getColumns(), $newIndexName); + return $this->addUniqueIndex($oldIndex->getColumns(), $newIndexName, $oldIndex->getOptions()); } - return $this->addIndex($oldIndex->getColumns(), $newIndexName, $oldIndex->getFlags()); + return $this->addIndex($oldIndex->getColumns(), $newIndexName, $oldIndex->getFlags(), $oldIndex->getOptions()); } /** diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index 3174ff9dbc4..709f72018d4 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -741,6 +741,34 @@ public function testRenameIndex() $this->assertTrue($table->hasIndex('UNIQ_D87F7E0C76FF8CAA78240498')); } + /** + * @group DBAL-2508 + */ + public function testKeepsIndexOptionsOnRenamingRegularIndex() + { + $table = new Table('foo'); + $table->addColumn('id', 'integer'); + $table->addIndex(array('id'), 'idx_bar', array(), array('where' => '1 = 1')); + + $table->renameIndex('idx_bar', 'idx_baz'); + + $this->assertSame(array('where' => '1 = 1'), $table->getIndex('idx_baz')->getOptions()); + } + + /** + * @group DBAL-2508 + */ + public function testKeepsIndexOptionsOnRenamingUniqueIndex() + { + $table = new Table('foo'); + $table->addColumn('id', 'integer'); + $table->addUniqueIndex(array('id'), 'idx_bar', array('where' => '1 = 1')); + + $table->renameIndex('idx_bar', 'idx_baz'); + + $this->assertSame(array('where' => '1 = 1'), $table->getIndex('idx_baz')->getOptions()); + } + /** * @group DBAL-234 * @expectedException \Doctrine\DBAL\Schema\SchemaException