Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DBAL-2508] Pass through index options when renaming index on table #2611

Merged
merged 1 commit into from
Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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