Skip to content

Commit

Permalink
Merge pull request #2611 from deeky666/DBAL-2508
Browse files Browse the repository at this point in the history
[DBAL-2508] Pass through index options when renaming index on table
  • Loading branch information
Ocramius authored Jan 23, 2017
2 parents 4f7df7c + ccc3d3b commit 036abc0
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 036abc0

Please sign in to comment.