Commit c8835edf authored by Benjamin Eberlei's avatar Benjamin Eberlei

[DBAL-224] Add API to drop index and pk from tables instances

parent 468af759
...@@ -159,6 +159,32 @@ class Table extends AbstractAsset ...@@ -159,6 +159,32 @@ class Table extends AbstractAsset
return $this->_createIndex($columnNames, $indexName, false, false); return $this->_createIndex($columnNames, $indexName, false, false);
} }
/**
* Drop an index from this table.
*
* @param string $indexName
* @return void
*/
public function dropPrimaryKey()
{
$this->dropIndex($this->_primaryKeyName);
}
/**
* Drop an index from this table.
*
* @param string $indexName
* @return void
*/
public function dropIndex($indexName)
{
$indexName = strtolower($indexName);
if (!$this->hasIndex($indexName)) {
throw SchemaException::indexDoesNotExist($indexName, $this->_name);
}
unset($this->_indexes[$indexName]);
}
/** /**
* *
* @param array $columnNames * @param array $columnNames
......
...@@ -497,4 +497,34 @@ class TableTest extends \Doctrine\Tests\DbalTestCase ...@@ -497,4 +497,34 @@ class TableTest extends \Doctrine\Tests\DbalTestCase
$this->assertEquals('test.test', $table->getFullQualifiedName("test")); $this->assertEquals('test.test', $table->getFullQualifiedName("test"));
$this->assertEquals('other.test', $table->getFullQualifiedName("other")); $this->assertEquals('other.test', $table->getFullQualifiedName("other"));
} }
/**
* @group DBAL-224
*/
public function testDropIndex()
{
$table = new Table("test");
$table->addColumn('id', 'integer');
$table->addIndex(array('id'), 'idx');
$this->assertTrue($table->hasIndex('idx'));
$table->dropIndex('idx');
$this->assertFalse($table->hasIndex('idx'));
}
/**
* @group DBAL-224
*/
public function testDropPrimaryKey()
{
$table = new Table("test");
$table->addColumn('id', 'integer');
$table->setPrimaryKey(array('id'));
$this->assertTrue($table->hasPrimaryKey());
$table->dropPrimaryKey();
$this->assertFalse($table->hasPrimaryKey());
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment