Skip to content

Commit

Permalink
Merge branch 'fix/#2611-#2508-pass-through-index-options-when-renamin…
Browse files Browse the repository at this point in the history
…g-indexes' into 2.5

Backport #2611 to 2.5
Backport #2508 to 2.5
  • Loading branch information
Ocramius committed Jan 23, 2017
2 parents 8a13144 + 2437390 commit fc376f7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Schema/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
28 changes: 28 additions & 0 deletions tests/Doctrine/Tests/DBAL/Schema/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fc376f7

Please sign in to comment.