[2.0] DDC-302 - Drop convenience methods since their API is somewhat strange, have to think about something else. Dropped AbstractSchemaManager::listTableConstraints() support - since it only returns the names of all constraints, which are already returned much more nicely with listTableIndexes().
This commit is contained in:
parent
ae6e597dca
commit
3de3bbb969
@ -155,7 +155,7 @@ abstract class AbstractSchemaManager
|
|||||||
/**
|
/**
|
||||||
* List the available sequences for this connection
|
* List the available sequences for this connection
|
||||||
*
|
*
|
||||||
* @return array $sequences
|
* @return Sequence[]
|
||||||
*/
|
*/
|
||||||
public function listSequences($database = null)
|
public function listSequences($database = null)
|
||||||
{
|
{
|
||||||
@ -169,39 +169,9 @@ abstract class AbstractSchemaManager
|
|||||||
return $this->_getPortableSequencesList($sequences);
|
return $this->_getPortableSequencesList($sequences);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* List the constraints for a given table
|
|
||||||
*
|
|
||||||
* @param string $table The name of the table
|
|
||||||
* @return array $tableConstraints
|
|
||||||
*/
|
|
||||||
public function listTableConstraints($table)
|
|
||||||
{
|
|
||||||
$sql = $this->_platform->getListTableConstraintsSql($table);
|
|
||||||
|
|
||||||
$tableConstraints = $this->_conn->fetchAll($sql);
|
|
||||||
|
|
||||||
return $this->_getPortableTableConstraintsList($tableConstraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List the columns for a given table.
|
* List the columns for a given table.
|
||||||
*
|
*
|
||||||
* @example array(
|
|
||||||
* 'colA' => array(
|
|
||||||
* 'name' => 'colA',
|
|
||||||
* 'type' => \Doctrine\DBAL\Types\StringType instance,
|
|
||||||
* 'length' => 255,
|
|
||||||
* 'precision' => null,
|
|
||||||
* 'scale' => null,
|
|
||||||
* 'unsigned' => false,
|
|
||||||
* 'fixed' => false,
|
|
||||||
* 'notnull' => false,
|
|
||||||
* 'default' => null,
|
|
||||||
* 'platformDetails' => array(),
|
|
||||||
* ),
|
|
||||||
* );
|
|
||||||
*
|
|
||||||
* In contrast to other libraries and to the old version of Doctrine,
|
* In contrast to other libraries and to the old version of Doctrine,
|
||||||
* this column definition does try to contain the 'primary' field for
|
* this column definition does try to contain the 'primary' field for
|
||||||
* the reason that it is not portable accross different RDBMS. Use
|
* the reason that it is not portable accross different RDBMS. Use
|
||||||
@ -210,7 +180,7 @@ abstract class AbstractSchemaManager
|
|||||||
* in the platformDetails array.
|
* in the platformDetails array.
|
||||||
*
|
*
|
||||||
* @param string $table The name of the table.
|
* @param string $table The name of the table.
|
||||||
* @return array $tableColumns The column descriptions.
|
* @return Column[]
|
||||||
*/
|
*/
|
||||||
public function listTableColumns($table)
|
public function listTableColumns($table)
|
||||||
{
|
{
|
||||||
@ -263,20 +233,6 @@ abstract class AbstractSchemaManager
|
|||||||
|
|
||||||
$tables = array();
|
$tables = array();
|
||||||
foreach ($tableNames AS $tableName) {
|
foreach ($tableNames AS $tableName) {
|
||||||
$columns = $this->listTableColumns($tableName);
|
|
||||||
$foreignKeys = array();
|
|
||||||
if ($this->_platform->supportsForeignKeyConstraints()) {
|
|
||||||
$foreignKeys = $this->listTableForeignKeys($tableName);
|
|
||||||
}
|
|
||||||
$indexes = $this->listTableIndexes($tableName);
|
|
||||||
|
|
||||||
$idGeneratorType = Table::ID_NONE;
|
|
||||||
foreach ($columns AS $column) {
|
|
||||||
if ($column->hasPlatformOption('autoincrement') && $column->getPlatformOption('autoincrement')) {
|
|
||||||
$idGeneratorType = Table::ID_IDENTITY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$tables[] = $this->listTableDetails($tableName);
|
$tables[] = $this->listTableDetails($tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,81 +589,6 @@ abstract class AbstractSchemaManager
|
|||||||
$this->alterTable($tableDiff);
|
$this->alterTable($tableDiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a new table column
|
|
||||||
*
|
|
||||||
* @param string $name The name of the table
|
|
||||||
* @param string $column The name of the column to add
|
|
||||||
* @param array $definition The definition of the column to add
|
|
||||||
*/
|
|
||||||
public function addTableColumn($name, $column, $definition)
|
|
||||||
{
|
|
||||||
$change = array(
|
|
||||||
'add' => array(
|
|
||||||
$column => $definition
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->alterTable($name, $change);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a column from a table
|
|
||||||
*
|
|
||||||
* @param string $tableName The name of the table
|
|
||||||
* @param array|string $column The column name or array of names
|
|
||||||
*/
|
|
||||||
public function removeTableColumn($name, $column)
|
|
||||||
{
|
|
||||||
$change = array(
|
|
||||||
'remove' => is_array($column) ? $column : array($column => array())
|
|
||||||
);
|
|
||||||
$this->alterTable($name, $change);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Change a given table column. You can change the type, length, etc.
|
|
||||||
*
|
|
||||||
* @param string $name The name of the table
|
|
||||||
* @param string $type The type of the column
|
|
||||||
* @param string $length The length of the column
|
|
||||||
* @param string $definition The definition array for the column
|
|
||||||
*/
|
|
||||||
public function changeTableColumn($name, $type, $length = null, $definition = array())
|
|
||||||
{
|
|
||||||
$definition['type'] = $type;
|
|
||||||
|
|
||||||
$change = array(
|
|
||||||
'change' => array(
|
|
||||||
$name => array(
|
|
||||||
'length' => $length,
|
|
||||||
'definition' => $definition
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->alterTable($name, $change);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rename a given table column
|
|
||||||
*
|
|
||||||
* @param string $name The name of the table
|
|
||||||
* @param string $oldName The old column name
|
|
||||||
* @param string $newName The new column
|
|
||||||
* @param string $definition The column definition array if you want to change something
|
|
||||||
*/
|
|
||||||
public function renameTableColumn($name, $oldName, $newName, $definition = array())
|
|
||||||
{
|
|
||||||
$change = array(
|
|
||||||
'rename' => array(
|
|
||||||
$oldName => array(
|
|
||||||
'name' => $newName,
|
|
||||||
'definition' => $definition
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->alterTable($name, $change);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methods for filtering return values of list*() methods to convert
|
* Methods for filtering return values of list*() methods to convert
|
||||||
* the native DBMS data definition to a portable Doctrine definition
|
* the native DBMS data definition to a portable Doctrine definition
|
||||||
@ -781,22 +662,6 @@ abstract class AbstractSchemaManager
|
|||||||
throw DBALException::notSupported('Sequences');
|
throw DBALException::notSupported('Sequences');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _getPortableTableConstraintsList($tableConstraints)
|
|
||||||
{
|
|
||||||
$list = array();
|
|
||||||
foreach ($tableConstraints as $key => $value) {
|
|
||||||
if ($value = $this->_getPortableTableConstraintDefinition($value)) {
|
|
||||||
$list[] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function _getPortableTableConstraintDefinition($tableConstraint)
|
|
||||||
{
|
|
||||||
return $tableConstraint;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Independent of the database the keys of the column list result are lowercased.
|
* Independent of the database the keys of the column list result are lowercased.
|
||||||
*
|
*
|
||||||
|
@ -70,18 +70,6 @@ class MySqlSchemaManager extends AbstractSchemaManager
|
|||||||
return parent::_getPortableTableIndexesList($tableIndexes, $tableName);
|
return parent::_getPortableTableIndexesList($tableIndexes, $tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _getPortableTableConstraintDefinition($tableConstraint)
|
|
||||||
{
|
|
||||||
$tableConstraint = array_change_key_case($tableConstraint, CASE_LOWER);
|
|
||||||
|
|
||||||
if ( ! $tableConstraint['non_unique']) {
|
|
||||||
$index = $tableConstraint['key_name'];
|
|
||||||
if ( ! empty($index)) {
|
|
||||||
return $index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function _getPortableSequenceDefinition($sequence)
|
protected function _getPortableSequenceDefinition($sequence)
|
||||||
{
|
{
|
||||||
return end($sequence);
|
return end($sequence);
|
||||||
|
@ -233,12 +233,6 @@ class OracleSchemaManager extends AbstractSchemaManager
|
|||||||
return new Sequence($sequence['sequence_name'], $sequence['increment_by'], $sequence['min_value']);
|
return new Sequence($sequence['sequence_name'], $sequence['increment_by'], $sequence['min_value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _getPortableTableConstraintDefinition($tableConstraint)
|
|
||||||
{
|
|
||||||
$tableConstraint = \array_change_key_case($tableConstraint, CASE_LOWER);
|
|
||||||
return $tableConstraint['constraint_name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function _getPortableFunctionDefinition($function)
|
protected function _getPortableFunctionDefinition($function)
|
||||||
{
|
{
|
||||||
$function = \array_change_key_case($function, CASE_LOWER);
|
$function = \array_change_key_case($function, CASE_LOWER);
|
||||||
|
@ -162,11 +162,6 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
|||||||
return new Sequence($sequence['relname'], $data[0]['increment_by'], $data[0]['min_value']);
|
return new Sequence($sequence['relname'], $data[0]['increment_by'], $data[0]['min_value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _getPortableTableConstraintDefinition($tableConstraint)
|
|
||||||
{
|
|
||||||
return $tableConstraint['relname'];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function _getPortableTableColumnDefinition($tableColumn)
|
protected function _getPortableTableColumnDefinition($tableColumn)
|
||||||
{
|
{
|
||||||
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
|
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
|
||||||
|
@ -8,13 +8,6 @@ require_once __DIR__ . '/../../../TestInit.php';
|
|||||||
|
|
||||||
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
|
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
|
||||||
{
|
{
|
||||||
public function testListTableConstraints()
|
|
||||||
{
|
|
||||||
$this->createTestTable('list_table_constraints_test');
|
|
||||||
$tableConstraints = $this->_sm->listTableConstraints('list_table_constraints_test');
|
|
||||||
$this->assertEquals(array('PRIMARY'), $tableConstraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testListUsers()
|
public function testListUsers()
|
||||||
{
|
{
|
||||||
$users = $this->_sm->listUsers();
|
$users = $this->_sm->listUsers();
|
||||||
|
@ -32,13 +32,6 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
|
|||||||
$this->_sm->listTriggers();
|
$this->_sm->listTriggers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testListTableConstraints()
|
|
||||||
{
|
|
||||||
$this->createTestTable('test_constraints');
|
|
||||||
$tableConstraints = $this->_sm->listTableConstraints('test_constraints');
|
|
||||||
$this->assertTrue(count($tableConstraints)>=2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testListUsers()
|
public function testListUsers()
|
||||||
{
|
{
|
||||||
$users = $this->_sm->listUsers();
|
$users = $this->_sm->listUsers();
|
||||||
|
@ -8,13 +8,6 @@ require_once __DIR__ . '/../../../TestInit.php';
|
|||||||
|
|
||||||
class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
|
class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
|
||||||
{
|
{
|
||||||
public function testListTableConstraints()
|
|
||||||
{
|
|
||||||
$this->createTestTable('list_table_constraints_test');
|
|
||||||
$tableConstraints = $this->_sm->listTableConstraints('list_table_constraints_test');
|
|
||||||
$this->assertEquals(array('list_table_constraints_test_pkey'), $tableConstraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testListUsers()
|
public function testListUsers()
|
||||||
{
|
{
|
||||||
$users = $this->_sm->listUsers();
|
$users = $this->_sm->listUsers();
|
||||||
|
@ -36,15 +36,6 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
|
|||||||
$this->_sm->listTriggers();
|
$this->_sm->listTriggers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testListTableConstraints()
|
|
||||||
{
|
|
||||||
// TODO: Implement support for constraints/foreign keys to be specified
|
|
||||||
// when creating tables. Sqlite does not support adding them after
|
|
||||||
// the table has already been created
|
|
||||||
$tableConstraints = $this->_sm->listTableConstraints('list_table_constraints_test');
|
|
||||||
$this->assertEquals(array(), $tableConstraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Exception
|
* @expectedException \Exception
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user