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