Reworked Table::$_primaryKey

parent 971b9b48
...@@ -112,6 +112,7 @@ Table columns are no longer indexed by column name. Use the `name` attribute of ...@@ -112,6 +112,7 @@ Table columns are no longer indexed by column name. Use the `name` attribute of
- Method `Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableViewDefinition()` no longer optionally returns false. It will always return a `Doctrine\DBAL\Schema\View` instance. - Method `Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableViewDefinition()` no longer optionally returns false. It will always return a `Doctrine\DBAL\Schema\View` instance.
- Method `Doctrine\DBAL\Schema\Comparator::diffTable()` now optionally returns null instead of false. - Method `Doctrine\DBAL\Schema\Comparator::diffTable()` now optionally returns null instead of false.
- Property `Doctrine\DBAL\Schema\Table::$_primaryKeyName` is now optionally null instead of false.
- Property `Doctrine\DBAL\Schema\TableDiff::$newName` is now optionally null instead of false. - Property `Doctrine\DBAL\Schema\TableDiff::$newName` is now optionally null instead of false.
- Method `Doctrine\DBAL\Schema\AbstractSchemaManager::tablesExist()` no longer accepts a string. Use `Doctrine\DBAL\Schema\AbstractSchemaManager::tableExists()` instead. - Method `Doctrine\DBAL\Schema\AbstractSchemaManager::tablesExist()` no longer accepts a string. Use `Doctrine\DBAL\Schema\AbstractSchemaManager::tableExists()` instead.
- Method `Doctrine\DBAL\Schema\OracleSchemaManager::createDatabase()` no longer accepts `null` for `$database` argument. - Method `Doctrine\DBAL\Schema\OracleSchemaManager::createDatabase()` no longer accepts `null` for `$database` argument.
......
...@@ -41,8 +41,8 @@ class Table extends AbstractAsset ...@@ -41,8 +41,8 @@ class Table extends AbstractAsset
/** @var Index[] */ /** @var Index[] */
protected $_indexes = []; protected $_indexes = [];
/** @var string */ /** @var string|null */
protected $_primaryKeyName = false; protected $_primaryKeyName;
/** @var UniqueConstraint[] */ /** @var UniqueConstraint[] */
protected $_uniqueConstraints = []; protected $_uniqueConstraints = [];
...@@ -163,8 +163,12 @@ class Table extends AbstractAsset ...@@ -163,8 +163,12 @@ class Table extends AbstractAsset
*/ */
public function dropPrimaryKey() : void public function dropPrimaryKey() : void
{ {
if ($this->_primaryKeyName === null) {
return;
}
$this->dropIndex($this->_primaryKeyName); $this->dropIndex($this->_primaryKeyName);
$this->_primaryKeyName = false; $this->_primaryKeyName = null;
} }
/** /**
...@@ -500,9 +504,11 @@ class Table extends AbstractAsset ...@@ -500,9 +504,11 @@ class Table extends AbstractAsset
*/ */
public function getPrimaryKey() : ?Index public function getPrimaryKey() : ?Index
{ {
return $this->hasPrimaryKey() if ($this->_primaryKeyName !== null) {
? $this->getIndex($this->_primaryKeyName) return $this->getIndex($this->_primaryKeyName);
: null; }
return null;
} }
/** /**
...@@ -528,7 +534,7 @@ class Table extends AbstractAsset ...@@ -528,7 +534,7 @@ class Table extends AbstractAsset
*/ */
public function hasPrimaryKey() : bool public function hasPrimaryKey() : bool
{ {
return $this->_primaryKeyName && $this->hasIndex($this->_primaryKeyName); return $this->_primaryKeyName !== null && $this->hasIndex($this->_primaryKeyName);
} }
/** /**
...@@ -684,7 +690,7 @@ class Table extends AbstractAsset ...@@ -684,7 +690,7 @@ class Table extends AbstractAsset
} }
if ((isset($this->_indexes[$indexName]) && ! in_array($indexName, $replacedImplicitIndexes, true)) || if ((isset($this->_indexes[$indexName]) && ! in_array($indexName, $replacedImplicitIndexes, true)) ||
($this->_primaryKeyName !== false && $indexCandidate->isPrimary()) ($this->_primaryKeyName !== null && $indexCandidate->isPrimary())
) { ) {
throw IndexAlreadyExists::new($indexName, $this->_name); throw IndexAlreadyExists::new($indexName, $this->_name);
} }
......
...@@ -12,7 +12,6 @@ parameters: ...@@ -12,7 +12,6 @@ parameters:
# changing these would be a BC break, to be done in next major # changing these would be a BC break, to be done in next major
- '~^Method Doctrine\\DBAL\\Query\\QueryBuilder::execute\(\) should return Doctrine\\DBAL\\Driver\\Statement\|int but returns Doctrine\\DBAL\\Driver\\ResultStatement\.\z~' - '~^Method Doctrine\\DBAL\\Query\\QueryBuilder::execute\(\) should return Doctrine\\DBAL\\Driver\\Statement\|int but returns Doctrine\\DBAL\\Driver\\ResultStatement\.\z~'
- '~^Property Doctrine\\DBAL\\Schema\\Table::\$_primaryKeyName \(string\) does not accept (default value of type )?false\.\z~'
# https://bugs.php.net/bug.php?id=78126 # https://bugs.php.net/bug.php?id=78126
- '~^Call to an undefined method PDO::sqliteCreateFunction\(\)\.\z~' - '~^Call to an undefined method PDO::sqliteCreateFunction\(\)\.\z~'
......
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