composer update
This commit is contained in:
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -36,16 +19,10 @@ use function substr;
|
||||
*
|
||||
* This encapsulation hack is necessary to keep a consistent state of the database schema. Say we have a list of tables
|
||||
* array($tableName => Table($tableName)); if you want to rename the table, you have to make sure
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
abstract class AbstractAsset
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
/** @var string */
|
||||
protected $_name;
|
||||
|
||||
/**
|
||||
@@ -55,9 +32,7 @@ abstract class AbstractAsset
|
||||
*/
|
||||
protected $_namespace = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
/** @var bool */
|
||||
protected $_quoted = false;
|
||||
|
||||
/**
|
||||
@@ -71,12 +46,12 @@ abstract class AbstractAsset
|
||||
{
|
||||
if ($this->isIdentifierQuoted($name)) {
|
||||
$this->_quoted = true;
|
||||
$name = $this->trimQuotes($name);
|
||||
$name = $this->trimQuotes($name);
|
||||
}
|
||||
if (strpos($name, ".") !== false) {
|
||||
$parts = explode(".", $name);
|
||||
if (strpos($name, '.') !== false) {
|
||||
$parts = explode('.', $name);
|
||||
$this->_namespace = $parts[0];
|
||||
$name = $parts[1];
|
||||
$name = $parts[1];
|
||||
}
|
||||
$this->_name = $name;
|
||||
}
|
||||
@@ -90,7 +65,7 @@ abstract class AbstractAsset
|
||||
*/
|
||||
public function isInDefaultNamespace($defaultNamespaceName)
|
||||
{
|
||||
return $this->_namespace == $defaultNamespaceName || $this->_namespace === null;
|
||||
return $this->_namespace === $defaultNamespaceName || $this->_namespace === null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +91,7 @@ abstract class AbstractAsset
|
||||
public function getShortestName($defaultNamespaceName)
|
||||
{
|
||||
$shortestName = $this->getName();
|
||||
if ($this->_namespace == $defaultNamespaceName) {
|
||||
if ($this->_namespace === $defaultNamespaceName) {
|
||||
$shortestName = $this->_name;
|
||||
}
|
||||
|
||||
@@ -139,8 +114,8 @@ abstract class AbstractAsset
|
||||
public function getFullQualifiedName($defaultNamespaceName)
|
||||
{
|
||||
$name = $this->getName();
|
||||
if ( ! $this->_namespace) {
|
||||
$name = $defaultNamespaceName . "." . $name;
|
||||
if (! $this->_namespace) {
|
||||
$name = $defaultNamespaceName . '.' . $name;
|
||||
}
|
||||
|
||||
return strtolower($name);
|
||||
@@ -165,7 +140,7 @@ abstract class AbstractAsset
|
||||
*/
|
||||
protected function isIdentifierQuoted($identifier)
|
||||
{
|
||||
return (isset($identifier[0]) && ($identifier[0] == '`' || $identifier[0] == '"' || $identifier[0] == '['));
|
||||
return isset($identifier[0]) && ($identifier[0] === '`' || $identifier[0] === '"' || $identifier[0] === '[');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,7 +163,7 @@ abstract class AbstractAsset
|
||||
public function getName()
|
||||
{
|
||||
if ($this->_namespace) {
|
||||
return $this->_namespace . "." . $this->_name;
|
||||
return $this->_namespace . '.' . $this->_name;
|
||||
}
|
||||
|
||||
return $this->_name;
|
||||
@@ -198,19 +173,17 @@ abstract class AbstractAsset
|
||||
* Gets the quoted representation of this asset but only if it was defined with one. Otherwise
|
||||
* return the plain unquoted value as inserted.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQuotedName(AbstractPlatform $platform)
|
||||
{
|
||||
$keywords = $platform->getReservedKeywordsList();
|
||||
$parts = explode(".", $this->getName());
|
||||
$parts = explode('.', $this->getName());
|
||||
foreach ($parts as $k => $v) {
|
||||
$parts[$k] = ($this->_quoted || $keywords->isKeyword($v)) ? $platform->quoteIdentifier($v) : $v;
|
||||
$parts[$k] = $this->_quoted || $keywords->isKeyword($v) ? $platform->quoteIdentifier($v) : $v;
|
||||
}
|
||||
|
||||
return implode(".", $parts);
|
||||
return implode('.', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,15 +193,15 @@ abstract class AbstractAsset
|
||||
* however building idents automatically for foreign keys, composite keys or such can easily create
|
||||
* very long names.
|
||||
*
|
||||
* @param array $columnNames
|
||||
* @param string $prefix
|
||||
* @param int $maxSize
|
||||
* @param string[] $columnNames
|
||||
* @param string $prefix
|
||||
* @param int $maxSize
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _generateIdentifierName($columnNames, $prefix='', $maxSize=30)
|
||||
protected function _generateIdentifierName($columnNames, $prefix = '', $maxSize = 30)
|
||||
{
|
||||
$hash = implode("", array_map(function ($column) {
|
||||
$hash = implode('', array_map(static function ($column) {
|
||||
return dechex(crc32($column));
|
||||
}, $columnNames));
|
||||
|
||||
|
@@ -1,37 +1,23 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
use Doctrine\DBAL\Events;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\ConnectionException;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs;
|
||||
use Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\Events;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Throwable;
|
||||
use function array_filter;
|
||||
use function array_intersect;
|
||||
use function array_map;
|
||||
use function array_values;
|
||||
use function call_user_func_array;
|
||||
use function count;
|
||||
use function func_get_args;
|
||||
use function is_array;
|
||||
use function is_null;
|
||||
use function preg_match;
|
||||
use function str_replace;
|
||||
use function strtolower;
|
||||
@@ -39,37 +25,27 @@ use function strtolower;
|
||||
/**
|
||||
* Base class for schema managers. Schema managers are used to inspect and/or
|
||||
* modify the database schema/structure.
|
||||
*
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @since 2.0
|
||||
*/
|
||||
abstract class AbstractSchemaManager
|
||||
{
|
||||
/**
|
||||
* Holds instance of the Doctrine connection for this schema manager.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
* @var Connection
|
||||
*/
|
||||
protected $_conn;
|
||||
|
||||
/**
|
||||
* Holds instance of the database platform used for this schema manager.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
|
||||
* @var AbstractPlatform
|
||||
*/
|
||||
protected $_platform;
|
||||
|
||||
/**
|
||||
* Constructor. Accepts the Connection instance to manage the schema for.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Connection $conn
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform|null $platform
|
||||
*/
|
||||
public function __construct(\Doctrine\DBAL\Connection $conn, AbstractPlatform $platform = null)
|
||||
public function __construct(Connection $conn, ?AbstractPlatform $platform = null)
|
||||
{
|
||||
$this->_conn = $conn;
|
||||
$this->_platform = $platform ?: $this->_conn->getDatabasePlatform();
|
||||
@@ -78,7 +54,7 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Returns the associated platform.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
|
||||
* @return AbstractPlatform
|
||||
*/
|
||||
public function getDatabasePlatform()
|
||||
{
|
||||
@@ -99,14 +75,14 @@ abstract class AbstractSchemaManager
|
||||
*/
|
||||
public function tryMethod()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$args = func_get_args();
|
||||
$method = $args[0];
|
||||
unset($args[0]);
|
||||
$args = array_values($args);
|
||||
|
||||
try {
|
||||
return call_user_func_array([$this, $method], $args);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -114,7 +90,7 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Lists the available databases for this connection.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function listDatabases()
|
||||
{
|
||||
@@ -128,7 +104,7 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Returns a list of all namespaces in the current database.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function listNamespaceNames()
|
||||
{
|
||||
@@ -144,7 +120,7 @@ abstract class AbstractSchemaManager
|
||||
*
|
||||
* @param string|null $database
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Sequence[]
|
||||
* @return Sequence[]
|
||||
*/
|
||||
public function listSequences($database = null)
|
||||
{
|
||||
@@ -171,11 +147,11 @@ abstract class AbstractSchemaManager
|
||||
* @param string $table The name of the table.
|
||||
* @param string|null $database
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column[]
|
||||
* @return Column[]
|
||||
*/
|
||||
public function listTableColumns($table, $database = null)
|
||||
{
|
||||
if ( ! $database) {
|
||||
if (! $database) {
|
||||
$database = $this->_conn->getDatabase();
|
||||
}
|
||||
|
||||
@@ -193,7 +169,7 @@ abstract class AbstractSchemaManager
|
||||
*
|
||||
* @param string $table The name of the table.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Index[]
|
||||
* @return Index[]
|
||||
*/
|
||||
public function listTableIndexes($table)
|
||||
{
|
||||
@@ -207,7 +183,7 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Returns true if all the given tables exist.
|
||||
*
|
||||
* @param array $tableNames
|
||||
* @param string[] $tableNames
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -215,19 +191,19 @@ abstract class AbstractSchemaManager
|
||||
{
|
||||
$tableNames = array_map('strtolower', (array) $tableNames);
|
||||
|
||||
return count($tableNames) == count(\array_intersect($tableNames, array_map('strtolower', $this->listTableNames())));
|
||||
return count($tableNames) === count(array_intersect($tableNames, array_map('strtolower', $this->listTableNames())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all tables in the current database.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function listTableNames()
|
||||
{
|
||||
$sql = $this->_platform->getListTablesSQL();
|
||||
|
||||
$tables = $this->_conn->fetchAll($sql);
|
||||
$tables = $this->_conn->fetchAll($sql);
|
||||
$tableNames = $this->_getPortableTablesList($tables);
|
||||
|
||||
return $this->filterAssetNames($tableNames);
|
||||
@@ -237,27 +213,23 @@ abstract class AbstractSchemaManager
|
||||
* Filters asset names if they are configured to return only a subset of all
|
||||
* the found elements.
|
||||
*
|
||||
* @param array $assetNames
|
||||
* @param mixed[] $assetNames
|
||||
*
|
||||
* @return array
|
||||
* @return mixed[]
|
||||
*/
|
||||
protected function filterAssetNames($assetNames)
|
||||
{
|
||||
$filterExpr = $this->getFilterSchemaAssetsExpression();
|
||||
if ( ! $filterExpr) {
|
||||
$filter = $this->_conn->getConfiguration()->getSchemaAssetsFilter();
|
||||
if (! $filter) {
|
||||
return $assetNames;
|
||||
}
|
||||
|
||||
return array_values(
|
||||
array_filter($assetNames, function ($assetName) use ($filterExpr) {
|
||||
$assetName = ($assetName instanceof AbstractAsset) ? $assetName->getName() : $assetName;
|
||||
|
||||
return preg_match($filterExpr, $assetName);
|
||||
})
|
||||
);
|
||||
return array_values(array_filter($assetNames, $filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use Configuration::getSchemaAssetsFilter() instead
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getFilterSchemaAssetsExpression()
|
||||
@@ -268,7 +240,7 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Lists the tables for this connection.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table[]
|
||||
* @return Table[]
|
||||
*/
|
||||
public function listTables()
|
||||
{
|
||||
@@ -285,11 +257,11 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
* @return Table
|
||||
*/
|
||||
public function listTableDetails($tableName)
|
||||
{
|
||||
$columns = $this->listTableColumns($tableName);
|
||||
$columns = $this->listTableColumns($tableName);
|
||||
$foreignKeys = [];
|
||||
if ($this->_platform->supportsForeignKeyConstraints()) {
|
||||
$foreignKeys = $this->listTableForeignKeys($tableName);
|
||||
@@ -302,13 +274,13 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Lists the views this connection has.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\View[]
|
||||
* @return View[]
|
||||
*/
|
||||
public function listViews()
|
||||
{
|
||||
$database = $this->_conn->getDatabase();
|
||||
$sql = $this->_platform->getListViewsSQL($database);
|
||||
$views = $this->_conn->fetchAll($sql);
|
||||
$sql = $this->_platform->getListViewsSQL($database);
|
||||
$views = $this->_conn->fetchAll($sql);
|
||||
|
||||
return $this->_getPortableViewsList($views);
|
||||
}
|
||||
@@ -319,14 +291,14 @@ abstract class AbstractSchemaManager
|
||||
* @param string $table The name of the table.
|
||||
* @param string|null $database
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
|
||||
* @return ForeignKeyConstraint[]
|
||||
*/
|
||||
public function listTableForeignKeys($table, $database = null)
|
||||
{
|
||||
if ($database === null) {
|
||||
$database = $this->_conn->getDatabase();
|
||||
}
|
||||
$sql = $this->_platform->getListTableForeignKeysSQL($table, $database);
|
||||
$sql = $this->_platform->getListTableForeignKeysSQL($table, $database);
|
||||
$tableForeignKeys = $this->_conn->fetchAll($sql);
|
||||
|
||||
return $this->_getPortableTableForeignKeysList($tableForeignKeys);
|
||||
@@ -363,8 +335,8 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Drops the index from the given table.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Index|string $index The name of the index.
|
||||
* @param \Doctrine\DBAL\Schema\Table|string $table The name of the table.
|
||||
* @param Index|string $index The name of the index.
|
||||
* @param Table|string $table The name of the table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -380,8 +352,7 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Drops the constraint from the given table.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Constraint $constraint
|
||||
* @param \Doctrine\DBAL\Schema\Table|string $table The name of the table.
|
||||
* @param Table|string $table The name of the table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -393,8 +364,8 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Drops a foreign key from a table.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint|string $foreignKey The name of the foreign key.
|
||||
* @param \Doctrine\DBAL\Schema\Table|string $table The name of the table with the foreign key.
|
||||
* @param ForeignKeyConstraint|string $foreignKey The name of the foreign key.
|
||||
* @param Table|string $table The name of the table with the foreign key.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -444,8 +415,6 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Creates a new table.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function createTable(Table $table)
|
||||
@@ -457,11 +426,11 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Creates a new sequence.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
* @param Sequence $sequence
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Doctrine\DBAL\ConnectionException If something fails at database level.
|
||||
* @throws ConnectionException If something fails at database level.
|
||||
*/
|
||||
public function createSequence($sequence)
|
||||
{
|
||||
@@ -471,8 +440,7 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Creates a constraint on a table.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Constraint $constraint
|
||||
* @param \Doctrine\DBAL\Schema\Table|string $table
|
||||
* @param Table|string $table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -484,8 +452,7 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Creates a new index on a table.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Index $index
|
||||
* @param \Doctrine\DBAL\Schema\Table|string $table The name of the table on which the index is to be created.
|
||||
* @param Table|string $table The name of the table on which the index is to be created.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -497,8 +464,8 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Creates a new foreign key.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey The ForeignKey instance.
|
||||
* @param \Doctrine\DBAL\Schema\Table|string $table The name of the table on which the foreign key is to be created.
|
||||
* @param ForeignKeyConstraint $foreignKey The ForeignKey instance.
|
||||
* @param Table|string $table The name of the table on which the foreign key is to be created.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -510,8 +477,6 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\View $view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function createView(View $view)
|
||||
@@ -527,8 +492,7 @@ abstract class AbstractSchemaManager
|
||||
* @see dropConstraint()
|
||||
* @see createConstraint()
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Constraint $constraint
|
||||
* @param \Doctrine\DBAL\Schema\Table|string $table
|
||||
* @param Table|string $table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -541,8 +505,7 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Drops and creates a new index on a table.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Index $index
|
||||
* @param \Doctrine\DBAL\Schema\Table|string $table The name of the table on which the index is to be created.
|
||||
* @param Table|string $table The name of the table on which the index is to be created.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -555,8 +518,8 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Drops and creates a new foreign key.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey An associative array that defines properties of the foreign key to be created.
|
||||
* @param \Doctrine\DBAL\Schema\Table|string $table The name of the table on which the foreign key is to be created.
|
||||
* @param ForeignKeyConstraint $foreignKey An associative array that defines properties of the foreign key to be created.
|
||||
* @param Table|string $table The name of the table on which the foreign key is to be created.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -569,11 +532,9 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Drops and create a new sequence.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Doctrine\DBAL\ConnectionException If something fails at database level.
|
||||
* @throws ConnectionException If something fails at database level.
|
||||
*/
|
||||
public function dropAndCreateSequence(Sequence $sequence)
|
||||
{
|
||||
@@ -584,8 +545,6 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Drops and creates a new table.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dropAndCreateTable(Table $table)
|
||||
@@ -610,8 +569,6 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Drops and creates a new view.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\View $view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dropAndCreateView(View $view)
|
||||
@@ -625,17 +582,17 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Alters an existing tables schema.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function alterTable(TableDiff $tableDiff)
|
||||
{
|
||||
$queries = $this->_platform->getAlterTableSQL($tableDiff);
|
||||
if (is_array($queries) && count($queries)) {
|
||||
foreach ($queries as $ddlQuery) {
|
||||
$this->_execSql($ddlQuery);
|
||||
}
|
||||
if (! is_array($queries) || ! count($queries)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($queries as $ddlQuery) {
|
||||
$this->_execSql($ddlQuery);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -649,7 +606,7 @@ abstract class AbstractSchemaManager
|
||||
*/
|
||||
public function renameTable($name, $newName)
|
||||
{
|
||||
$tableDiff = new TableDiff($name);
|
||||
$tableDiff = new TableDiff($name);
|
||||
$tableDiff->newName = $newName;
|
||||
$this->alterTable($tableDiff);
|
||||
}
|
||||
@@ -660,17 +617,21 @@ abstract class AbstractSchemaManager
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param array $databases
|
||||
* @param mixed[] $databases
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
protected function _getPortableDatabasesList($databases)
|
||||
{
|
||||
$list = [];
|
||||
foreach ($databases as $value) {
|
||||
if ($value = $this->_getPortableDatabaseDefinition($value)) {
|
||||
$list[] = $value;
|
||||
$value = $this->_getPortableDatabaseDefinition($value);
|
||||
|
||||
if (! $value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[] = $value;
|
||||
}
|
||||
|
||||
return $list;
|
||||
@@ -679,9 +640,9 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Converts a list of namespace names from the native DBMS data definition to a portable Doctrine definition.
|
||||
*
|
||||
* @param array $namespaces The list of namespace names in the native DBMS data definition.
|
||||
* @param mixed[][] $namespaces The list of namespace names in the native DBMS data definition.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getPortableNamespacesList(array $namespaces)
|
||||
{
|
||||
@@ -695,7 +656,7 @@ abstract class AbstractSchemaManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $database
|
||||
* @param mixed $database
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -707,7 +668,7 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Converts a namespace definition from the native DBMS data definition to a portable Doctrine definition.
|
||||
*
|
||||
* @param array $namespace The native DBMS namespace definition.
|
||||
* @param mixed[] $namespace The native DBMS namespace definition.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -717,24 +678,28 @@ abstract class AbstractSchemaManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $functions
|
||||
* @param mixed[][] $functions
|
||||
*
|
||||
* @return array
|
||||
* @return mixed[][]
|
||||
*/
|
||||
protected function _getPortableFunctionsList($functions)
|
||||
{
|
||||
$list = [];
|
||||
foreach ($functions as $value) {
|
||||
if ($value = $this->_getPortableFunctionDefinition($value)) {
|
||||
$list[] = $value;
|
||||
$value = $this->_getPortableFunctionDefinition($value);
|
||||
|
||||
if (! $value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[] = $value;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $function
|
||||
* @param mixed[] $function
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -744,24 +709,28 @@ abstract class AbstractSchemaManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $triggers
|
||||
* @param mixed[][] $triggers
|
||||
*
|
||||
* @return array
|
||||
* @return mixed[][]
|
||||
*/
|
||||
protected function _getPortableTriggersList($triggers)
|
||||
{
|
||||
$list = [];
|
||||
foreach ($triggers as $value) {
|
||||
if ($value = $this->_getPortableTriggerDefinition($value)) {
|
||||
$list[] = $value;
|
||||
$value = $this->_getPortableTriggerDefinition($value);
|
||||
|
||||
if (! $value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[] = $value;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $trigger
|
||||
* @param mixed[] $trigger
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -771,28 +740,32 @@ abstract class AbstractSchemaManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sequences
|
||||
* @param mixed[][] $sequences
|
||||
*
|
||||
* @return array
|
||||
* @return Sequence[]
|
||||
*/
|
||||
protected function _getPortableSequencesList($sequences)
|
||||
{
|
||||
$list = [];
|
||||
foreach ($sequences as $value) {
|
||||
if ($value = $this->_getPortableSequenceDefinition($value)) {
|
||||
$list[] = $value;
|
||||
$value = $this->_getPortableSequenceDefinition($value);
|
||||
|
||||
if (! $value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[] = $value;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sequence
|
||||
* @param mixed[] $sequence
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Sequence
|
||||
* @return Sequence
|
||||
*
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
* @throws DBALException
|
||||
*/
|
||||
protected function _getPortableSequenceDefinition($sequence)
|
||||
{
|
||||
@@ -804,11 +777,11 @@ abstract class AbstractSchemaManager
|
||||
*
|
||||
* The name of the created column instance however is kept in its case.
|
||||
*
|
||||
* @param string $table The name of the table.
|
||||
* @param string $database
|
||||
* @param array $tableColumns
|
||||
* @param string $table The name of the table.
|
||||
* @param string $database
|
||||
* @param mixed[][] $tableColumns
|
||||
*
|
||||
* @return array
|
||||
* @return Column[]
|
||||
*/
|
||||
protected function _getPortableTableColumnList($table, $database, $tableColumns)
|
||||
{
|
||||
@@ -816,25 +789,27 @@ abstract class AbstractSchemaManager
|
||||
|
||||
$list = [];
|
||||
foreach ($tableColumns as $tableColumn) {
|
||||
$column = null;
|
||||
$column = null;
|
||||
$defaultPrevented = false;
|
||||
|
||||
if (null !== $eventManager && $eventManager->hasListeners(Events::onSchemaColumnDefinition)) {
|
||||
if ($eventManager !== null && $eventManager->hasListeners(Events::onSchemaColumnDefinition)) {
|
||||
$eventArgs = new SchemaColumnDefinitionEventArgs($tableColumn, $table, $database, $this->_conn);
|
||||
$eventManager->dispatchEvent(Events::onSchemaColumnDefinition, $eventArgs);
|
||||
|
||||
$defaultPrevented = $eventArgs->isDefaultPrevented();
|
||||
$column = $eventArgs->getColumn();
|
||||
$column = $eventArgs->getColumn();
|
||||
}
|
||||
|
||||
if ( ! $defaultPrevented) {
|
||||
if (! $defaultPrevented) {
|
||||
$column = $this->_getPortableTableColumnDefinition($tableColumn);
|
||||
}
|
||||
|
||||
if ($column) {
|
||||
$name = strtolower($column->getQuotedName($this->_platform));
|
||||
$list[$name] = $column;
|
||||
if (! $column) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = strtolower($column->getQuotedName($this->_platform));
|
||||
$list[$name] = $column;
|
||||
}
|
||||
|
||||
return $list;
|
||||
@@ -843,21 +818,21 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Gets Table Column Definition.
|
||||
*
|
||||
* @param array $tableColumn
|
||||
* @param mixed[] $tableColumn
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
* @return Column
|
||||
*/
|
||||
abstract protected function _getPortableTableColumnDefinition($tableColumn);
|
||||
|
||||
/**
|
||||
* Aggregates and groups the index results according to the required data result.
|
||||
*
|
||||
* @param array $tableIndexRows
|
||||
* @param mixed[][] $tableIndexRows
|
||||
* @param string|null $tableName
|
||||
*
|
||||
* @return array
|
||||
* @return Index[]
|
||||
*/
|
||||
protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null)
|
||||
protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null)
|
||||
{
|
||||
$result = [];
|
||||
foreach ($tableIndexRows as $tableIndex) {
|
||||
@@ -867,68 +842,83 @@ abstract class AbstractSchemaManager
|
||||
}
|
||||
$keyName = strtolower($keyName);
|
||||
|
||||
if (!isset($result[$keyName])) {
|
||||
if (! isset($result[$keyName])) {
|
||||
$options = [
|
||||
'lengths' => [],
|
||||
];
|
||||
|
||||
if (isset($tableIndex['where'])) {
|
||||
$options['where'] = $tableIndex['where'];
|
||||
}
|
||||
|
||||
$result[$keyName] = [
|
||||
'name' => $indexName,
|
||||
'columns' => [$tableIndex['column_name']],
|
||||
'columns' => [],
|
||||
'unique' => $tableIndex['non_unique'] ? false : true,
|
||||
'primary' => $tableIndex['primary'],
|
||||
'flags' => $tableIndex['flags'] ?? [],
|
||||
'options' => isset($tableIndex['where']) ? ['where' => $tableIndex['where']] : [],
|
||||
'options' => $options,
|
||||
];
|
||||
} else {
|
||||
$result[$keyName]['columns'][] = $tableIndex['column_name'];
|
||||
}
|
||||
|
||||
$result[$keyName]['columns'][] = $tableIndex['column_name'];
|
||||
$result[$keyName]['options']['lengths'][] = $tableIndex['length'] ?? null;
|
||||
}
|
||||
|
||||
$eventManager = $this->_platform->getEventManager();
|
||||
|
||||
$indexes = [];
|
||||
foreach ($result as $indexKey => $data) {
|
||||
$index = null;
|
||||
$index = null;
|
||||
$defaultPrevented = false;
|
||||
|
||||
if (null !== $eventManager && $eventManager->hasListeners(Events::onSchemaIndexDefinition)) {
|
||||
if ($eventManager !== null && $eventManager->hasListeners(Events::onSchemaIndexDefinition)) {
|
||||
$eventArgs = new SchemaIndexDefinitionEventArgs($data, $tableName, $this->_conn);
|
||||
$eventManager->dispatchEvent(Events::onSchemaIndexDefinition, $eventArgs);
|
||||
|
||||
$defaultPrevented = $eventArgs->isDefaultPrevented();
|
||||
$index = $eventArgs->getIndex();
|
||||
$index = $eventArgs->getIndex();
|
||||
}
|
||||
|
||||
if ( ! $defaultPrevented) {
|
||||
if (! $defaultPrevented) {
|
||||
$index = new Index($data['name'], $data['columns'], $data['unique'], $data['primary'], $data['flags'], $data['options']);
|
||||
}
|
||||
|
||||
if ($index) {
|
||||
$indexes[$indexKey] = $index;
|
||||
if (! $index) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$indexes[$indexKey] = $index;
|
||||
}
|
||||
|
||||
return $indexes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $tables
|
||||
* @param mixed[][] $tables
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
protected function _getPortableTablesList($tables)
|
||||
{
|
||||
$list = [];
|
||||
foreach ($tables as $value) {
|
||||
if ($value = $this->_getPortableTableDefinition($value)) {
|
||||
$list[] = $value;
|
||||
$value = $this->_getPortableTableDefinition($value);
|
||||
|
||||
if (! $value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[] = $value;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $table
|
||||
* @param mixed $table
|
||||
*
|
||||
* @return array
|
||||
* @return string
|
||||
*/
|
||||
protected function _getPortableTableDefinition($table)
|
||||
{
|
||||
@@ -936,26 +926,30 @@ abstract class AbstractSchemaManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $users
|
||||
* @param mixed[][] $users
|
||||
*
|
||||
* @return array
|
||||
* @return string[][]
|
||||
*/
|
||||
protected function _getPortableUsersList($users)
|
||||
{
|
||||
$list = [];
|
||||
foreach ($users as $value) {
|
||||
if ($value = $this->_getPortableUserDefinition($value)) {
|
||||
$list[] = $value;
|
||||
$value = $this->_getPortableUserDefinition($value);
|
||||
|
||||
if (! $value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[] = $value;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $user
|
||||
* @param mixed[] $user
|
||||
*
|
||||
* @return mixed
|
||||
* @return mixed[]
|
||||
*/
|
||||
protected function _getPortableUserDefinition($user)
|
||||
{
|
||||
@@ -963,27 +957,31 @@ abstract class AbstractSchemaManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $views
|
||||
* @param mixed[][] $views
|
||||
*
|
||||
* @return array
|
||||
* @return View[]
|
||||
*/
|
||||
protected function _getPortableViewsList($views)
|
||||
{
|
||||
$list = [];
|
||||
foreach ($views as $value) {
|
||||
if ($view = $this->_getPortableViewDefinition($value)) {
|
||||
$viewName = strtolower($view->getQuotedName($this->_platform));
|
||||
$list[$viewName] = $view;
|
||||
$view = $this->_getPortableViewDefinition($value);
|
||||
|
||||
if (! $view) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$viewName = strtolower($view->getQuotedName($this->_platform));
|
||||
$list[$viewName] = $view;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $view
|
||||
* @param mixed[] $view
|
||||
*
|
||||
* @return mixed
|
||||
* @return View|false
|
||||
*/
|
||||
protected function _getPortableViewDefinition($view)
|
||||
{
|
||||
@@ -991,26 +989,30 @@ abstract class AbstractSchemaManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $tableForeignKeys
|
||||
* @param mixed[][] $tableForeignKeys
|
||||
*
|
||||
* @return array
|
||||
* @return ForeignKeyConstraint[]
|
||||
*/
|
||||
protected function _getPortableTableForeignKeysList($tableForeignKeys)
|
||||
{
|
||||
$list = [];
|
||||
foreach ($tableForeignKeys as $value) {
|
||||
if ($value = $this->_getPortableTableForeignKeyDefinition($value)) {
|
||||
$list[] = $value;
|
||||
$value = $this->_getPortableTableForeignKeyDefinition($value);
|
||||
|
||||
if (! $value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[] = $value;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $tableForeignKey
|
||||
* @param mixed $tableForeignKey
|
||||
*
|
||||
* @return mixed
|
||||
* @return ForeignKeyConstraint
|
||||
*/
|
||||
protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
|
||||
{
|
||||
@@ -1018,7 +1020,7 @@ abstract class AbstractSchemaManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $sql
|
||||
* @param string[]|string $sql
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -1032,7 +1034,7 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Creates a schema instance for the current database.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Schema
|
||||
* @return Schema
|
||||
*/
|
||||
public function createSchema()
|
||||
{
|
||||
@@ -1056,7 +1058,7 @@ abstract class AbstractSchemaManager
|
||||
/**
|
||||
* Creates the configuration for this schema.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaConfig
|
||||
* @return SchemaConfig
|
||||
*/
|
||||
public function createSchemaConfig()
|
||||
{
|
||||
@@ -1090,7 +1092,7 @@ abstract class AbstractSchemaManager
|
||||
* For databases that don't support subschema/namespaces this method
|
||||
* returns the name of the currently connected database.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSchemaSearchPaths()
|
||||
{
|
||||
@@ -1108,7 +1110,7 @@ abstract class AbstractSchemaManager
|
||||
*/
|
||||
public function extractDoctrineTypeFromComment($comment, $currentType)
|
||||
{
|
||||
if (preg_match("(\(DC2Type:(((?!\)).)+)\))", $comment, $match)) {
|
||||
if (preg_match('(\(DC2Type:(((?!\)).)+)\))', $comment, $match)) {
|
||||
$currentType = $match[1];
|
||||
}
|
||||
|
||||
@@ -1123,6 +1125,6 @@ abstract class AbstractSchemaManager
|
||||
*/
|
||||
public function removeDoctrineTypeFromComment($comment, $type)
|
||||
{
|
||||
return str_replace('(DC2Type:'.$type.')', '', $comment);
|
||||
return str_replace('(DC2Type:' . $type . ')', '', $comment);
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -29,86 +12,55 @@ use function trigger_error;
|
||||
|
||||
/**
|
||||
* Object representation of a database column.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class Column extends AbstractAsset
|
||||
{
|
||||
/**
|
||||
* @var Type
|
||||
*/
|
||||
/** @var Type */
|
||||
protected $_type;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
/** @var int|null */
|
||||
protected $_length = null;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
/** @var int */
|
||||
protected $_precision = 10;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
/** @var int */
|
||||
protected $_scale = 0;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
/** @var bool */
|
||||
protected $_unsigned = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
/** @var bool */
|
||||
protected $_fixed = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
/** @var bool */
|
||||
protected $_notnull = true;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
/** @var string|null */
|
||||
protected $_default = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
/** @var bool */
|
||||
protected $_autoincrement = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var mixed[] */
|
||||
protected $_platformOptions = [];
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
/** @var string|null */
|
||||
protected $_columnDefinition = null;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
/** @var string|null */
|
||||
protected $_comment = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var mixed[] */
|
||||
protected $_customSchemaOptions = [];
|
||||
|
||||
/**
|
||||
* Creates a new Column.
|
||||
*
|
||||
* @param string $columnName
|
||||
* @param Type $type
|
||||
* @param array $options
|
||||
* @param string $columnName
|
||||
* @param mixed[] $options
|
||||
*/
|
||||
public function __construct($columnName, Type $type, array $options=[])
|
||||
public function __construct($columnName, Type $type, array $options = [])
|
||||
{
|
||||
$this->_setName($columnName);
|
||||
$this->setType($type);
|
||||
@@ -116,18 +68,18 @@ class Column extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
* @param mixed[] $options
|
||||
*
|
||||
* @return Column
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
foreach ($options as $name => $value) {
|
||||
$method = "set".$name;
|
||||
if ( ! method_exists($this, $method)) {
|
||||
$method = 'set' . $name;
|
||||
if (! method_exists($this, $method)) {
|
||||
// next major: throw an exception
|
||||
@trigger_error(sprintf(
|
||||
'The "%s" column option is not supported,'.
|
||||
'The "%s" column option is not supported,' .
|
||||
' setting it is deprecated and will cause an error in Doctrine 3.0',
|
||||
$name
|
||||
), E_USER_DEPRECATED);
|
||||
@@ -141,8 +93,6 @@ class Column extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Type $type
|
||||
*
|
||||
* @return Column
|
||||
*/
|
||||
public function setType(Type $type)
|
||||
@@ -175,7 +125,7 @@ class Column extends AbstractAsset
|
||||
*/
|
||||
public function setPrecision($precision)
|
||||
{
|
||||
if (!is_numeric($precision)) {
|
||||
if (! is_numeric($precision)) {
|
||||
$precision = 10; // defaults to 10 when no valid precision is given.
|
||||
}
|
||||
|
||||
@@ -191,7 +141,7 @@ class Column extends AbstractAsset
|
||||
*/
|
||||
public function setScale($scale)
|
||||
{
|
||||
if (!is_numeric($scale)) {
|
||||
if (! is_numeric($scale)) {
|
||||
$scale = 0;
|
||||
}
|
||||
|
||||
@@ -249,7 +199,7 @@ class Column extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $platformOptions
|
||||
* @param mixed[] $platformOptions
|
||||
*
|
||||
* @return Column
|
||||
*/
|
||||
@@ -350,7 +300,7 @@ class Column extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getPlatformOptions()
|
||||
{
|
||||
@@ -459,7 +409,7 @@ class Column extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $customSchemaOptions
|
||||
* @param mixed[] $customSchemaOptions
|
||||
*
|
||||
* @return Column
|
||||
*/
|
||||
@@ -471,7 +421,7 @@ class Column extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getCustomSchemaOptions()
|
||||
{
|
||||
@@ -479,7 +429,7 @@ class Column extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -23,45 +6,31 @@ use function in_array;
|
||||
|
||||
/**
|
||||
* Represents the change of a column.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class ColumnDiff
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
/** @var string */
|
||||
public $oldColumnName;
|
||||
|
||||
/**
|
||||
* @var Column
|
||||
*/
|
||||
/** @var Column */
|
||||
public $column;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var string[] */
|
||||
public $changedProperties = [];
|
||||
|
||||
/**
|
||||
* @var Column
|
||||
*/
|
||||
/** @var Column */
|
||||
public $fromColumn;
|
||||
|
||||
/**
|
||||
* @param string $oldColumnName
|
||||
* @param Column $column
|
||||
* @param string[] $changedProperties
|
||||
* @param Column $fromColumn
|
||||
*/
|
||||
public function __construct($oldColumnName, Column $column, array $changedProperties = [], Column $fromColumn = null)
|
||||
public function __construct($oldColumnName, Column $column, array $changedProperties = [], ?Column $fromColumn = null)
|
||||
{
|
||||
$this->oldColumnName = $oldColumnName;
|
||||
$this->column = $column;
|
||||
$this->oldColumnName = $oldColumnName;
|
||||
$this->column = $column;
|
||||
$this->changedProperties = $changedProperties;
|
||||
$this->fromColumn = $fromColumn;
|
||||
$this->fromColumn = $fromColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -32,18 +15,11 @@ use function strtolower;
|
||||
|
||||
/**
|
||||
* Compares two Schemas and return an instance of SchemaDiff.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class Comparator
|
||||
{
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Schema $fromSchema
|
||||
* @param \Doctrine\DBAL\Schema\Schema $toSchema
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaDiff
|
||||
* @return SchemaDiff
|
||||
*/
|
||||
public static function compareSchemas(Schema $fromSchema, Schema $toSchema)
|
||||
{
|
||||
@@ -59,33 +35,34 @@ class Comparator
|
||||
* operations to change the schema stored in $fromSchema to the schema that is
|
||||
* stored in $toSchema.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Schema $fromSchema
|
||||
* @param \Doctrine\DBAL\Schema\Schema $toSchema
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaDiff
|
||||
* @return SchemaDiff
|
||||
*/
|
||||
public function compare(Schema $fromSchema, Schema $toSchema)
|
||||
{
|
||||
$diff = new SchemaDiff();
|
||||
$diff = new SchemaDiff();
|
||||
$diff->fromSchema = $fromSchema;
|
||||
|
||||
$foreignKeysToTable = [];
|
||||
|
||||
foreach ($toSchema->getNamespaces() as $namespace) {
|
||||
if ( ! $fromSchema->hasNamespace($namespace)) {
|
||||
$diff->newNamespaces[$namespace] = $namespace;
|
||||
if ($fromSchema->hasNamespace($namespace)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$diff->newNamespaces[$namespace] = $namespace;
|
||||
}
|
||||
|
||||
foreach ($fromSchema->getNamespaces() as $namespace) {
|
||||
if ( ! $toSchema->hasNamespace($namespace)) {
|
||||
$diff->removedNamespaces[$namespace] = $namespace;
|
||||
if ($toSchema->hasNamespace($namespace)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$diff->removedNamespaces[$namespace] = $namespace;
|
||||
}
|
||||
|
||||
foreach ($toSchema->getTables() as $table) {
|
||||
$tableName = $table->getShortestName($toSchema->getName());
|
||||
if ( ! $fromSchema->hasTable($tableName)) {
|
||||
if (! $fromSchema->hasTable($tableName)) {
|
||||
$diff->newTables[$tableName] = $toSchema->getTable($tableName);
|
||||
} else {
|
||||
$tableDifferences = $this->diffTable($fromSchema->getTable($tableName), $toSchema->getTable($tableName));
|
||||
@@ -100,14 +77,14 @@ class Comparator
|
||||
$tableName = $table->getShortestName($fromSchema->getName());
|
||||
|
||||
$table = $fromSchema->getTable($tableName);
|
||||
if ( ! $toSchema->hasTable($tableName)) {
|
||||
if (! $toSchema->hasTable($tableName)) {
|
||||
$diff->removedTables[$tableName] = $table;
|
||||
}
|
||||
|
||||
// also remember all foreign keys that point to a specific table
|
||||
foreach ($table->getForeignKeys() as $foreignKey) {
|
||||
$foreignTable = strtolower($foreignKey->getForeignTableName());
|
||||
if (!isset($foreignKeysToTable[$foreignTable])) {
|
||||
if (! isset($foreignKeysToTable[$foreignTable])) {
|
||||
$foreignKeysToTable[$foreignTable] = [];
|
||||
}
|
||||
$foreignKeysToTable[$foreignTable][] = $foreignKey;
|
||||
@@ -115,31 +92,35 @@ class Comparator
|
||||
}
|
||||
|
||||
foreach ($diff->removedTables as $tableName => $table) {
|
||||
if (isset($foreignKeysToTable[$tableName])) {
|
||||
$diff->orphanedForeignKeys = array_merge($diff->orphanedForeignKeys, $foreignKeysToTable[$tableName]);
|
||||
if (! isset($foreignKeysToTable[$tableName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// deleting duplicated foreign keys present on both on the orphanedForeignKey
|
||||
// and the removedForeignKeys from changedTables
|
||||
foreach ($foreignKeysToTable[$tableName] as $foreignKey) {
|
||||
// strtolower the table name to make if compatible with getShortestName
|
||||
$localTableName = strtolower($foreignKey->getLocalTableName());
|
||||
if (isset($diff->changedTables[$localTableName])) {
|
||||
foreach ($diff->changedTables[$localTableName]->removedForeignKeys as $key => $removedForeignKey) {
|
||||
// We check if the key is from the removed table if not we skip.
|
||||
if ($tableName !== strtolower($removedForeignKey->getForeignTableName())) {
|
||||
continue;
|
||||
}
|
||||
unset($diff->changedTables[$localTableName]->removedForeignKeys[$key]);
|
||||
}
|
||||
$diff->orphanedForeignKeys = array_merge($diff->orphanedForeignKeys, $foreignKeysToTable[$tableName]);
|
||||
|
||||
// deleting duplicated foreign keys present on both on the orphanedForeignKey
|
||||
// and the removedForeignKeys from changedTables
|
||||
foreach ($foreignKeysToTable[$tableName] as $foreignKey) {
|
||||
// strtolower the table name to make if compatible with getShortestName
|
||||
$localTableName = strtolower($foreignKey->getLocalTableName());
|
||||
if (! isset($diff->changedTables[$localTableName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($diff->changedTables[$localTableName]->removedForeignKeys as $key => $removedForeignKey) {
|
||||
// We check if the key is from the removed table if not we skip.
|
||||
if ($tableName !== strtolower($removedForeignKey->getForeignTableName())) {
|
||||
continue;
|
||||
}
|
||||
unset($diff->changedTables[$localTableName]->removedForeignKeys[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($toSchema->getSequences() as $sequence) {
|
||||
$sequenceName = $sequence->getShortestName($toSchema->getName());
|
||||
if ( ! $fromSchema->hasSequence($sequenceName)) {
|
||||
if ( ! $this->isAutoIncrementSequenceInSchema($fromSchema, $sequence)) {
|
||||
if (! $fromSchema->hasSequence($sequenceName)) {
|
||||
if (! $this->isAutoIncrementSequenceInSchema($fromSchema, $sequence)) {
|
||||
$diff->newSequences[] = $sequence;
|
||||
}
|
||||
} else {
|
||||
@@ -156,17 +137,19 @@ class Comparator
|
||||
|
||||
$sequenceName = $sequence->getShortestName($fromSchema->getName());
|
||||
|
||||
if ( ! $toSchema->hasSequence($sequenceName)) {
|
||||
$diff->removedSequences[] = $sequence;
|
||||
if ($toSchema->hasSequence($sequenceName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$diff->removedSequences[] = $sequence;
|
||||
}
|
||||
|
||||
return $diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Schema $schema
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
* @param Schema $schema
|
||||
* @param Sequence $sequence
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -182,14 +165,11 @@ class Comparator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence1
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence2
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function diffSequence(Sequence $sequence1, Sequence $sequence2)
|
||||
{
|
||||
if ($sequence1->getAllocationSize() != $sequence2->getAllocationSize()) {
|
||||
if ($sequence1->getAllocationSize() !== $sequence2->getAllocationSize()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -201,15 +181,12 @@ class Comparator
|
||||
*
|
||||
* If there are no differences this method returns the boolean false.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Table $table1
|
||||
* @param \Doctrine\DBAL\Schema\Table $table2
|
||||
*
|
||||
* @return TableDiff|false
|
||||
*/
|
||||
public function diffTable(Table $table1, Table $table2)
|
||||
{
|
||||
$changes = 0;
|
||||
$tableDifferences = new TableDiff($table1->getName());
|
||||
$changes = 0;
|
||||
$tableDifferences = new TableDiff($table1->getName());
|
||||
$tableDifferences->fromTable = $table1;
|
||||
|
||||
$table1Columns = $table1->getColumns();
|
||||
@@ -217,15 +194,17 @@ class Comparator
|
||||
|
||||
/* See if all the fields in table 1 exist in table 2 */
|
||||
foreach ($table2Columns as $columnName => $column) {
|
||||
if ( !$table1->hasColumn($columnName)) {
|
||||
$tableDifferences->addedColumns[$columnName] = $column;
|
||||
$changes++;
|
||||
if ($table1->hasColumn($columnName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tableDifferences->addedColumns[$columnName] = $column;
|
||||
$changes++;
|
||||
}
|
||||
/* See if there are any removed fields in table 2 */
|
||||
foreach ($table1Columns as $columnName => $column) {
|
||||
// See if column is removed in table 2.
|
||||
if ( ! $table2->hasColumn($columnName)) {
|
||||
if (! $table2->hasColumn($columnName)) {
|
||||
$tableDifferences->removedColumns[$columnName] = $column;
|
||||
$changes++;
|
||||
continue;
|
||||
@@ -234,12 +213,14 @@ class Comparator
|
||||
// See if column has changed properties in table 2.
|
||||
$changedProperties = $this->diffColumn($column, $table2->getColumn($columnName));
|
||||
|
||||
if ( ! empty($changedProperties)) {
|
||||
$columnDiff = new ColumnDiff($column->getName(), $table2->getColumn($columnName), $changedProperties);
|
||||
$columnDiff->fromColumn = $column;
|
||||
$tableDifferences->changedColumns[$column->getName()] = $columnDiff;
|
||||
$changes++;
|
||||
if (empty($changedProperties)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$columnDiff = new ColumnDiff($column->getName(), $table2->getColumn($columnName), $changedProperties);
|
||||
$columnDiff->fromColumn = $column;
|
||||
$tableDifferences->changedColumns[$column->getName()] = $columnDiff;
|
||||
$changes++;
|
||||
}
|
||||
|
||||
$this->detectColumnRenamings($tableDifferences);
|
||||
@@ -270,23 +251,25 @@ class Comparator
|
||||
// See if index has changed in table 2.
|
||||
$table2Index = $index->isPrimary() ? $table2->getPrimaryKey() : $table2->getIndex($indexName);
|
||||
|
||||
if ($this->diffIndex($index, $table2Index)) {
|
||||
$tableDifferences->changedIndexes[$indexName] = $table2Index;
|
||||
$changes++;
|
||||
if (! $this->diffIndex($index, $table2Index)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tableDifferences->changedIndexes[$indexName] = $table2Index;
|
||||
$changes++;
|
||||
}
|
||||
|
||||
$this->detectIndexRenamings($tableDifferences);
|
||||
|
||||
$fromFkeys = $table1->getForeignKeys();
|
||||
$toFkeys = $table2->getForeignKeys();
|
||||
$toFkeys = $table2->getForeignKeys();
|
||||
|
||||
foreach ($fromFkeys as $key1 => $constraint1) {
|
||||
foreach ($toFkeys as $key2 => $constraint2) {
|
||||
if ($this->diffForeignKey($constraint1, $constraint2) === false) {
|
||||
unset($fromFkeys[$key1], $toFkeys[$key2]);
|
||||
} else {
|
||||
if (strtolower($constraint1->getName()) == strtolower($constraint2->getName())) {
|
||||
if (strtolower($constraint1->getName()) === strtolower($constraint2->getName())) {
|
||||
$tableDifferences->changedForeignKeys[] = $constraint2;
|
||||
$changes++;
|
||||
unset($fromFkeys[$key1], $toFkeys[$key2]);
|
||||
@@ -319,26 +302,32 @@ class Comparator
|
||||
$renameCandidates = [];
|
||||
foreach ($tableDifferences->addedColumns as $addedColumnName => $addedColumn) {
|
||||
foreach ($tableDifferences->removedColumns as $removedColumn) {
|
||||
if (count($this->diffColumn($addedColumn, $removedColumn)) == 0) {
|
||||
$renameCandidates[$addedColumn->getName()][] = [$removedColumn, $addedColumn, $addedColumnName];
|
||||
if (count($this->diffColumn($addedColumn, $removedColumn)) !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$renameCandidates[$addedColumn->getName()][] = [$removedColumn, $addedColumn, $addedColumnName];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($renameCandidates as $candidateColumns) {
|
||||
if (count($candidateColumns) == 1) {
|
||||
list($removedColumn, $addedColumn) = $candidateColumns[0];
|
||||
$removedColumnName = strtolower($removedColumn->getName());
|
||||
$addedColumnName = strtolower($addedColumn->getName());
|
||||
|
||||
if ( ! isset($tableDifferences->renamedColumns[$removedColumnName])) {
|
||||
$tableDifferences->renamedColumns[$removedColumnName] = $addedColumn;
|
||||
unset(
|
||||
$tableDifferences->addedColumns[$addedColumnName],
|
||||
$tableDifferences->removedColumns[$removedColumnName]
|
||||
);
|
||||
}
|
||||
if (count($candidateColumns) !== 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
[$removedColumn, $addedColumn] = $candidateColumns[0];
|
||||
$removedColumnName = strtolower($removedColumn->getName());
|
||||
$addedColumnName = strtolower($addedColumn->getName());
|
||||
|
||||
if (isset($tableDifferences->renamedColumns[$removedColumnName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tableDifferences->renamedColumns[$removedColumnName] = $addedColumn;
|
||||
unset(
|
||||
$tableDifferences->addedColumns[$addedColumnName],
|
||||
$tableDifferences->removedColumns[$removedColumnName]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,9 +344,11 @@ class Comparator
|
||||
// Gather possible rename candidates by comparing each added and removed index based on semantics.
|
||||
foreach ($tableDifferences->addedIndexes as $addedIndexName => $addedIndex) {
|
||||
foreach ($tableDifferences->removedIndexes as $removedIndex) {
|
||||
if (! $this->diffIndex($addedIndex, $removedIndex)) {
|
||||
$renameCandidates[$addedIndex->getName()][] = [$removedIndex, $addedIndex, $addedIndexName];
|
||||
if ($this->diffIndex($addedIndex, $removedIndex)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$renameCandidates[$addedIndex->getName()][] = [$removedIndex, $addedIndex, $addedIndexName];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,36 +357,37 @@ class Comparator
|
||||
// we can safely rename it.
|
||||
// Otherwise it is unclear if a rename action is really intended,
|
||||
// therefore we let those ambiguous indexes be added/dropped.
|
||||
if (count($candidateIndexes) === 1) {
|
||||
list($removedIndex, $addedIndex) = $candidateIndexes[0];
|
||||
|
||||
$removedIndexName = strtolower($removedIndex->getName());
|
||||
$addedIndexName = strtolower($addedIndex->getName());
|
||||
|
||||
if (! isset($tableDifferences->renamedIndexes[$removedIndexName])) {
|
||||
$tableDifferences->renamedIndexes[$removedIndexName] = $addedIndex;
|
||||
unset(
|
||||
$tableDifferences->addedIndexes[$addedIndexName],
|
||||
$tableDifferences->removedIndexes[$removedIndexName]
|
||||
);
|
||||
}
|
||||
if (count($candidateIndexes) !== 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
[$removedIndex, $addedIndex] = $candidateIndexes[0];
|
||||
|
||||
$removedIndexName = strtolower($removedIndex->getName());
|
||||
$addedIndexName = strtolower($addedIndex->getName());
|
||||
|
||||
if (isset($tableDifferences->renamedIndexes[$removedIndexName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tableDifferences->renamedIndexes[$removedIndexName] = $addedIndex;
|
||||
unset(
|
||||
$tableDifferences->addedIndexes[$addedIndexName],
|
||||
$tableDifferences->removedIndexes[$removedIndexName]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $key1
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $key2
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2)
|
||||
{
|
||||
if (array_map('strtolower', $key1->getUnquotedLocalColumns()) != array_map('strtolower', $key2->getUnquotedLocalColumns())) {
|
||||
if (array_map('strtolower', $key1->getUnquotedLocalColumns()) !== array_map('strtolower', $key2->getUnquotedLocalColumns())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (array_map('strtolower', $key1->getUnquotedForeignColumns()) != array_map('strtolower', $key2->getUnquotedForeignColumns())) {
|
||||
if (array_map('strtolower', $key1->getUnquotedForeignColumns()) !== array_map('strtolower', $key2->getUnquotedForeignColumns())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -403,7 +395,7 @@ class Comparator
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($key1->onUpdate() != $key2->onUpdate()) {
|
||||
if ($key1->onUpdate() !== $key2->onUpdate()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -416,10 +408,7 @@ class Comparator
|
||||
* If there are differences this method returns $field2, otherwise the
|
||||
* boolean false.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Column $column1
|
||||
* @param \Doctrine\DBAL\Schema\Column $column2
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function diffColumn(Column $column1, Column $column2)
|
||||
{
|
||||
@@ -429,9 +418,11 @@ class Comparator
|
||||
$changedProperties = [];
|
||||
|
||||
foreach (['type', 'notnull', 'unsigned', 'autoincrement'] as $property) {
|
||||
if ($properties1[$property] != $properties2[$property]) {
|
||||
$changedProperties[] = $property;
|
||||
if ($properties1[$property] === $properties2[$property]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$changedProperties[] = $property;
|
||||
}
|
||||
|
||||
// This is a very nasty hack to make comparator work with the legacy json_array type, which should be killed in v3
|
||||
@@ -441,12 +432,10 @@ class Comparator
|
||||
$changedProperties[] = 'comment';
|
||||
}
|
||||
|
||||
if ($properties1['default'] != $properties2['default'] ||
|
||||
// Null values need to be checked additionally as they tell whether to create or drop a default value.
|
||||
// null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation.
|
||||
(null === $properties1['default'] && null !== $properties2['default']) ||
|
||||
(null === $properties2['default'] && null !== $properties1['default'])
|
||||
) {
|
||||
// Null values need to be checked additionally as they tell whether to create or drop a default value.
|
||||
// null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation.
|
||||
if (($properties1['default'] === null) !== ($properties2['default'] === null)
|
||||
|| (string) $properties1['default'] !== (string) $properties2['default']) {
|
||||
$changedProperties[] = 'default';
|
||||
}
|
||||
|
||||
@@ -456,26 +445,26 @@ class Comparator
|
||||
// check if value of length is set at all, default value assumed otherwise.
|
||||
$length1 = $properties1['length'] ?: 255;
|
||||
$length2 = $properties2['length'] ?: 255;
|
||||
if ($length1 != $length2) {
|
||||
if ($length1 !== $length2) {
|
||||
$changedProperties[] = 'length';
|
||||
}
|
||||
|
||||
if ($properties1['fixed'] != $properties2['fixed']) {
|
||||
if ($properties1['fixed'] !== $properties2['fixed']) {
|
||||
$changedProperties[] = 'fixed';
|
||||
}
|
||||
} elseif ($properties1['type'] instanceof Types\DecimalType) {
|
||||
if (($properties1['precision'] ?: 10) != ($properties2['precision'] ?: 10)) {
|
||||
if (($properties1['precision'] ?: 10) !== ($properties2['precision'] ?: 10)) {
|
||||
$changedProperties[] = 'precision';
|
||||
}
|
||||
if ($properties1['scale'] != $properties2['scale']) {
|
||||
if ($properties1['scale'] !== $properties2['scale']) {
|
||||
$changedProperties[] = 'scale';
|
||||
}
|
||||
}
|
||||
|
||||
// A null value and an empty string are actually equal for a comment so they should not trigger a change.
|
||||
if ($properties1['comment'] !== $properties2['comment'] &&
|
||||
! (null === $properties1['comment'] && '' === $properties2['comment']) &&
|
||||
! (null === $properties2['comment'] && '' === $properties1['comment'])
|
||||
! ($properties1['comment'] === null && $properties2['comment'] === '') &&
|
||||
! ($properties2['comment'] === null && $properties1['comment'] === '')
|
||||
) {
|
||||
$changedProperties[] = 'comment';
|
||||
}
|
||||
@@ -484,7 +473,7 @@ class Comparator
|
||||
$customOptions2 = $column2->getCustomSchemaOptions();
|
||||
|
||||
foreach (array_merge(array_keys($customOptions1), array_keys($customOptions2)) as $key) {
|
||||
if ( ! array_key_exists($key, $properties1) || ! array_key_exists($key, $properties2)) {
|
||||
if (! array_key_exists($key, $properties1) || ! array_key_exists($key, $properties2)) {
|
||||
$changedProperties[] = $key;
|
||||
} elseif ($properties1[$key] !== $properties2[$key]) {
|
||||
$changedProperties[] = $key;
|
||||
@@ -495,9 +484,11 @@ class Comparator
|
||||
$platformOptions2 = $column2->getPlatformOptions();
|
||||
|
||||
foreach (array_keys(array_intersect_key($platformOptions1, $platformOptions2)) as $key) {
|
||||
if ($properties1[$key] !== $properties2[$key]) {
|
||||
$changedProperties[] = $key;
|
||||
if ($properties1[$key] === $properties2[$key]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$changedProperties[] = $key;
|
||||
}
|
||||
|
||||
return array_unique($changedProperties);
|
||||
@@ -510,7 +501,7 @@ class Comparator
|
||||
*/
|
||||
private function isALegacyJsonComparison(Types\Type $one, Types\Type $other) : bool
|
||||
{
|
||||
if ( ! $one instanceof Types\JsonType || ! $other instanceof Types\JsonType) {
|
||||
if (! $one instanceof Types\JsonType || ! $other instanceof Types\JsonType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -524,9 +515,6 @@ class Comparator
|
||||
* Compares $index1 with $index2 and returns $index2 if there are any
|
||||
* differences or false in case there are no differences.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Index $index1
|
||||
* @param \Doctrine\DBAL\Schema\Index $index2
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function diffIndex(Index $index1, Index $index2)
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -23,10 +6,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
|
||||
/**
|
||||
* Marker interface for constraints.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
interface Constraint
|
||||
{
|
||||
@@ -36,8 +15,6 @@ interface Constraint
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQuotedName(AbstractPlatform $platform);
|
||||
@@ -46,7 +23,7 @@ interface Constraint
|
||||
* Returns the names of the referencing table columns
|
||||
* the constraint is associated with.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getColumns();
|
||||
|
||||
@@ -58,9 +35,9 @@ interface Constraint
|
||||
* is a keyword reserved by the platform.
|
||||
* Otherwise the plain unquoted value as inserted is returned.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation.
|
||||
* @param AbstractPlatform $platform The platform to use for quotation.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getQuotedColumns(AbstractPlatform $platform);
|
||||
}
|
||||
|
@@ -1,24 +1,9 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use const CASE_LOWER;
|
||||
use function array_change_key_case;
|
||||
use function is_resource;
|
||||
use function strpos;
|
||||
@@ -28,10 +13,6 @@ use function trim;
|
||||
|
||||
/**
|
||||
* IBM Db2 Schema Manager.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 1.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class DB2SchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
@@ -43,8 +24,8 @@ class DB2SchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
public function listTableNames()
|
||||
{
|
||||
$sql = $this->_platform->getListTablesSQL();
|
||||
$sql .= " AND CREATOR = UPPER('".$this->_conn->getUsername()."')";
|
||||
$sql = $this->_platform->getListTablesSQL();
|
||||
$sql .= ' AND CREATOR = UPPER(' . $this->_conn->quote($this->_conn->getUsername()) . ')';
|
||||
|
||||
$tables = $this->_conn->fetchAll($sql);
|
||||
|
||||
@@ -56,35 +37,35 @@ class DB2SchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableTableColumnDefinition($tableColumn)
|
||||
{
|
||||
$tableColumn = array_change_key_case($tableColumn, \CASE_LOWER);
|
||||
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
|
||||
|
||||
$length = null;
|
||||
$fixed = null;
|
||||
$unsigned = false;
|
||||
$scale = false;
|
||||
$length = null;
|
||||
$fixed = null;
|
||||
$unsigned = false;
|
||||
$scale = false;
|
||||
$precision = false;
|
||||
|
||||
$default = null;
|
||||
|
||||
if (null !== $tableColumn['default'] && 'NULL' != $tableColumn['default']) {
|
||||
if ($tableColumn['default'] !== null && $tableColumn['default'] !== 'NULL') {
|
||||
$default = trim($tableColumn['default'], "'");
|
||||
}
|
||||
|
||||
$type = $this->_platform->getDoctrineTypeMapping($tableColumn['typename']);
|
||||
|
||||
if (isset($tableColumn['comment'])) {
|
||||
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
|
||||
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
|
||||
$tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
|
||||
}
|
||||
|
||||
switch (strtolower($tableColumn['typename'])) {
|
||||
case 'varchar':
|
||||
$length = $tableColumn['length'];
|
||||
$fixed = false;
|
||||
$fixed = false;
|
||||
break;
|
||||
case 'character':
|
||||
$length = $tableColumn['length'];
|
||||
$fixed = true;
|
||||
$fixed = true;
|
||||
break;
|
||||
case 'clob':
|
||||
$length = $tableColumn['length'];
|
||||
@@ -92,7 +73,7 @@ class DB2SchemaManager extends AbstractSchemaManager
|
||||
case 'decimal':
|
||||
case 'double':
|
||||
case 'real':
|
||||
$scale = $tableColumn['scale'];
|
||||
$scale = $tableColumn['scale'];
|
||||
$precision = $tableColumn['length'];
|
||||
break;
|
||||
}
|
||||
@@ -102,8 +83,8 @@ class DB2SchemaManager extends AbstractSchemaManager
|
||||
'unsigned' => (bool) $unsigned,
|
||||
'fixed' => (bool) $fixed,
|
||||
'default' => $default,
|
||||
'autoincrement' => (boolean) $tableColumn['autoincrement'],
|
||||
'notnull' => (bool) ($tableColumn['nulls'] == 'N'),
|
||||
'autoincrement' => (bool) $tableColumn['autoincrement'],
|
||||
'notnull' => (bool) ($tableColumn['nulls'] === 'N'),
|
||||
'scale' => null,
|
||||
'precision' => null,
|
||||
'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== ''
|
||||
@@ -113,11 +94,11 @@ class DB2SchemaManager extends AbstractSchemaManager
|
||||
];
|
||||
|
||||
if ($scale !== null && $precision !== null) {
|
||||
$options['scale'] = $scale;
|
||||
$options['scale'] = $scale;
|
||||
$options['precision'] = $precision;
|
||||
}
|
||||
|
||||
return new Column($tableColumn['colname'], \Doctrine\DBAL\Types\Type::getType($type), $options);
|
||||
return new Column($tableColumn['colname'], Type::getType($type), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +108,7 @@ class DB2SchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
$tableNames = [];
|
||||
foreach ($tables as $tableRow) {
|
||||
$tableRow = array_change_key_case($tableRow, \CASE_LOWER);
|
||||
$tableRow = array_change_key_case($tableRow, CASE_LOWER);
|
||||
$tableNames[] = $tableRow['name'];
|
||||
}
|
||||
|
||||
@@ -140,8 +121,8 @@ class DB2SchemaManager extends AbstractSchemaManager
|
||||
protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null)
|
||||
{
|
||||
foreach ($tableIndexRows as &$tableIndexRow) {
|
||||
$tableIndexRow = array_change_key_case($tableIndexRow, \CASE_LOWER);
|
||||
$tableIndexRow['primary'] = (boolean) $tableIndexRow['primary'];
|
||||
$tableIndexRow = array_change_key_case($tableIndexRow, CASE_LOWER);
|
||||
$tableIndexRow['primary'] = (bool) $tableIndexRow['primary'];
|
||||
}
|
||||
|
||||
return parent::_getPortableTableIndexesList($tableIndexRows, $tableName);
|
||||
@@ -169,9 +150,9 @@ class DB2SchemaManager extends AbstractSchemaManager
|
||||
$foreignKeys = [];
|
||||
|
||||
foreach ($tableForeignKeys as $tableForeignKey) {
|
||||
$tableForeignKey = array_change_key_case($tableForeignKey, \CASE_LOWER);
|
||||
$tableForeignKey = array_change_key_case($tableForeignKey, CASE_LOWER);
|
||||
|
||||
if (!isset($foreignKeys[$tableForeignKey['index_name']])) {
|
||||
if (! isset($foreignKeys[$tableForeignKey['index_name']])) {
|
||||
$foreignKeys[$tableForeignKey['index_name']] = [
|
||||
'local_columns' => [$tableForeignKey['local_column']],
|
||||
'foreign_table' => $tableForeignKey['foreign_table'],
|
||||
@@ -180,10 +161,10 @@ class DB2SchemaManager extends AbstractSchemaManager
|
||||
'options' => [
|
||||
'onUpdate' => $tableForeignKey['on_update'],
|
||||
'onDelete' => $tableForeignKey['on_delete'],
|
||||
]
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$foreignKeys[$tableForeignKey['index_name']]['local_columns'][] = $tableForeignKey['local_column'];
|
||||
$foreignKeys[$tableForeignKey['index_name']]['local_columns'][] = $tableForeignKey['local_column'];
|
||||
$foreignKeys[$tableForeignKey['index_name']]['foreign_columns'][] = $tableForeignKey['foreign_column'];
|
||||
}
|
||||
}
|
||||
@@ -196,10 +177,10 @@ class DB2SchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableForeignKeyRuleDef($def)
|
||||
{
|
||||
if ($def == "C") {
|
||||
return "CASCADE";
|
||||
} elseif ($def == "N") {
|
||||
return "SET NULL";
|
||||
if ($def === 'C') {
|
||||
return 'CASCADE';
|
||||
} elseif ($def === 'N') {
|
||||
return 'SET NULL';
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -210,10 +191,10 @@ class DB2SchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableViewDefinition($view)
|
||||
{
|
||||
$view = array_change_key_case($view, \CASE_LOWER);
|
||||
$view = array_change_key_case($view, CASE_LOWER);
|
||||
// sadly this still segfaults on PDO_IBM, see http://pecl.php.net/bugs/bug.php?id=17199
|
||||
//$view['text'] = (is_resource($view['text']) ? stream_get_contents($view['text']) : $view['text']);
|
||||
if (!is_resource($view['text'])) {
|
||||
if (! is_resource($view['text'])) {
|
||||
$pos = strpos($view['text'], ' AS ');
|
||||
$sql = substr($view['text'], $pos+4);
|
||||
} else {
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -26,8 +9,6 @@ use function trim;
|
||||
|
||||
/**
|
||||
* Schema manager for the Drizzle RDBMS.
|
||||
*
|
||||
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
|
||||
*/
|
||||
class DrizzleSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
@@ -38,25 +19,25 @@ class DrizzleSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
$dbType = strtolower($tableColumn['DATA_TYPE']);
|
||||
|
||||
$type = $this->_platform->getDoctrineTypeMapping($dbType);
|
||||
$type = $this->extractDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
|
||||
$type = $this->_platform->getDoctrineTypeMapping($dbType);
|
||||
$type = $this->extractDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
|
||||
$tableColumn['COLUMN_COMMENT'] = $this->removeDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
|
||||
|
||||
$options = [
|
||||
'notnull' => !(bool) $tableColumn['IS_NULLABLE'],
|
||||
'notnull' => ! (bool) $tableColumn['IS_NULLABLE'],
|
||||
'length' => (int) $tableColumn['CHARACTER_MAXIMUM_LENGTH'],
|
||||
'default' => $tableColumn['COLUMN_DEFAULT'] ?? null,
|
||||
'autoincrement' => (bool) $tableColumn['IS_AUTO_INCREMENT'],
|
||||
'scale' => (int) $tableColumn['NUMERIC_SCALE'],
|
||||
'precision' => (int) $tableColumn['NUMERIC_PRECISION'],
|
||||
'comment' => isset($tableColumn['COLUMN_COMMENT']) && '' !== $tableColumn['COLUMN_COMMENT']
|
||||
'comment' => isset($tableColumn['COLUMN_COMMENT']) && $tableColumn['COLUMN_COMMENT'] !== ''
|
||||
? $tableColumn['COLUMN_COMMENT']
|
||||
: null,
|
||||
];
|
||||
|
||||
$column = new Column($tableColumn['COLUMN_NAME'], Type::getType($type), $options);
|
||||
|
||||
if ( ! empty($tableColumn['COLLATION_NAME'])) {
|
||||
if (! empty($tableColumn['COLLATION_NAME'])) {
|
||||
$column->setPlatformOption('collation', $tableColumn['COLLATION_NAME']);
|
||||
}
|
||||
|
||||
@@ -113,8 +94,8 @@ class DrizzleSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
$indexes = [];
|
||||
foreach ($tableIndexes as $k) {
|
||||
$k['primary'] = (boolean) $k['primary'];
|
||||
$indexes[] = $k;
|
||||
$k['primary'] = (bool) $k['primary'];
|
||||
$indexes[] = $k;
|
||||
}
|
||||
|
||||
return parent::_getPortableTableIndexesList($indexes, $tableName);
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -31,18 +14,13 @@ use function strtoupper;
|
||||
|
||||
/**
|
||||
* An abstraction class for a foreign key constraint.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Steve Müller <st.mueller@dzh-online.de>
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
*/
|
||||
class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
{
|
||||
/**
|
||||
* Instance of the referencing table the foreign key constraint is associated with.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Table
|
||||
* @var Table
|
||||
*/
|
||||
protected $_localTable;
|
||||
|
||||
@@ -70,26 +48,28 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
protected $_foreignColumnNames;
|
||||
|
||||
/**
|
||||
* @var array Options associated with the foreign key constraint.
|
||||
* Options associated with the foreign key constraint.
|
||||
*
|
||||
* @var mixed[]
|
||||
*/
|
||||
protected $_options;
|
||||
|
||||
/**
|
||||
* Initializes the foreign key constraint.
|
||||
*
|
||||
* @param array $localColumnNames Names of the referencing table columns.
|
||||
* @param string[] $localColumnNames Names of the referencing table columns.
|
||||
* @param Table|string $foreignTableName Referenced table.
|
||||
* @param array $foreignColumnNames Names of the referenced table columns.
|
||||
* @param string[] $foreignColumnNames Names of the referenced table columns.
|
||||
* @param string|null $name Name of the foreign key constraint.
|
||||
* @param array $options Options associated with the foreign key constraint.
|
||||
* @param mixed[] $options Options associated with the foreign key constraint.
|
||||
*/
|
||||
public function __construct(array $localColumnNames, $foreignTableName, array $foreignColumnNames, $name = null, array $options = [])
|
||||
{
|
||||
$this->_setName($name);
|
||||
$identifierConstructorCallback = function ($column) {
|
||||
$identifierConstructorCallback = static function ($column) {
|
||||
return new Identifier($column);
|
||||
};
|
||||
$this->_localColumnNames = $localColumnNames
|
||||
$this->_localColumnNames = $localColumnNames
|
||||
? array_combine($localColumnNames, array_map($identifierConstructorCallback, $localColumnNames))
|
||||
: [];
|
||||
|
||||
@@ -102,7 +82,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
$this->_foreignColumnNames = $foreignColumnNames
|
||||
? array_combine($foreignColumnNames, array_map($identifierConstructorCallback, $foreignColumnNames))
|
||||
: [];
|
||||
$this->_options = $options;
|
||||
$this->_options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +100,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
* Sets the Table instance of the referencing table
|
||||
* the foreign key constraint is associated with.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Table $table Instance of the referencing table.
|
||||
* @param Table $table Instance of the referencing table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -141,7 +121,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
* Returns the names of the referencing table columns
|
||||
* the foreign key constraint is associated with.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getLocalColumns()
|
||||
{
|
||||
@@ -156,9 +136,9 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
* is a keyword reserved by the platform.
|
||||
* Otherwise the plain unquoted value as inserted is returned.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation.
|
||||
* @param AbstractPlatform $platform The platform to use for quotation.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getQuotedLocalColumns(AbstractPlatform $platform)
|
||||
{
|
||||
@@ -174,7 +154,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
/**
|
||||
* Returns unquoted representation of local table column names for comparison with other FK
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getUnquotedLocalColumns()
|
||||
{
|
||||
@@ -184,7 +164,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
/**
|
||||
* Returns unquoted representation of foreign table column names for comparison with other FK
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getUnquotedForeignColumns()
|
||||
{
|
||||
@@ -209,11 +189,11 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
* is a keyword reserved by the platform.
|
||||
* Otherwise the plain unquoted value as inserted is returned.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation.
|
||||
*
|
||||
* @see getQuotedLocalColumns
|
||||
*
|
||||
* @return array
|
||||
* @param AbstractPlatform $platform The platform to use for quotation.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getQuotedColumns(AbstractPlatform $platform)
|
||||
{
|
||||
@@ -238,7 +218,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
*/
|
||||
public function getUnqualifiedForeignTableName()
|
||||
{
|
||||
$parts = explode(".", $this->_foreignTableName->getName());
|
||||
$parts = explode('.', $this->_foreignTableName->getName());
|
||||
|
||||
return strtolower(end($parts));
|
||||
}
|
||||
@@ -251,7 +231,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
* is a keyword reserved by the platform.
|
||||
* Otherwise the plain unquoted value as inserted is returned.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation.
|
||||
* @param AbstractPlatform $platform The platform to use for quotation.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -264,7 +244,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
* Returns the names of the referenced table columns
|
||||
* the foreign key constraint is associated with.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getForeignColumns()
|
||||
{
|
||||
@@ -279,9 +259,9 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
* is a keyword reserved by the platform.
|
||||
* Otherwise the plain unquoted value as inserted is returned.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation.
|
||||
* @param AbstractPlatform $platform The platform to use for quotation.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getQuotedForeignColumns(AbstractPlatform $platform)
|
||||
{
|
||||
@@ -322,7 +302,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
/**
|
||||
* Returns the options associated with the foreign key constraint.
|
||||
*
|
||||
* @return array
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
@@ -364,7 +344,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
|
||||
if (isset($this->_options[$event])) {
|
||||
$onEvent = strtoupper($this->_options[$event]);
|
||||
|
||||
if ( ! in_array($onEvent, ['NO ACTION', 'RESTRICT'])) {
|
||||
if (! in_array($onEvent, ['NO ACTION', 'RESTRICT'])) {
|
||||
return $onEvent;
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -24,16 +7,10 @@ namespace Doctrine\DBAL\Schema;
|
||||
*
|
||||
* Wraps identifier names like column names in indexes / foreign keys
|
||||
* in an abstract class for proper quotation capabilities.
|
||||
*
|
||||
* @author Steve Müller <st.mueller@dzh-online.de>
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.4
|
||||
*/
|
||||
class Identifier extends AbstractAsset
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $identifier Identifier name to wrap.
|
||||
* @param bool $quote Whether to force quoting the given identifier.
|
||||
*/
|
||||
@@ -41,8 +18,10 @@ class Identifier extends AbstractAsset
|
||||
{
|
||||
$this->_setName($identifier);
|
||||
|
||||
if ($quote && ! $this->_quoted) {
|
||||
$this->_setName('"' . $this->getName() . '"');
|
||||
if (! $quote || $this->_quoted) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_setName('"' . $this->getName() . '"');
|
||||
}
|
||||
}
|
||||
|
@@ -1,28 +1,13 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use InvalidArgumentException;
|
||||
use function array_keys;
|
||||
use function array_map;
|
||||
use function array_search;
|
||||
use function array_shift;
|
||||
use function count;
|
||||
use function is_string;
|
||||
use function strtolower;
|
||||
@@ -37,21 +22,17 @@ class Index extends AbstractAsset implements Constraint
|
||||
*/
|
||||
protected $_columns = [];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
/** @var bool */
|
||||
protected $_isUnique = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
/** @var bool */
|
||||
protected $_isPrimary = false;
|
||||
|
||||
/**
|
||||
* Platform specific flags for indexes.
|
||||
* array($flagName => true)
|
||||
*
|
||||
* @var array
|
||||
* @var true[]
|
||||
*/
|
||||
protected $_flags = [];
|
||||
|
||||
@@ -59,8 +40,7 @@ class Index extends AbstractAsset implements Constraint
|
||||
* Platform specific options
|
||||
*
|
||||
* @todo $_flags should eventually be refactored into options
|
||||
*
|
||||
* @var array
|
||||
* @var mixed[]
|
||||
*/
|
||||
private $options = [];
|
||||
|
||||
@@ -70,16 +50,16 @@ class Index extends AbstractAsset implements Constraint
|
||||
* @param bool $isUnique
|
||||
* @param bool $isPrimary
|
||||
* @param string[] $flags
|
||||
* @param array $options
|
||||
* @param mixed[] $options
|
||||
*/
|
||||
public function __construct($indexName, array $columns, $isUnique = false, $isPrimary = false, array $flags = [], array $options = [])
|
||||
{
|
||||
$isUnique = $isUnique || $isPrimary;
|
||||
|
||||
$this->_setName($indexName);
|
||||
$this->_isUnique = $isUnique;
|
||||
$this->_isUnique = $isUnique;
|
||||
$this->_isPrimary = $isPrimary;
|
||||
$this->options = $options;
|
||||
$this->options = $options;
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$this->_addColumn($column);
|
||||
@@ -94,15 +74,15 @@ class Index extends AbstractAsset implements Constraint
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function _addColumn($column)
|
||||
{
|
||||
if (is_string($column)) {
|
||||
$this->_columns[$column] = new Identifier($column);
|
||||
} else {
|
||||
throw new \InvalidArgumentException("Expecting a string as Index Column");
|
||||
if (! is_string($column)) {
|
||||
throw new InvalidArgumentException('Expecting a string as Index Column');
|
||||
}
|
||||
|
||||
$this->_columns[$column] = new Identifier($column);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,10 +98,21 @@ class Index extends AbstractAsset implements Constraint
|
||||
*/
|
||||
public function getQuotedColumns(AbstractPlatform $platform)
|
||||
{
|
||||
$subParts = $platform->supportsColumnLengthIndexes() && $this->hasOption('lengths')
|
||||
? $this->getOption('lengths') : [];
|
||||
|
||||
$columns = [];
|
||||
|
||||
foreach ($this->_columns as $column) {
|
||||
$columns[] = $column->getQuotedName($platform);
|
||||
$length = array_shift($subParts);
|
||||
|
||||
$quotedColumn = $column->getQuotedName($platform);
|
||||
|
||||
if ($length !== null) {
|
||||
$quotedColumn .= '(' . $length . ')';
|
||||
}
|
||||
|
||||
$columns[] = $quotedColumn;
|
||||
}
|
||||
|
||||
return $columns;
|
||||
@@ -142,7 +133,7 @@ class Index extends AbstractAsset implements Constraint
|
||||
*/
|
||||
public function isSimpleIndex()
|
||||
{
|
||||
return !$this->_isPrimary && !$this->_isUnique;
|
||||
return ! $this->_isPrimary && ! $this->_isUnique;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +169,7 @@ class Index extends AbstractAsset implements Constraint
|
||||
/**
|
||||
* Checks if this index exactly spans the given column names in the correct order.
|
||||
*
|
||||
* @param array $columnNames
|
||||
* @param string[] $columnNames
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -189,9 +180,11 @@ class Index extends AbstractAsset implements Constraint
|
||||
$sameColumns = true;
|
||||
|
||||
for ($i = 0; $i < $numberOfColumns; $i++) {
|
||||
if ( ! isset($columnNames[$i]) || $this->trimQuotes(strtolower($columns[$i])) !== $this->trimQuotes(strtolower($columnNames[$i]))) {
|
||||
$sameColumns = false;
|
||||
if (isset($columnNames[$i]) && $this->trimQuotes(strtolower($columns[$i])) === $this->trimQuotes(strtolower($columnNames[$i]))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sameColumns = false;
|
||||
}
|
||||
|
||||
return $sameColumns;
|
||||
@@ -200,15 +193,13 @@ class Index extends AbstractAsset implements Constraint
|
||||
/**
|
||||
* Checks if the other index already fulfills all the indexing and constraint needs of the current one.
|
||||
*
|
||||
* @param Index $other
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isFullfilledBy(Index $other)
|
||||
{
|
||||
// allow the other index to be equally large only. It being larger is an option
|
||||
// but it creates a problem with scenarios of the kind PRIMARY KEY(foo,bar) UNIQUE(foo)
|
||||
if (count($other->getColumns()) != count($this->getColumns())) {
|
||||
if (count($other->getColumns()) !== count($this->getColumns())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -216,11 +207,11 @@ class Index extends AbstractAsset implements Constraint
|
||||
$sameColumns = $this->spansColumns($other->getColumns());
|
||||
|
||||
if ($sameColumns) {
|
||||
if ( ! $this->samePartialIndex($other)) {
|
||||
if (! $this->samePartialIndex($other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $this->isUnique() && ! $this->isPrimary()) {
|
||||
if (! $this->isUnique() && ! $this->isPrimary()) {
|
||||
// this is a special case: If the current key is neither primary or unique, any unique or
|
||||
// primary key will always have the same effect for the index and there cannot be any constraint
|
||||
// overlaps. This means a primary or unique index can always fulfill the requirements of just an
|
||||
@@ -228,7 +219,7 @@ class Index extends AbstractAsset implements Constraint
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($other->isPrimary() != $this->isPrimary()) {
|
||||
if ($other->isPrimary() !== $this->isPrimary()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -241,8 +232,6 @@ class Index extends AbstractAsset implements Constraint
|
||||
/**
|
||||
* Detects if the other index is a non-unique, non primary index that can be overwritten by this one.
|
||||
*
|
||||
* @param Index $other
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function overrules(Index $other)
|
||||
@@ -269,11 +258,11 @@ class Index extends AbstractAsset implements Constraint
|
||||
/**
|
||||
* Adds Flag for an index that translates to platform specific handling.
|
||||
*
|
||||
* @example $index->addFlag('CLUSTERED')
|
||||
*
|
||||
* @param string $flag
|
||||
*
|
||||
* @return Index
|
||||
*
|
||||
* @example $index->addFlag('CLUSTERED')
|
||||
*/
|
||||
public function addFlag($flag)
|
||||
{
|
||||
@@ -327,7 +316,7 @@ class Index extends AbstractAsset implements Constraint
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
@@ -336,17 +325,15 @@ class Index extends AbstractAsset implements Constraint
|
||||
|
||||
/**
|
||||
* Return whether the two indexes have the same partial index
|
||||
* @param \Doctrine\DBAL\Schema\Index $other
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function samePartialIndex(Index $other)
|
||||
{
|
||||
if ($this->hasOption('where') && $other->hasOption('where') && $this->getOption('where') == $other->getOption('where')) {
|
||||
if ($this->hasOption('where') && $other->hasOption('where') && $this->getOption('where') === $other->getOption('where')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ! $this->hasOption('where') && ! $other->hasOption('where');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -27,6 +10,7 @@ use function array_change_key_case;
|
||||
use function array_shift;
|
||||
use function array_values;
|
||||
use function end;
|
||||
use function explode;
|
||||
use function preg_match;
|
||||
use function preg_replace;
|
||||
use function str_replace;
|
||||
@@ -34,15 +18,10 @@ use function stripslashes;
|
||||
use function strpos;
|
||||
use function strtok;
|
||||
use function strtolower;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* Schema manager for the MySql RDBMS.
|
||||
*
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @since 2.0
|
||||
*/
|
||||
class MySqlSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
@@ -90,6 +69,8 @@ class MySqlSchemaManager extends AbstractSchemaManager
|
||||
} elseif (strpos($v['index_type'], 'SPATIAL') !== false) {
|
||||
$v['flags'] = ['SPATIAL'];
|
||||
}
|
||||
$v['length'] = $v['sub_part'] ?? null;
|
||||
|
||||
$tableIndexes[$k] = $v;
|
||||
}
|
||||
|
||||
@@ -125,7 +106,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
|
||||
|
||||
$fixed = null;
|
||||
|
||||
if ( ! isset($tableColumn['name'])) {
|
||||
if (! isset($tableColumn['name'])) {
|
||||
$tableColumn['name'] = '';
|
||||
}
|
||||
|
||||
@@ -233,7 +214,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
|
||||
* @link https://mariadb.com/kb/en/library/information-schema-columns-table/
|
||||
* @link https://jira.mariadb.org/browse/MDEV-13132
|
||||
*
|
||||
* @param null|string $columnDefault default value as stored in information_schema for MariaDB >= 10.2.7
|
||||
* @param string|null $columnDefault default value as stored in information_schema for MariaDB >= 10.2.7
|
||||
*/
|
||||
private function getMariaDb1027ColumnDefault(MariaDb1027Platform $platform, ?string $columnDefault) : ?string
|
||||
{
|
||||
@@ -242,7 +223,9 @@ class MySqlSchemaManager extends AbstractSchemaManager
|
||||
}
|
||||
if ($columnDefault[0] === "'") {
|
||||
return stripslashes(
|
||||
str_replace("''", "'",
|
||||
str_replace(
|
||||
"''",
|
||||
"'",
|
||||
preg_replace('/^\'(.*)\'$/', '$1', $columnDefault)
|
||||
)
|
||||
);
|
||||
@@ -266,11 +249,11 @@ class MySqlSchemaManager extends AbstractSchemaManager
|
||||
$list = [];
|
||||
foreach ($tableForeignKeys as $value) {
|
||||
$value = array_change_key_case($value, CASE_LOWER);
|
||||
if ( ! isset($list[$value['constraint_name']])) {
|
||||
if ( ! isset($value['delete_rule']) || $value['delete_rule'] === "RESTRICT") {
|
||||
if (! isset($list[$value['constraint_name']])) {
|
||||
if (! isset($value['delete_rule']) || $value['delete_rule'] === 'RESTRICT') {
|
||||
$value['delete_rule'] = null;
|
||||
}
|
||||
if ( ! isset($value['update_rule']) || $value['update_rule'] === "RESTRICT") {
|
||||
if (! isset($value['update_rule']) || $value['update_rule'] === 'RESTRICT') {
|
||||
$value['update_rule'] = null;
|
||||
}
|
||||
|
||||
@@ -303,4 +286,44 @@ class MySqlSchemaManager extends AbstractSchemaManager
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function listTableDetails($tableName)
|
||||
{
|
||||
$table = parent::listTableDetails($tableName);
|
||||
|
||||
/** @var MySqlPlatform $platform */
|
||||
$platform = $this->_platform;
|
||||
$sql = $platform->getListTableMetadataSQL($tableName);
|
||||
|
||||
$tableOptions = $this->_conn->fetchAssoc($sql);
|
||||
|
||||
$table->addOption('engine', $tableOptions['ENGINE']);
|
||||
if ($tableOptions['TABLE_COLLATION'] !== null) {
|
||||
$table->addOption('collation', $tableOptions['TABLE_COLLATION']);
|
||||
}
|
||||
if ($tableOptions['AUTO_INCREMENT'] !== null) {
|
||||
$table->addOption('autoincrement', $tableOptions['AUTO_INCREMENT']);
|
||||
}
|
||||
$table->addOption('comment', $tableOptions['TABLE_COMMENT']);
|
||||
|
||||
if ($tableOptions['CREATE_OPTIONS'] === null) {
|
||||
return $table;
|
||||
}
|
||||
|
||||
$createOptionsString = trim($tableOptions['CREATE_OPTIONS']);
|
||||
|
||||
$createOptions = [];
|
||||
|
||||
if ($createOptionsString !== '') {
|
||||
foreach (explode(' ', $createOptionsString) as $option) {
|
||||
[$createOption, $value] = explode('=', $option);
|
||||
|
||||
$createOptions[$createOption] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$table->addOption('create_options', $createOptions);
|
||||
|
||||
return $table;
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -27,7 +10,6 @@ use const CASE_LOWER;
|
||||
use function array_change_key_case;
|
||||
use function array_values;
|
||||
use function assert;
|
||||
use function is_null;
|
||||
use function preg_match;
|
||||
use function sprintf;
|
||||
use function strpos;
|
||||
@@ -37,11 +19,6 @@ use function trim;
|
||||
|
||||
/**
|
||||
* Oracle Schema Manager.
|
||||
*
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @since 2.0
|
||||
*/
|
||||
class OracleSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
@@ -78,7 +55,7 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableViewDefinition($view)
|
||||
{
|
||||
$view = \array_change_key_case($view, CASE_LOWER);
|
||||
$view = array_change_key_case($view, CASE_LOWER);
|
||||
|
||||
return new View($this->getQuotedIdentifierName($view['view_name']), $view['text']);
|
||||
}
|
||||
@@ -88,7 +65,7 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableUserDefinition($user)
|
||||
{
|
||||
$user = \array_change_key_case($user, CASE_LOWER);
|
||||
$user = array_change_key_case($user, CASE_LOWER);
|
||||
|
||||
return [
|
||||
'user' => $user['username'],
|
||||
@@ -100,7 +77,7 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableTableDefinition($table)
|
||||
{
|
||||
$table = \array_change_key_case($table, CASE_LOWER);
|
||||
$table = array_change_key_case($table, CASE_LOWER);
|
||||
|
||||
return $this->getQuotedIdentifierName($table['table_name']);
|
||||
}
|
||||
@@ -108,29 +85,28 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @license New BSD License
|
||||
* @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html
|
||||
*/
|
||||
protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
|
||||
protected function _getPortableTableIndexesList($tableIndexes, $tableName = null)
|
||||
{
|
||||
$indexBuffer = [];
|
||||
foreach ($tableIndexes as $tableIndex) {
|
||||
$tableIndex = \array_change_key_case($tableIndex, CASE_LOWER);
|
||||
$tableIndex = array_change_key_case($tableIndex, CASE_LOWER);
|
||||
|
||||
$keyName = strtolower($tableIndex['name']);
|
||||
$buffer = [];
|
||||
|
||||
if (strtolower($tableIndex['is_primary']) == "p") {
|
||||
$keyName = 'primary';
|
||||
$buffer['primary'] = true;
|
||||
if (strtolower($tableIndex['is_primary']) === 'p') {
|
||||
$keyName = 'primary';
|
||||
$buffer['primary'] = true;
|
||||
$buffer['non_unique'] = false;
|
||||
} else {
|
||||
$buffer['primary'] = false;
|
||||
$buffer['primary'] = false;
|
||||
$buffer['non_unique'] = ! $tableIndex['is_unique'];
|
||||
}
|
||||
$buffer['key_name'] = $keyName;
|
||||
$buffer['key_name'] = $keyName;
|
||||
$buffer['column_name'] = $this->getQuotedIdentifierName($tableIndex['column_name']);
|
||||
$indexBuffer[] = $buffer;
|
||||
$indexBuffer[] = $buffer;
|
||||
}
|
||||
|
||||
return parent::_getPortableTableIndexesList($indexBuffer, $tableName);
|
||||
@@ -141,20 +117,20 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableTableColumnDefinition($tableColumn)
|
||||
{
|
||||
$tableColumn = \array_change_key_case($tableColumn, CASE_LOWER);
|
||||
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
|
||||
|
||||
$dbType = strtolower($tableColumn['data_type']);
|
||||
if (strpos($dbType, "timestamp(") === 0) {
|
||||
if (strpos($dbType, "with time zone")) {
|
||||
$dbType = "timestamptz";
|
||||
if (strpos($dbType, 'timestamp(') === 0) {
|
||||
if (strpos($dbType, 'with time zone')) {
|
||||
$dbType = 'timestamptz';
|
||||
} else {
|
||||
$dbType = "timestamp";
|
||||
$dbType = 'timestamp';
|
||||
}
|
||||
}
|
||||
|
||||
$unsigned = $fixed = null;
|
||||
|
||||
if ( ! isset($tableColumn['column_name'])) {
|
||||
if (! isset($tableColumn['column_name'])) {
|
||||
$tableColumn['column_name'] = '';
|
||||
}
|
||||
|
||||
@@ -165,36 +141,36 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
$tableColumn['data_default'] = null;
|
||||
}
|
||||
|
||||
if (null !== $tableColumn['data_default']) {
|
||||
if ($tableColumn['data_default'] !== null) {
|
||||
// Default values returned from database are enclosed in single quotes.
|
||||
$tableColumn['data_default'] = trim($tableColumn['data_default'], "'");
|
||||
}
|
||||
|
||||
$precision = null;
|
||||
$scale = null;
|
||||
$scale = null;
|
||||
|
||||
$type = $this->_platform->getDoctrineTypeMapping($dbType);
|
||||
$type = $this->extractDoctrineTypeFromComment($tableColumn['comments'], $type);
|
||||
$type = $this->_platform->getDoctrineTypeMapping($dbType);
|
||||
$type = $this->extractDoctrineTypeFromComment($tableColumn['comments'], $type);
|
||||
$tableColumn['comments'] = $this->removeDoctrineTypeFromComment($tableColumn['comments'], $type);
|
||||
|
||||
switch ($dbType) {
|
||||
case 'number':
|
||||
if ($tableColumn['data_precision'] == 20 && $tableColumn['data_scale'] == 0) {
|
||||
if ($tableColumn['data_precision'] === 20 && $tableColumn['data_scale'] === 0) {
|
||||
$precision = 20;
|
||||
$scale = 0;
|
||||
$type = 'bigint';
|
||||
} elseif ($tableColumn['data_precision'] == 5 && $tableColumn['data_scale'] == 0) {
|
||||
$type = 'smallint';
|
||||
$scale = 0;
|
||||
$type = 'bigint';
|
||||
} elseif ($tableColumn['data_precision'] === 5 && $tableColumn['data_scale'] === 0) {
|
||||
$type = 'smallint';
|
||||
$precision = 5;
|
||||
$scale = 0;
|
||||
} elseif ($tableColumn['data_precision'] == 1 && $tableColumn['data_scale'] == 0) {
|
||||
$scale = 0;
|
||||
} elseif ($tableColumn['data_precision'] === 1 && $tableColumn['data_scale'] === 0) {
|
||||
$precision = 1;
|
||||
$scale = 0;
|
||||
$type = 'boolean';
|
||||
$scale = 0;
|
||||
$type = 'boolean';
|
||||
} elseif ($tableColumn['data_scale'] > 0) {
|
||||
$precision = $tableColumn['data_precision'];
|
||||
$scale = $tableColumn['data_scale'];
|
||||
$type = 'decimal';
|
||||
$scale = $tableColumn['data_scale'];
|
||||
$type = 'decimal';
|
||||
}
|
||||
$length = null;
|
||||
break;
|
||||
@@ -206,12 +182,12 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
case 'varchar2':
|
||||
case 'nvarchar2':
|
||||
$length = $tableColumn['char_length'];
|
||||
$fixed = false;
|
||||
$fixed = false;
|
||||
break;
|
||||
case 'char':
|
||||
case 'nchar':
|
||||
$length = $tableColumn['char_length'];
|
||||
$fixed = true;
|
||||
$fixed = true;
|
||||
break;
|
||||
case 'date':
|
||||
case 'timestamp':
|
||||
@@ -221,8 +197,8 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
case 'binary_float':
|
||||
case 'binary_double':
|
||||
$precision = $tableColumn['data_precision'];
|
||||
$scale = $tableColumn['data_scale'];
|
||||
$length = null;
|
||||
$scale = $tableColumn['data_scale'];
|
||||
$length = null;
|
||||
break;
|
||||
case 'clob':
|
||||
case 'nclob':
|
||||
@@ -248,7 +224,7 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
'length' => $length,
|
||||
'precision' => $precision,
|
||||
'scale' => $scale,
|
||||
'comment' => isset($tableColumn['comments']) && '' !== $tableColumn['comments']
|
||||
'comment' => isset($tableColumn['comments']) && $tableColumn['comments'] !== ''
|
||||
? $tableColumn['comments']
|
||||
: null,
|
||||
];
|
||||
@@ -263,9 +239,9 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
$list = [];
|
||||
foreach ($tableForeignKeys as $value) {
|
||||
$value = \array_change_key_case($value, CASE_LOWER);
|
||||
if (!isset($list[$value['constraint_name']])) {
|
||||
if ($value['delete_rule'] == "NO ACTION") {
|
||||
$value = array_change_key_case($value, CASE_LOWER);
|
||||
if (! isset($list[$value['constraint_name']])) {
|
||||
if ($value['delete_rule'] === 'NO ACTION') {
|
||||
$value['delete_rule'] = null;
|
||||
}
|
||||
|
||||
@@ -278,18 +254,20 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
];
|
||||
}
|
||||
|
||||
$localColumn = $this->getQuotedIdentifierName($value['local_column']);
|
||||
$localColumn = $this->getQuotedIdentifierName($value['local_column']);
|
||||
$foreignColumn = $this->getQuotedIdentifierName($value['foreign_column']);
|
||||
|
||||
$list[$value['constraint_name']]['local'][$value['position']] = $localColumn;
|
||||
$list[$value['constraint_name']]['local'][$value['position']] = $localColumn;
|
||||
$list[$value['constraint_name']]['foreign'][$value['position']] = $foreignColumn;
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($list as $constraint) {
|
||||
$result[] = new ForeignKeyConstraint(
|
||||
array_values($constraint['local']), $this->getQuotedIdentifierName($constraint['foreignTable']),
|
||||
array_values($constraint['foreign']), $this->getQuotedIdentifierName($constraint['name']),
|
||||
array_values($constraint['local']),
|
||||
$this->getQuotedIdentifierName($constraint['foreignTable']),
|
||||
array_values($constraint['foreign']),
|
||||
$this->getQuotedIdentifierName($constraint['name']),
|
||||
['onDelete' => $constraint['onDelete']]
|
||||
);
|
||||
}
|
||||
@@ -302,7 +280,7 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableSequenceDefinition($sequence)
|
||||
{
|
||||
$sequence = \array_change_key_case($sequence, CASE_LOWER);
|
||||
$sequence = array_change_key_case($sequence, CASE_LOWER);
|
||||
|
||||
return new Sequence(
|
||||
$this->getQuotedIdentifierName($sequence['sequence_name']),
|
||||
@@ -316,7 +294,7 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableFunctionDefinition($function)
|
||||
{
|
||||
$function = \array_change_key_case($function, CASE_LOWER);
|
||||
$function = array_change_key_case($function, CASE_LOWER);
|
||||
|
||||
return $function['name'];
|
||||
}
|
||||
@@ -326,7 +304,7 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableDatabaseDefinition($database)
|
||||
{
|
||||
$database = \array_change_key_case($database, CASE_LOWER);
|
||||
$database = array_change_key_case($database, CASE_LOWER);
|
||||
|
||||
return $database['username'];
|
||||
}
|
||||
@@ -340,11 +318,11 @@ class OracleSchemaManager extends AbstractSchemaManager
|
||||
$database = $this->_conn->getDatabase();
|
||||
}
|
||||
|
||||
$params = $this->_conn->getParams();
|
||||
$username = $database;
|
||||
$password = $params['password'];
|
||||
$params = $this->_conn->getParams();
|
||||
$username = $database;
|
||||
$password = $params['password'];
|
||||
|
||||
$query = 'CREATE USER ' . $username . ' IDENTIFIED BY ' . $password;
|
||||
$query = 'CREATE USER ' . $username . ' IDENTIFIED BY ' . $password;
|
||||
$this->_conn->executeUpdate($query);
|
||||
|
||||
$query = 'GRANT DBA TO ' . $username;
|
||||
@@ -423,7 +401,7 @@ SQL;
|
||||
$activeUserSessions = $this->_conn->fetchAll($sql, [strtoupper($user)]);
|
||||
|
||||
foreach ($activeUserSessions as $activeUserSession) {
|
||||
$activeUserSession = array_change_key_case($activeUserSession, \CASE_LOWER);
|
||||
$activeUserSession = array_change_key_case($activeUserSession, CASE_LOWER);
|
||||
|
||||
$this->_execSql(
|
||||
sprintf(
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -31,10 +14,11 @@ use function array_map;
|
||||
use function array_shift;
|
||||
use function assert;
|
||||
use function explode;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function join;
|
||||
use function preg_match;
|
||||
use function preg_replace;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function stripos;
|
||||
use function strlen;
|
||||
@@ -44,23 +28,16 @@ use function trim;
|
||||
|
||||
/**
|
||||
* PostgreSQL Schema Manager.
|
||||
*
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @since 2.0
|
||||
*/
|
||||
class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var string[] */
|
||||
private $existingSchemaPaths;
|
||||
|
||||
/**
|
||||
* Gets all the existing schema names.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSchemaNames()
|
||||
{
|
||||
@@ -74,12 +51,12 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
*
|
||||
* This is a PostgreSQL only function.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSchemaSearchPaths()
|
||||
{
|
||||
$params = $this->_conn->getParams();
|
||||
$schema = explode(",", $this->_conn->fetchColumn('SHOW search_path'));
|
||||
$schema = explode(',', $this->_conn->fetchColumn('SHOW search_path'));
|
||||
|
||||
if (isset($params['user'])) {
|
||||
$schema = str_replace('"$user"', $params['user'], $schema);
|
||||
@@ -93,7 +70,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
*
|
||||
* This is a PostgreSQL only function.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getExistingSchemaSearchPaths()
|
||||
{
|
||||
@@ -116,7 +93,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
$names = $this->getSchemaNames();
|
||||
$paths = $this->getSchemaSearchPaths();
|
||||
|
||||
$this->existingSchemaPaths = array_filter($paths, function ($v) use ($names) {
|
||||
$this->existingSchemaPaths = array_filter($paths, static function ($v) use ($names) {
|
||||
return in_array($v, $names);
|
||||
});
|
||||
}
|
||||
@@ -171,13 +148,16 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
if (preg_match('/FOREIGN KEY \((.+)\) REFERENCES (.+)\((.+)\)/', $tableForeignKey['condef'], $values)) {
|
||||
// PostgreSQL returns identifiers that are keywords with quotes, we need them later, don't get
|
||||
// the idea to trim them here.
|
||||
$localColumns = array_map('trim', explode(",", $values[1]));
|
||||
$foreignColumns = array_map('trim', explode(",", $values[3]));
|
||||
$foreignTable = $values[2];
|
||||
$localColumns = array_map('trim', explode(',', $values[1]));
|
||||
$foreignColumns = array_map('trim', explode(',', $values[3]));
|
||||
$foreignTable = $values[2];
|
||||
}
|
||||
|
||||
return new ForeignKeyConstraint(
|
||||
$localColumns, $foreignTable, $foreignColumns, $tableForeignKey['conname'],
|
||||
$localColumns,
|
||||
$foreignTable,
|
||||
$foreignColumns,
|
||||
$tableForeignKey['conname'],
|
||||
['onUpdate' => $onUpdate, 'onDelete' => $onDelete]
|
||||
);
|
||||
}
|
||||
@@ -195,7 +175,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableViewDefinition($view)
|
||||
{
|
||||
return new View($view['schemaname'].'.'.$view['viewname'], $view['definition']);
|
||||
return new View($view['schemaname'] . '.' . $view['viewname'], $view['definition']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,7 +185,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
return [
|
||||
'user' => $user['usename'],
|
||||
'password' => $user['passwd']
|
||||
'password' => $user['passwd'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -214,46 +194,49 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableTableDefinition($table)
|
||||
{
|
||||
$schemas = $this->getExistingSchemaSearchPaths();
|
||||
$schemas = $this->getExistingSchemaSearchPaths();
|
||||
$firstSchema = array_shift($schemas);
|
||||
|
||||
if ($table['schema_name'] == $firstSchema) {
|
||||
if ($table['schema_name'] === $firstSchema) {
|
||||
return $table['table_name'];
|
||||
}
|
||||
|
||||
return $table['schema_name'] . "." . $table['table_name'];
|
||||
return $table['schema_name'] . '.' . $table['table_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @license New BSD License
|
||||
* @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html
|
||||
*/
|
||||
protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
|
||||
protected function _getPortableTableIndexesList($tableIndexes, $tableName = null)
|
||||
{
|
||||
$buffer = [];
|
||||
foreach ($tableIndexes as $row) {
|
||||
$colNumbers = explode(' ', $row['indkey']);
|
||||
$colNumbersSql = 'IN (' . join(' ,', $colNumbers) . ' )';
|
||||
$columnNameSql = "SELECT attnum, attname FROM pg_attribute
|
||||
WHERE attrelid={$row['indrelid']} AND attnum $colNumbersSql ORDER BY attnum ASC;";
|
||||
$colNumbers = array_map('intval', explode(' ', $row['indkey']));
|
||||
$columnNameSql = sprintf(
|
||||
'SELECT attnum, attname FROM pg_attribute WHERE attrelid=%d AND attnum IN (%s) ORDER BY attnum ASC',
|
||||
$row['indrelid'],
|
||||
implode(' ,', $colNumbers)
|
||||
);
|
||||
|
||||
$stmt = $this->_conn->executeQuery($columnNameSql);
|
||||
$stmt = $this->_conn->executeQuery($columnNameSql);
|
||||
$indexColumns = $stmt->fetchAll();
|
||||
|
||||
// required for getting the order of the columns right.
|
||||
foreach ($colNumbers as $colNum) {
|
||||
foreach ($indexColumns as $colRow) {
|
||||
if ($colNum == $colRow['attnum']) {
|
||||
$buffer[] = [
|
||||
'key_name' => $row['relname'],
|
||||
'column_name' => trim($colRow['attname']),
|
||||
'non_unique' => !$row['indisunique'],
|
||||
'primary' => $row['indisprimary'],
|
||||
'where' => $row['where'],
|
||||
];
|
||||
if ($colNum !== $colRow['attnum']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$buffer[] = [
|
||||
'key_name' => $row['relname'],
|
||||
'column_name' => trim($colRow['attname']),
|
||||
'non_unique' => ! $row['indisunique'],
|
||||
'primary' => $row['indisprimary'],
|
||||
'where' => $row['where'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -277,8 +260,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
$sequenceDefinitions = [];
|
||||
|
||||
foreach ($sequences as $sequence) {
|
||||
if ($sequence['schemaname'] != 'public') {
|
||||
$sequenceName = $sequence['schemaname'] . "." . $sequence['relname'];
|
||||
if ($sequence['schemaname'] !== 'public') {
|
||||
$sequenceName = $sequence['schemaname'] . '.' . $sequence['relname'];
|
||||
} else {
|
||||
$sequenceName = $sequence['relname'];
|
||||
}
|
||||
@@ -309,14 +292,14 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
protected function _getPortableSequenceDefinition($sequence)
|
||||
{
|
||||
if ($sequence['schemaname'] !== 'public') {
|
||||
$sequenceName = $sequence['schemaname'] . "." . $sequence['relname'];
|
||||
$sequenceName = $sequence['schemaname'] . '.' . $sequence['relname'];
|
||||
} else {
|
||||
$sequenceName = $sequence['relname'];
|
||||
}
|
||||
|
||||
if ( ! isset($sequence['increment_by'], $sequence['min_value'])) {
|
||||
if (! isset($sequence['increment_by'], $sequence['min_value'])) {
|
||||
/** @var string[] $data */
|
||||
$data = $this->_conn->fetchAssoc('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));
|
||||
$data = $this->_conn->fetchAssoc('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));
|
||||
|
||||
$sequence += $data;
|
||||
}
|
||||
@@ -333,7 +316,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
|
||||
if (strtolower($tableColumn['type']) === 'varchar' || strtolower($tableColumn['type']) === 'bpchar') {
|
||||
// get length from varchar definition
|
||||
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $tableColumn['complete_type']);
|
||||
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $tableColumn['complete_type']);
|
||||
$tableColumn['length'] = $length;
|
||||
}
|
||||
|
||||
@@ -342,8 +325,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
$autoincrement = false;
|
||||
if (preg_match("/^nextval\('(.*)'(::.*)?\)$/", $tableColumn['default'], $matches)) {
|
||||
$tableColumn['sequence'] = $matches[1];
|
||||
$tableColumn['default'] = null;
|
||||
$autoincrement = true;
|
||||
$tableColumn['default'] = null;
|
||||
$autoincrement = true;
|
||||
}
|
||||
|
||||
if (preg_match("/^['(](.*)[')]::.*$/", $tableColumn['default'], $matches)) {
|
||||
@@ -355,7 +338,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
}
|
||||
|
||||
$length = $tableColumn['length'] ?? null;
|
||||
if ($length == '-1' && isset($tableColumn['atttypmod'])) {
|
||||
if ($length === '-1' && isset($tableColumn['atttypmod'])) {
|
||||
$length = $tableColumn['atttypmod'] - 4;
|
||||
}
|
||||
if ((int) $length <= 0) {
|
||||
@@ -363,40 +346,40 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
}
|
||||
$fixed = null;
|
||||
|
||||
if (!isset($tableColumn['name'])) {
|
||||
if (! isset($tableColumn['name'])) {
|
||||
$tableColumn['name'] = '';
|
||||
}
|
||||
|
||||
$precision = null;
|
||||
$scale = null;
|
||||
$jsonb = null;
|
||||
$scale = null;
|
||||
$jsonb = null;
|
||||
|
||||
$dbType = strtolower($tableColumn['type']);
|
||||
if (strlen($tableColumn['domain_type']) && !$this->_platform->hasDoctrineTypeMappingFor($tableColumn['type'])) {
|
||||
$dbType = strtolower($tableColumn['domain_type']);
|
||||
if (strlen($tableColumn['domain_type']) && ! $this->_platform->hasDoctrineTypeMappingFor($tableColumn['type'])) {
|
||||
$dbType = strtolower($tableColumn['domain_type']);
|
||||
$tableColumn['complete_type'] = $tableColumn['domain_complete_type'];
|
||||
}
|
||||
|
||||
$type = $this->_platform->getDoctrineTypeMapping($dbType);
|
||||
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
|
||||
$type = $this->_platform->getDoctrineTypeMapping($dbType);
|
||||
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
|
||||
$tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
|
||||
|
||||
switch ($dbType) {
|
||||
case 'smallint':
|
||||
case 'int2':
|
||||
$tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']);
|
||||
$length = null;
|
||||
$length = null;
|
||||
break;
|
||||
case 'int':
|
||||
case 'int4':
|
||||
case 'integer':
|
||||
$tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']);
|
||||
$length = null;
|
||||
$length = null;
|
||||
break;
|
||||
case 'bigint':
|
||||
case 'int8':
|
||||
$tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']);
|
||||
$length = null;
|
||||
$length = null;
|
||||
break;
|
||||
case 'bool':
|
||||
case 'boolean':
|
||||
@@ -435,8 +418,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
|
||||
if (preg_match('([A-Za-z]+\(([0-9]+)\,([0-9]+)\))', $tableColumn['complete_type'], $match)) {
|
||||
$precision = $match[1];
|
||||
$scale = $match[2];
|
||||
$length = null;
|
||||
$scale = $match[2];
|
||||
$length = null;
|
||||
}
|
||||
break;
|
||||
case 'year':
|
||||
@@ -469,7 +452,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
|
||||
|
||||
$column = new Column($tableColumn['field'], Type::getType($type), $options);
|
||||
|
||||
if (isset($tableColumn['collation']) && !empty($tableColumn['collation'])) {
|
||||
if (isset($tableColumn['collation']) && ! empty($tableColumn['collation'])) {
|
||||
$column->setPlatformOption('collation', $tableColumn['collation']);
|
||||
}
|
||||
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -26,10 +9,6 @@ use function preg_replace;
|
||||
|
||||
/**
|
||||
* SAP Sybase SQL Anywhere schema manager.
|
||||
*
|
||||
* @author Steve Müller <st.mueller@dzh-online.de>
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.5
|
||||
*/
|
||||
class SQLAnywhereSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
@@ -114,11 +93,11 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
|
||||
$fixed = false;
|
||||
$default = null;
|
||||
|
||||
if (null !== $tableColumn['default']) {
|
||||
if ($tableColumn['default'] !== null) {
|
||||
// Strip quotes from default value.
|
||||
$default = preg_replace(["/^'(.*)'$/", "/''/"], ["$1", "'"], $tableColumn['default']);
|
||||
$default = preg_replace(["/^'(.*)'$/", "/''/"], ['$1', "'"], $tableColumn['default']);
|
||||
|
||||
if ('autoincrement' == $default) {
|
||||
if ($default === 'autoincrement') {
|
||||
$default = null;
|
||||
}
|
||||
}
|
||||
@@ -134,14 +113,14 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
|
||||
case 'decimal':
|
||||
case 'float':
|
||||
$precision = $tableColumn['length'];
|
||||
$scale = $tableColumn['scale'];
|
||||
$scale = $tableColumn['scale'];
|
||||
}
|
||||
|
||||
return new Column(
|
||||
$tableColumn['column_name'],
|
||||
Type::getType($type),
|
||||
[
|
||||
'length' => $type == 'string' ? $tableColumn['length'] : null,
|
||||
'length' => $type === 'string' ? $tableColumn['length'] : null,
|
||||
'precision' => $precision,
|
||||
'scale' => $scale,
|
||||
'unsigned' => (bool) $tableColumn['unsigned'],
|
||||
@@ -149,7 +128,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
|
||||
'notnull' => (bool) $tableColumn['notnull'],
|
||||
'default' => $default,
|
||||
'autoincrement' => (bool) $tableColumn['autoincrement'],
|
||||
'comment' => isset($tableColumn['comment']) && '' !== $tableColumn['comment']
|
||||
'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== ''
|
||||
? $tableColumn['comment']
|
||||
: null,
|
||||
]
|
||||
@@ -186,7 +165,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
|
||||
$foreignKeys = [];
|
||||
|
||||
foreach ($tableForeignKeys as $tableForeignKey) {
|
||||
if (!isset($foreignKeys[$tableForeignKey['index_name']])) {
|
||||
if (! isset($foreignKeys[$tableForeignKey['index_name']])) {
|
||||
$foreignKeys[$tableForeignKey['index_name']] = [
|
||||
'local_columns' => [$tableForeignKey['local_column']],
|
||||
'foreign_table' => $tableForeignKey['foreign_table'],
|
||||
@@ -199,11 +178,11 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
|
||||
'onDelete' => $tableForeignKey['on_delete'],
|
||||
'check_on_commit' => $tableForeignKey['check_on_commit'],
|
||||
'clustered' => $tableForeignKey['clustered'],
|
||||
'for_olap_workload' => $tableForeignKey['for_olap_workload']
|
||||
]
|
||||
'for_olap_workload' => $tableForeignKey['for_olap_workload'],
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$foreignKeys[$tableForeignKey['index_name']]['local_columns'][] = $tableForeignKey['local_column'];
|
||||
$foreignKeys[$tableForeignKey['index_name']]['local_columns'][] = $tableForeignKey['local_column'];
|
||||
$foreignKeys[$tableForeignKey['index_name']]['foreign_columns'][] = $tableForeignKey['foreign_column'];
|
||||
}
|
||||
}
|
||||
@@ -217,8 +196,8 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
|
||||
protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null)
|
||||
{
|
||||
foreach ($tableIndexRows as &$tableIndex) {
|
||||
$tableIndex['primary'] = (boolean) $tableIndex['primary'];
|
||||
$tableIndex['flags'] = [];
|
||||
$tableIndex['primary'] = (bool) $tableIndex['primary'];
|
||||
$tableIndex['flags'] = [];
|
||||
|
||||
if ($tableIndex['clustered']) {
|
||||
$tableIndex['flags'][] = 'clustered';
|
||||
@@ -228,9 +207,11 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
|
||||
$tableIndex['flags'][] = 'with_nulls_not_distinct';
|
||||
}
|
||||
|
||||
if ($tableIndex['for_olap_workload']) {
|
||||
$tableIndex['flags'][] = 'for_olap_workload';
|
||||
if (! $tableIndex['for_olap_workload']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tableIndex['flags'][] = 'for_olap_workload';
|
||||
}
|
||||
|
||||
return parent::_getPortableTableIndexesList($tableIndexRows, $tableName);
|
||||
@@ -243,7 +224,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
return new View(
|
||||
$view['table_name'],
|
||||
preg_replace('/^.*\s+as\s+SELECT(.*)/i', "SELECT$1", $view['view_def'])
|
||||
preg_replace('/^.*\s+as\s+SELECT(.*)/i', 'SELECT$1', $view['view_def'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,27 +1,11 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\Driver\DriverException;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use PDOException;
|
||||
use function count;
|
||||
use function in_array;
|
||||
use function preg_replace;
|
||||
@@ -33,13 +17,6 @@ use function trim;
|
||||
|
||||
/**
|
||||
* SQL Server Schema Manager.
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
||||
* @author Juozas Kaziukenas <juozas@juokaz.com>
|
||||
* @author Steve Müller <st.mueller@dzh-online.de>
|
||||
* @since 2.0
|
||||
*/
|
||||
class SQLServerSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
@@ -84,19 +61,23 @@ class SQLServerSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableTableColumnDefinition($tableColumn)
|
||||
{
|
||||
$dbType = strtok($tableColumn['type'], '(), ');
|
||||
$fixed = null;
|
||||
$length = (int) $tableColumn['length'];
|
||||
$dbType = strtok($tableColumn['type'], '(), ');
|
||||
$fixed = null;
|
||||
$length = (int) $tableColumn['length'];
|
||||
$default = $tableColumn['default'];
|
||||
|
||||
if (!isset($tableColumn['name'])) {
|
||||
if (! isset($tableColumn['name'])) {
|
||||
$tableColumn['name'] = '';
|
||||
}
|
||||
|
||||
while ($default != ($default2 = preg_replace("/^\((.*)\)$/", '$1', $default))) {
|
||||
$default = trim($default2, "'");
|
||||
if ($default !== null) {
|
||||
while ($default !== ($default2 = preg_replace('/^\((.*)\)$/', '$1', $default))) {
|
||||
$default = trim($default2, "'");
|
||||
|
||||
if ($default !== 'getdate()') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($default == 'getdate()') {
|
||||
$default = $this->_platform->getCurrentTimestampSQL();
|
||||
}
|
||||
}
|
||||
@@ -106,17 +87,17 @@ class SQLServerSchemaManager extends AbstractSchemaManager
|
||||
case 'nvarchar':
|
||||
case 'ntext':
|
||||
// Unicode data requires 2 bytes per character
|
||||
$length = $length / 2;
|
||||
$length /= 2;
|
||||
break;
|
||||
case 'varchar':
|
||||
// TEXT type is returned as VARCHAR(MAX) with a length of -1
|
||||
if ($length == -1) {
|
||||
if ($length === -1) {
|
||||
$dbType = 'text';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ('char' === $dbType || 'nchar' === $dbType || 'binary' === $dbType) {
|
||||
if ($dbType === 'char' || $dbType === 'nchar' || $dbType === 'binary') {
|
||||
$fixed = true;
|
||||
}
|
||||
|
||||
@@ -125,7 +106,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
|
||||
$tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
|
||||
|
||||
$options = [
|
||||
'length' => ($length == 0 || !in_array($type, ['text', 'string'])) ? null : $length,
|
||||
'length' => $length === 0 || ! in_array($type, ['text', 'string']) ? null : $length,
|
||||
'unsigned' => false,
|
||||
'fixed' => (bool) $fixed,
|
||||
'default' => $default !== 'NULL' ? $default : null,
|
||||
@@ -153,7 +134,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
|
||||
$foreignKeys = [];
|
||||
|
||||
foreach ($tableForeignKeys as $tableForeignKey) {
|
||||
if ( ! isset($foreignKeys[$tableForeignKey['ForeignKey']])) {
|
||||
if (! isset($foreignKeys[$tableForeignKey['ForeignKey']])) {
|
||||
$foreignKeys[$tableForeignKey['ForeignKey']] = [
|
||||
'local_columns' => [$tableForeignKey['ColumnName']],
|
||||
'foreign_table' => $tableForeignKey['ReferenceTableName'],
|
||||
@@ -161,11 +142,11 @@ class SQLServerSchemaManager extends AbstractSchemaManager
|
||||
'name' => $tableForeignKey['ForeignKey'],
|
||||
'options' => [
|
||||
'onUpdate' => str_replace('_', ' ', $tableForeignKey['update_referential_action_desc']),
|
||||
'onDelete' => str_replace('_', ' ', $tableForeignKey['delete_referential_action_desc'])
|
||||
]
|
||||
'onDelete' => str_replace('_', ' ', $tableForeignKey['delete_referential_action_desc']),
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$foreignKeys[$tableForeignKey['ForeignKey']]['local_columns'][] = $tableForeignKey['ColumnName'];
|
||||
$foreignKeys[$tableForeignKey['ForeignKey']]['local_columns'][] = $tableForeignKey['ColumnName'];
|
||||
$foreignKeys[$tableForeignKey['ForeignKey']]['foreign_columns'][] = $tableForeignKey['ReferenceColumnName'];
|
||||
}
|
||||
}
|
||||
@@ -176,12 +157,12 @@ class SQLServerSchemaManager extends AbstractSchemaManager
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null)
|
||||
protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null)
|
||||
{
|
||||
foreach ($tableIndexRows as &$tableIndex) {
|
||||
$tableIndex['non_unique'] = (boolean) $tableIndex['non_unique'];
|
||||
$tableIndex['primary'] = (boolean) $tableIndex['primary'];
|
||||
$tableIndex['flags'] = $tableIndex['flags'] ? [$tableIndex['flags']] : null;
|
||||
$tableIndex['non_unique'] = (bool) $tableIndex['non_unique'];
|
||||
$tableIndex['primary'] = (bool) $tableIndex['primary'];
|
||||
$tableIndex['flags'] = $tableIndex['flags'] ? [$tableIndex['flags']] : null;
|
||||
}
|
||||
|
||||
return parent::_getPortableTableIndexesList($tableIndexRows, $tableName);
|
||||
@@ -247,18 +228,18 @@ class SQLServerSchemaManager extends AbstractSchemaManager
|
||||
|
||||
try {
|
||||
$tableIndexes = $this->_conn->fetchAll($sql);
|
||||
} catch (\PDOException $e) {
|
||||
if ($e->getCode() == "IMSSP") {
|
||||
} catch (PDOException $e) {
|
||||
if ($e->getCode() === 'IMSSP') {
|
||||
return [];
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
} catch (DBALException $e) {
|
||||
if (strpos($e->getMessage(), 'SQLSTATE [01000, 15472]') === 0) {
|
||||
return [];
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->_getPortableTableIndexesList($tableIndexes, $table);
|
||||
@@ -273,7 +254,13 @@ class SQLServerSchemaManager extends AbstractSchemaManager
|
||||
foreach ($tableDiff->removedColumns as $col) {
|
||||
$columnConstraintSql = $this->getColumnConstraintSQL($tableDiff->name, $col->getName());
|
||||
foreach ($this->_conn->fetchAll($columnConstraintSql) as $constraint) {
|
||||
$this->_conn->exec("ALTER TABLE $tableDiff->name DROP CONSTRAINT " . $constraint['Name']);
|
||||
$this->_conn->exec(
|
||||
sprintf(
|
||||
'ALTER TABLE %s DROP CONSTRAINT %s',
|
||||
$tableDiff->name,
|
||||
$constraint['Name']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -296,8 +283,8 @@ class SQLServerSchemaManager extends AbstractSchemaManager
|
||||
ON Tab.[ID] = Sysobjects.[Parent_Obj]
|
||||
INNER JOIN sys.default_constraints DefCons ON DefCons.[object_id] = Sysobjects.[ID]
|
||||
INNER JOIN SysColumns Col ON Col.[ColID] = DefCons.[parent_column_id] AND Col.[ID] = Tab.[ID]
|
||||
WHERE Col.[Name] = " . $this->_conn->quote($column) ." AND Tab.[Name] = " . $this->_conn->quote($table) . "
|
||||
ORDER BY Col.[Name]";
|
||||
WHERE Col.[Name] = " . $this->_conn->quote($column) . ' AND Tab.[Name] = ' . $this->_conn->quote($table) . '
|
||||
ORDER BY Col.[Name]';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,29 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector;
|
||||
use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector;
|
||||
use Doctrine\DBAL\Schema\Visitor\NamespaceVisitor;
|
||||
use Doctrine\DBAL\Schema\Visitor\Visitor;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use function array_keys;
|
||||
use function strpos;
|
||||
use function strtolower;
|
||||
@@ -51,48 +34,37 @@ use function strtolower;
|
||||
* the CREATE/DROP SQL visitors will just filter this queries and do not
|
||||
* execute them. Only the queries for the currently connected database are
|
||||
* executed.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class Schema extends AbstractAsset
|
||||
{
|
||||
/**
|
||||
* The namespaces in this schema.
|
||||
*
|
||||
* @var array
|
||||
* @var string[]
|
||||
*/
|
||||
private $namespaces = [];
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Table[]
|
||||
*/
|
||||
/** @var Table[] */
|
||||
protected $_tables = [];
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Sequence[]
|
||||
*/
|
||||
/** @var Sequence[] */
|
||||
protected $_sequences = [];
|
||||
|
||||
/**
|
||||
* @var SchemaConfig
|
||||
*/
|
||||
/** @var SchemaConfig */
|
||||
protected $_schemaConfig = false;
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table[] $tables
|
||||
* @param \Doctrine\DBAL\Schema\Sequence[] $sequences
|
||||
* @param \Doctrine\DBAL\Schema\SchemaConfig $schemaConfig
|
||||
* @param array $namespaces
|
||||
* @param Table[] $tables
|
||||
* @param Sequence[] $sequences
|
||||
* @param string[] $namespaces
|
||||
*/
|
||||
public function __construct(
|
||||
array $tables = [],
|
||||
array $sequences = [],
|
||||
SchemaConfig $schemaConfig = null,
|
||||
?SchemaConfig $schemaConfig = null,
|
||||
array $namespaces = []
|
||||
) {
|
||||
if ($schemaConfig == null) {
|
||||
if ($schemaConfig === null) {
|
||||
$schemaConfig = new SchemaConfig();
|
||||
}
|
||||
$this->_schemaConfig = $schemaConfig;
|
||||
@@ -120,22 +92,20 @@ class Schema extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
* @throws SchemaException
|
||||
*/
|
||||
protected function _addTable(Table $table)
|
||||
{
|
||||
$namespaceName = $table->getNamespaceName();
|
||||
$tableName = $table->getFullQualifiedName($this->getName());
|
||||
$tableName = $table->getFullQualifiedName($this->getName());
|
||||
|
||||
if (isset($this->_tables[$tableName])) {
|
||||
throw SchemaException::tableAlreadyExists($tableName);
|
||||
}
|
||||
|
||||
if ( ! $table->isInDefaultNamespace($this->getName()) && ! $this->hasNamespace($namespaceName)) {
|
||||
if (! $table->isInDefaultNamespace($this->getName()) && ! $this->hasNamespace($namespaceName)) {
|
||||
$this->createNamespace($namespaceName);
|
||||
}
|
||||
|
||||
@@ -144,22 +114,20 @@ class Schema extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
* @throws SchemaException
|
||||
*/
|
||||
protected function _addSequence(Sequence $sequence)
|
||||
{
|
||||
$namespaceName = $sequence->getNamespaceName();
|
||||
$seqName = $sequence->getFullQualifiedName($this->getName());
|
||||
$seqName = $sequence->getFullQualifiedName($this->getName());
|
||||
|
||||
if (isset($this->_sequences[$seqName])) {
|
||||
throw SchemaException::sequenceAlreadyExists($seqName);
|
||||
}
|
||||
|
||||
if ( ! $sequence->isInDefaultNamespace($this->getName()) && ! $this->hasNamespace($namespaceName)) {
|
||||
if (! $sequence->isInDefaultNamespace($this->getName()) && ! $this->hasNamespace($namespaceName)) {
|
||||
$this->createNamespace($namespaceName);
|
||||
}
|
||||
|
||||
@@ -169,7 +137,7 @@ class Schema extends AbstractAsset
|
||||
/**
|
||||
* Returns the namespaces of this schema.
|
||||
*
|
||||
* @return array A list of namespace names.
|
||||
* @return string[] A list of namespace names.
|
||||
*/
|
||||
public function getNamespaces()
|
||||
{
|
||||
@@ -179,7 +147,7 @@ class Schema extends AbstractAsset
|
||||
/**
|
||||
* Gets all tables of this schema.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table[]
|
||||
* @return Table[]
|
||||
*/
|
||||
public function getTables()
|
||||
{
|
||||
@@ -189,14 +157,14 @@ class Schema extends AbstractAsset
|
||||
/**
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
* @return Table
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
* @throws SchemaException
|
||||
*/
|
||||
public function getTable($tableName)
|
||||
{
|
||||
$tableName = $this->getFullQualifiedAssetName($tableName);
|
||||
if (!isset($this->_tables[$tableName])) {
|
||||
if (! isset($this->_tables[$tableName])) {
|
||||
throw SchemaException::tableDoesNotExist($tableName);
|
||||
}
|
||||
|
||||
@@ -212,8 +180,8 @@ class Schema extends AbstractAsset
|
||||
{
|
||||
$name = $this->getUnquotedAssetName($name);
|
||||
|
||||
if (strpos($name, ".") === false) {
|
||||
$name = $this->getName() . "." . $name;
|
||||
if (strpos($name, '.') === false) {
|
||||
$name = $this->getName() . '.' . $name;
|
||||
}
|
||||
|
||||
return strtolower($name);
|
||||
@@ -266,7 +234,7 @@ class Schema extends AbstractAsset
|
||||
/**
|
||||
* Gets all table names, prefixed with a schema name, even the default one if present.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getTableNames()
|
||||
{
|
||||
@@ -288,14 +256,14 @@ class Schema extends AbstractAsset
|
||||
/**
|
||||
* @param string $sequenceName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Sequence
|
||||
* @return Sequence
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
* @throws SchemaException
|
||||
*/
|
||||
public function getSequence($sequenceName)
|
||||
{
|
||||
$sequenceName = $this->getFullQualifiedAssetName($sequenceName);
|
||||
if (!$this->hasSequence($sequenceName)) {
|
||||
if (! $this->hasSequence($sequenceName)) {
|
||||
throw SchemaException::sequenceDoesNotExist($sequenceName);
|
||||
}
|
||||
|
||||
@@ -303,7 +271,7 @@ class Schema extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Doctrine\DBAL\Schema\Sequence[]
|
||||
* @return Sequence[]
|
||||
*/
|
||||
public function getSequences()
|
||||
{
|
||||
@@ -337,7 +305,7 @@ class Schema extends AbstractAsset
|
||||
*
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
* @return Table
|
||||
*/
|
||||
public function createTable($tableName)
|
||||
{
|
||||
@@ -393,9 +361,9 @@ class Schema extends AbstractAsset
|
||||
* @param int $allocationSize
|
||||
* @param int $initialValue
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Sequence
|
||||
* @return Sequence
|
||||
*/
|
||||
public function createSequence($sequenceName, $allocationSize=1, $initialValue=1)
|
||||
public function createSequence($sequenceName, $allocationSize = 1, $initialValue = 1)
|
||||
{
|
||||
$seq = new Sequence($sequenceName, $allocationSize, $initialValue);
|
||||
$this->_addSequence($seq);
|
||||
@@ -419,9 +387,7 @@ class Schema extends AbstractAsset
|
||||
/**
|
||||
* Returns an array of necessary SQL queries to create the schema on the given platform.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function toSql(AbstractPlatform $platform)
|
||||
{
|
||||
@@ -434,9 +400,7 @@ class Schema extends AbstractAsset
|
||||
/**
|
||||
* Return an array of necessary SQL queries to drop the schema on the given platform.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function toDropSql(AbstractPlatform $platform)
|
||||
{
|
||||
@@ -447,10 +411,7 @@ class Schema extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Schema $toSchema
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform)
|
||||
{
|
||||
@@ -461,10 +422,7 @@ class Schema extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Schema $fromSchema
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform)
|
||||
{
|
||||
@@ -475,8 +433,6 @@ class Schema extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Visitor\Visitor $visitor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function visit(Visitor $visitor)
|
||||
|
@@ -1,51 +1,22 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
/**
|
||||
* Configuration for a Schema.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class SchemaConfig
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
/** @var bool */
|
||||
protected $hasExplicitForeignKeyIndexes = false;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
/** @var int */
|
||||
protected $maxIdentifierLength = 63;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
/** @var string */
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var mixed[] */
|
||||
protected $defaultTableOptions = [];
|
||||
|
||||
/**
|
||||
@@ -110,7 +81,7 @@ class SchemaConfig
|
||||
* Gets the default options that are passed to Table instances created with
|
||||
* Schema#createTable().
|
||||
*
|
||||
* @return array
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getDefaultTableOptions()
|
||||
{
|
||||
@@ -118,7 +89,7 @@ class SchemaConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $defaultTableOptions
|
||||
* @param mixed[] $defaultTableOptions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@@ -1,41 +1,16 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
use \Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use function array_merge;
|
||||
|
||||
/**
|
||||
* Schema Diff.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class SchemaDiff
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Schema
|
||||
*/
|
||||
/** @var Schema */
|
||||
public $fromSchema;
|
||||
|
||||
/**
|
||||
@@ -55,53 +30,44 @@ class SchemaDiff
|
||||
/**
|
||||
* All added tables.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Table[]
|
||||
* @var Table[]
|
||||
*/
|
||||
public $newTables = [];
|
||||
|
||||
/**
|
||||
* All changed tables.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\TableDiff[]
|
||||
* @var TableDiff[]
|
||||
*/
|
||||
public $changedTables = [];
|
||||
|
||||
/**
|
||||
* All removed tables.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Table[]
|
||||
* @var Table[]
|
||||
*/
|
||||
public $removedTables = [];
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Sequence[]
|
||||
*/
|
||||
/** @var Sequence[] */
|
||||
public $newSequences = [];
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Sequence[]
|
||||
*/
|
||||
/** @var Sequence[] */
|
||||
public $changedSequences = [];
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Sequence[]
|
||||
*/
|
||||
/** @var Sequence[] */
|
||||
public $removedSequences = [];
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
|
||||
*/
|
||||
/** @var ForeignKeyConstraint[] */
|
||||
public $orphanedForeignKeys = [];
|
||||
|
||||
/**
|
||||
* Constructs an SchemaDiff object.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Table[] $newTables
|
||||
* @param \Doctrine\DBAL\Schema\TableDiff[] $changedTables
|
||||
* @param \Doctrine\DBAL\Schema\Table[] $removedTables
|
||||
* @param \Doctrine\DBAL\Schema\Schema|null $fromSchema
|
||||
* @param Table[] $newTables
|
||||
* @param TableDiff[] $changedTables
|
||||
* @param Table[] $removedTables
|
||||
*/
|
||||
public function __construct($newTables = [], $changedTables = [], $removedTables = [], Schema $fromSchema = null)
|
||||
public function __construct($newTables = [], $changedTables = [], $removedTables = [], ?Schema $fromSchema = null)
|
||||
{
|
||||
$this->newTables = $newTables;
|
||||
$this->changedTables = $changedTables;
|
||||
@@ -118,9 +84,7 @@ class SchemaDiff
|
||||
*
|
||||
* This way it is ensured that assets are deleted which might not be relevant to the metadata schema at all.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function toSaveSql(AbstractPlatform $platform)
|
||||
{
|
||||
@@ -128,9 +92,7 @@ class SchemaDiff
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function toSql(AbstractPlatform $platform)
|
||||
{
|
||||
@@ -138,10 +100,9 @@ class SchemaDiff
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
* @param bool $saveMode
|
||||
* @param bool $saveMode
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
protected function _toSql(AbstractPlatform $platform, $saveMode = false)
|
||||
{
|
||||
@@ -153,13 +114,13 @@ class SchemaDiff
|
||||
}
|
||||
}
|
||||
|
||||
if ($platform->supportsForeignKeyConstraints() && $saveMode == false) {
|
||||
if ($platform->supportsForeignKeyConstraints() && $saveMode === false) {
|
||||
foreach ($this->orphanedForeignKeys as $orphanedForeignKey) {
|
||||
$sql[] = $platform->getDropForeignKeySQL($orphanedForeignKey, $orphanedForeignKey->getLocalTable());
|
||||
}
|
||||
}
|
||||
|
||||
if ($platform->supportsSequences() == true) {
|
||||
if ($platform->supportsSequences() === true) {
|
||||
foreach ($this->changedSequences as $sequence) {
|
||||
$sql[] = $platform->getAlterSequenceSQL($sequence);
|
||||
}
|
||||
@@ -182,10 +143,12 @@ class SchemaDiff
|
||||
$platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES)
|
||||
);
|
||||
|
||||
if ($platform->supportsForeignKeyConstraints()) {
|
||||
foreach ($table->getForeignKeys() as $foreignKey) {
|
||||
$foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table);
|
||||
}
|
||||
if (! $platform->supportsForeignKeyConstraints()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($table->getForeignKeys() as $foreignKey) {
|
||||
$foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table);
|
||||
}
|
||||
}
|
||||
$sql = array_merge($sql, $foreignKeySql);
|
||||
|
@@ -1,40 +1,24 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use function implode;
|
||||
use function sprintf;
|
||||
|
||||
class SchemaException extends \Doctrine\DBAL\DBALException
|
||||
class SchemaException extends DBALException
|
||||
{
|
||||
const TABLE_DOESNT_EXIST = 10;
|
||||
const TABLE_ALREADY_EXISTS = 20;
|
||||
const COLUMN_DOESNT_EXIST = 30;
|
||||
const COLUMN_ALREADY_EXISTS = 40;
|
||||
const INDEX_DOESNT_EXIST = 50;
|
||||
const INDEX_ALREADY_EXISTS = 60;
|
||||
const SEQUENCE_DOENST_EXIST = 70;
|
||||
const SEQUENCE_ALREADY_EXISTS = 80;
|
||||
const INDEX_INVALID_NAME = 90;
|
||||
const FOREIGNKEY_DOESNT_EXIST = 100;
|
||||
const NAMESPACE_ALREADY_EXISTS = 110;
|
||||
public const TABLE_DOESNT_EXIST = 10;
|
||||
public const TABLE_ALREADY_EXISTS = 20;
|
||||
public const COLUMN_DOESNT_EXIST = 30;
|
||||
public const COLUMN_ALREADY_EXISTS = 40;
|
||||
public const INDEX_DOESNT_EXIST = 50;
|
||||
public const INDEX_ALREADY_EXISTS = 60;
|
||||
public const SEQUENCE_DOENST_EXIST = 70;
|
||||
public const SEQUENCE_ALREADY_EXISTS = 80;
|
||||
public const INDEX_INVALID_NAME = 90;
|
||||
public const FOREIGNKEY_DOESNT_EXIST = 100;
|
||||
public const NAMESPACE_ALREADY_EXISTS = 110;
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
@@ -43,7 +27,7 @@ class SchemaException extends \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public static function tableDoesNotExist($tableName)
|
||||
{
|
||||
return new self("There is no table with name '".$tableName."' in the schema.", self::TABLE_DOESNT_EXIST);
|
||||
return new self("There is no table with name '" . $tableName . "' in the schema.", self::TABLE_DOESNT_EXIST);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +37,10 @@ class SchemaException extends \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public static function indexNameInvalid($indexName)
|
||||
{
|
||||
return new self("Invalid index-name $indexName given, has to be [a-zA-Z0-9_]", self::INDEX_INVALID_NAME);
|
||||
return new self(
|
||||
sprintf('Invalid index-name %s given, has to be [a-zA-Z0-9_]', $indexName),
|
||||
self::INDEX_INVALID_NAME
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,7 +51,10 @@ class SchemaException extends \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public static function indexDoesNotExist($indexName, $table)
|
||||
{
|
||||
return new self("Index '$indexName' does not exist on table '$table'.", self::INDEX_DOESNT_EXIST);
|
||||
return new self(
|
||||
sprintf("Index '%s' does not exist on table '%s'.", $indexName, $table),
|
||||
self::INDEX_DOESNT_EXIST
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +65,10 @@ class SchemaException extends \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public static function indexAlreadyExists($indexName, $table)
|
||||
{
|
||||
return new self("An index with name '$indexName' was already defined on table '$table'.", self::INDEX_ALREADY_EXISTS);
|
||||
return new self(
|
||||
sprintf("An index with name '%s' was already defined on table '%s'.", $indexName, $table),
|
||||
self::INDEX_ALREADY_EXISTS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,7 +79,10 @@ class SchemaException extends \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public static function columnDoesNotExist($columnName, $table)
|
||||
{
|
||||
return new self("There is no column with name '$columnName' on table '$table'.", self::COLUMN_DOESNT_EXIST);
|
||||
return new self(
|
||||
sprintf("There is no column with name '%s' on table '%s'.", $columnName, $table),
|
||||
self::COLUMN_DOESNT_EXIST
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +105,7 @@ class SchemaException extends \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public static function tableAlreadyExists($tableName)
|
||||
{
|
||||
return new self("The table with name '".$tableName."' already exists.", self::TABLE_ALREADY_EXISTS);
|
||||
return new self("The table with name '" . $tableName . "' already exists.", self::TABLE_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,7 +117,8 @@ class SchemaException extends \Doctrine\DBAL\DBALException
|
||||
public static function columnAlreadyExists($tableName, $columnName)
|
||||
{
|
||||
return new self(
|
||||
"The column '".$columnName."' on table '".$tableName."' already exists.", self::COLUMN_ALREADY_EXISTS
|
||||
"The column '" . $columnName . "' on table '" . $tableName . "' already exists.",
|
||||
self::COLUMN_ALREADY_EXISTS
|
||||
);
|
||||
}
|
||||
|
||||
@@ -132,7 +129,7 @@ class SchemaException extends \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public static function sequenceAlreadyExists($sequenceName)
|
||||
{
|
||||
return new self("The sequence '".$sequenceName."' already exists.", self::SEQUENCE_ALREADY_EXISTS);
|
||||
return new self("The sequence '" . $sequenceName . "' already exists.", self::SEQUENCE_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +139,7 @@ class SchemaException extends \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public static function sequenceDoesNotExist($sequenceName)
|
||||
{
|
||||
return new self("There exists no sequence with the name '".$sequenceName."'.", self::SEQUENCE_DOENST_EXIST);
|
||||
return new self("There exists no sequence with the name '" . $sequenceName . "'.", self::SEQUENCE_DOENST_EXIST);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,22 +150,22 @@ class SchemaException extends \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public static function foreignKeyDoesNotExist($fkName, $table)
|
||||
{
|
||||
return new self("There exists no foreign key with the name '$fkName' on table '$table'.", self::FOREIGNKEY_DOESNT_EXIST);
|
||||
return new self(
|
||||
sprintf("There exists no foreign key with the name '%s' on table '%s'.", $fkName, $table),
|
||||
self::FOREIGNKEY_DOESNT_EXIST
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $localTable
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
public static function namedForeignKeyRequired(Table $localTable, ForeignKeyConstraint $foreignKey)
|
||||
{
|
||||
return new self(
|
||||
"The performed schema operation on ".$localTable->getName()." requires a named foreign key, ".
|
||||
"but the given foreign key from (".implode(", ", $foreignKey->getColumns()).") onto foreign table ".
|
||||
"'".$foreignKey->getForeignTableName()."' (".implode(", ", $foreignKey->getForeignColumns()).") is currently ".
|
||||
"unnamed."
|
||||
'The performed schema operation on ' . $localTable->getName() . ' requires a named foreign key, ' .
|
||||
'but the given foreign key from (' . implode(', ', $foreignKey->getColumns()) . ') onto foreign table ' .
|
||||
"'" . $foreignKey->getForeignTableName() . "' (" . implode(', ', $foreignKey->getForeignColumns()) . ') is currently ' .
|
||||
'unnamed.'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -179,6 +176,8 @@ class SchemaException extends \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public static function alterTableChangeNotSupported($changeName)
|
||||
{
|
||||
return new self("Alter table change not supported, given '$changeName'");
|
||||
return new self(
|
||||
sprintf("Alter table change not supported, given '%s'", $changeName)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -26,26 +9,16 @@ use function sprintf;
|
||||
|
||||
/**
|
||||
* Sequence structure.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class Sequence extends AbstractAsset
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
/** @var int */
|
||||
protected $allocationSize = 1;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
/** @var int */
|
||||
protected $initialValue = 1;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
/** @var int|null */
|
||||
protected $cache = null;
|
||||
|
||||
/**
|
||||
@@ -57,9 +30,9 @@ class Sequence extends AbstractAsset
|
||||
public function __construct($name, $allocationSize = 1, $initialValue = 1, $cache = null)
|
||||
{
|
||||
$this->_setName($name);
|
||||
$this->allocationSize = is_numeric($allocationSize) ? $allocationSize : 1;
|
||||
$this->initialValue = is_numeric($initialValue) ? $initialValue : 1;
|
||||
$this->cache = $cache;
|
||||
$this->setAllocationSize($allocationSize);
|
||||
$this->setInitialValue($initialValue);
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +66,7 @@ class Sequence extends AbstractAsset
|
||||
*/
|
||||
public function setAllocationSize($allocationSize)
|
||||
{
|
||||
$this->allocationSize = is_numeric($allocationSize) ? $allocationSize : 1;
|
||||
$this->allocationSize = is_numeric($allocationSize) ? (int) $allocationSize : 1;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -105,7 +78,7 @@ class Sequence extends AbstractAsset
|
||||
*/
|
||||
public function setInitialValue($initialValue)
|
||||
{
|
||||
$this->initialValue = is_numeric($initialValue) ? $initialValue : 1;
|
||||
$this->initialValue = is_numeric($initialValue) ? (int) $initialValue : 1;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -128,25 +101,23 @@ class Sequence extends AbstractAsset
|
||||
* This is used inside the comparator to not report sequences as missing,
|
||||
* when the "from" schema implicitly creates the sequences.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAutoIncrementsFor(Table $table)
|
||||
{
|
||||
if ( ! $table->hasPrimaryKey()) {
|
||||
if (! $table->hasPrimaryKey()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$pkColumns = $table->getPrimaryKey()->getColumns();
|
||||
|
||||
if (count($pkColumns) != 1) {
|
||||
if (count($pkColumns) !== 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$column = $table->getColumn($pkColumns[0]);
|
||||
|
||||
if ( ! $column->getAutoincrement()) {
|
||||
if (! $column->getAutoincrement()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -158,8 +129,6 @@ class Sequence extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Visitor\Visitor $visitor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function visit(Visitor $visitor)
|
||||
|
@@ -1,25 +1,9 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
use Doctrine\DBAL\FetchMode;
|
||||
use Doctrine\DBAL\Types\StringType;
|
||||
use Doctrine\DBAL\Types\TextType;
|
||||
@@ -46,12 +30,6 @@ use function usort;
|
||||
|
||||
/**
|
||||
* Sqlite SchemaManager.
|
||||
*
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
* @author Martin Hasoň <martin.hason@gmail.com>
|
||||
* @since 2.0
|
||||
*/
|
||||
class SqliteSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
@@ -60,9 +38,11 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
public function dropDatabase($database)
|
||||
{
|
||||
if (file_exists($database)) {
|
||||
unlink($database);
|
||||
if (! file_exists($database)) {
|
||||
return;
|
||||
}
|
||||
|
||||
unlink($database);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,13 +50,13 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
public function createDatabase($database)
|
||||
{
|
||||
$params = $this->_conn->getParams();
|
||||
$driver = $params['driver'];
|
||||
$params = $this->_conn->getParams();
|
||||
$driver = $params['driver'];
|
||||
$options = [
|
||||
'driver' => $driver,
|
||||
'path' => $database
|
||||
'path' => $database,
|
||||
];
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
||||
$conn = DriverManager::getConnection($options);
|
||||
$conn->connect();
|
||||
$conn->close();
|
||||
}
|
||||
@@ -86,9 +66,9 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
public function renameTable($name, $newName)
|
||||
{
|
||||
$tableDiff = new TableDiff($name);
|
||||
$tableDiff = new TableDiff($name);
|
||||
$tableDiff->fromTable = $this->listTableDetails($name);
|
||||
$tableDiff->newName = $newName;
|
||||
$tableDiff->newName = $newName;
|
||||
$this->alterTable($tableDiff);
|
||||
}
|
||||
|
||||
@@ -97,7 +77,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
public function createForeignKey(ForeignKeyConstraint $foreignKey, $table)
|
||||
{
|
||||
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table);
|
||||
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table);
|
||||
$tableDiff->addedForeignKeys[] = $foreignKey;
|
||||
|
||||
$this->alterTable($tableDiff);
|
||||
@@ -108,7 +88,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table)
|
||||
{
|
||||
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table);
|
||||
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table);
|
||||
$tableDiff->changedForeignKeys[] = $foreignKey;
|
||||
|
||||
$this->alterTable($tableDiff);
|
||||
@@ -119,7 +99,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
public function dropForeignKey($foreignKey, $table)
|
||||
{
|
||||
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table);
|
||||
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table);
|
||||
$tableDiff->removedForeignKeys[] = $foreignKey;
|
||||
|
||||
$this->alterTable($tableDiff);
|
||||
@@ -130,17 +110,17 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
public function listTableForeignKeys($table, $database = null)
|
||||
{
|
||||
if (null === $database) {
|
||||
if ($database === null) {
|
||||
$database = $this->_conn->getDatabase();
|
||||
}
|
||||
$sql = $this->_platform->getListTableForeignKeysSQL($table, $database);
|
||||
$sql = $this->_platform->getListTableForeignKeysSQL($table, $database);
|
||||
$tableForeignKeys = $this->_conn->fetchAll($sql);
|
||||
|
||||
if ( ! empty($tableForeignKeys)) {
|
||||
$createSql = $this->_conn->fetchAll("SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type = 'table' AND name = '$table'");
|
||||
$createSql = $createSql[0]['sql'] ?? '';
|
||||
if (! empty($tableForeignKeys)) {
|
||||
$createSql = $this->getCreateTableSQL($table);
|
||||
|
||||
if (preg_match_all('#
|
||||
if ($createSql !== null && preg_match_all(
|
||||
'#
|
||||
(?:CONSTRAINT\s+([^\s]+)\s+)?
|
||||
(?:FOREIGN\s+KEY[^\)]+\)\s*)?
|
||||
REFERENCES\s+[^\s]+\s+(?:\([^\)]+\))?
|
||||
@@ -149,18 +129,19 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
(NOT\s+DEFERRABLE|DEFERRABLE)
|
||||
(?:\s+INITIALLY\s+(DEFERRED|IMMEDIATE))?
|
||||
)?#isx',
|
||||
$createSql, $match)) {
|
||||
|
||||
$names = array_reverse($match[1]);
|
||||
$createSql,
|
||||
$match
|
||||
)) {
|
||||
$names = array_reverse($match[1]);
|
||||
$deferrable = array_reverse($match[2]);
|
||||
$deferred = array_reverse($match[3]);
|
||||
$deferred = array_reverse($match[3]);
|
||||
} else {
|
||||
$names = $deferrable = $deferred = [];
|
||||
}
|
||||
|
||||
foreach ($tableForeignKeys as $key => $value) {
|
||||
$id = $value['id'];
|
||||
$tableForeignKeys[$key]['constraint_name'] = isset($names[$id]) && '' != $names[$id] ? $names[$id] : $id;
|
||||
$id = $value['id'];
|
||||
$tableForeignKeys[$key]['constraint_name'] = isset($names[$id]) && $names[$id] !== '' ? $names[$id] : $id;
|
||||
$tableForeignKeys[$key]['deferrable'] = isset($deferrable[$id]) && strtolower($deferrable[$id]) === 'deferrable';
|
||||
$tableForeignKeys[$key]['deferred'] = isset($deferred[$id]) && strtolower($deferred[$id]) === 'deferred';
|
||||
}
|
||||
@@ -180,52 +161,61 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @license New BSD License
|
||||
* @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html
|
||||
*/
|
||||
protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
|
||||
protected function _getPortableTableIndexesList($tableIndexes, $tableName = null)
|
||||
{
|
||||
$indexBuffer = [];
|
||||
|
||||
// fetch primary
|
||||
$stmt = $this->_conn->executeQuery("PRAGMA TABLE_INFO ('$tableName')");
|
||||
$stmt = $this->_conn->executeQuery(sprintf(
|
||||
'PRAGMA TABLE_INFO (%s)',
|
||||
$this->_conn->quote($tableName)
|
||||
));
|
||||
$indexArray = $stmt->fetchAll(FetchMode::ASSOCIATIVE);
|
||||
|
||||
usort($indexArray, function($a, $b) {
|
||||
if ($a['pk'] == $b['pk']) {
|
||||
usort($indexArray, static function ($a, $b) {
|
||||
if ($a['pk'] === $b['pk']) {
|
||||
return $a['cid'] - $b['cid'];
|
||||
}
|
||||
|
||||
return $a['pk'] - $b['pk'];
|
||||
});
|
||||
foreach ($indexArray as $indexColumnRow) {
|
||||
if ($indexColumnRow['pk'] != "0") {
|
||||
$indexBuffer[] = [
|
||||
'key_name' => 'primary',
|
||||
'primary' => true,
|
||||
'non_unique' => false,
|
||||
'column_name' => $indexColumnRow['name']
|
||||
];
|
||||
if ($indexColumnRow['pk'] === '0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$indexBuffer[] = [
|
||||
'key_name' => 'primary',
|
||||
'primary' => true,
|
||||
'non_unique' => false,
|
||||
'column_name' => $indexColumnRow['name'],
|
||||
];
|
||||
}
|
||||
|
||||
// fetch regular indexes
|
||||
foreach ($tableIndexes as $tableIndex) {
|
||||
// Ignore indexes with reserved names, e.g. autoindexes
|
||||
if (strpos($tableIndex['name'], 'sqlite_') !== 0) {
|
||||
$keyName = $tableIndex['name'];
|
||||
$idx = [];
|
||||
$idx['key_name'] = $keyName;
|
||||
$idx['primary'] = false;
|
||||
$idx['non_unique'] = $tableIndex['unique']?false:true;
|
||||
if (strpos($tableIndex['name'], 'sqlite_') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$stmt = $this->_conn->executeQuery("PRAGMA INDEX_INFO ('{$keyName}')");
|
||||
$keyName = $tableIndex['name'];
|
||||
$idx = [];
|
||||
$idx['key_name'] = $keyName;
|
||||
$idx['primary'] = false;
|
||||
$idx['non_unique'] = $tableIndex['unique']?false:true;
|
||||
|
||||
$stmt = $this->_conn->executeQuery(sprintf(
|
||||
'PRAGMA INDEX_INFO (%s)',
|
||||
$this->_conn->quote($keyName)
|
||||
));
|
||||
$indexArray = $stmt->fetchAll(FetchMode::ASSOCIATIVE);
|
||||
|
||||
foreach ($indexArray as $indexColumnRow) {
|
||||
$idx['column_name'] = $indexColumnRow['name'];
|
||||
$indexBuffer[] = $idx;
|
||||
}
|
||||
foreach ($indexArray as $indexColumnRow) {
|
||||
$idx['column_name'] = $indexColumnRow['name'];
|
||||
$indexBuffer[] = $idx;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +229,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
return [
|
||||
'name' => $tableIndex['name'],
|
||||
'unique' => (bool) $tableIndex['unique']
|
||||
'unique' => (bool) $tableIndex['unique'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -252,28 +242,33 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
|
||||
// find column with autoincrement
|
||||
$autoincrementColumn = null;
|
||||
$autoincrementCount = 0;
|
||||
$autoincrementCount = 0;
|
||||
|
||||
foreach ($tableColumns as $tableColumn) {
|
||||
if ('0' != $tableColumn['pk']) {
|
||||
$autoincrementCount++;
|
||||
if (null === $autoincrementColumn && 'integer' == strtolower($tableColumn['type'])) {
|
||||
$autoincrementColumn = $tableColumn['name'];
|
||||
}
|
||||
if ($tableColumn['pk'] === '0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$autoincrementCount++;
|
||||
if ($autoincrementColumn !== null || strtolower($tableColumn['type']) !== 'integer') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$autoincrementColumn = $tableColumn['name'];
|
||||
}
|
||||
|
||||
if (1 == $autoincrementCount && null !== $autoincrementColumn) {
|
||||
if ($autoincrementCount === 1 && $autoincrementColumn !== null) {
|
||||
foreach ($list as $column) {
|
||||
if ($autoincrementColumn == $column->getName()) {
|
||||
$column->setAutoincrement(true);
|
||||
if ($autoincrementColumn !== $column->getName()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$column->setAutoincrement(true);
|
||||
}
|
||||
}
|
||||
|
||||
// inspect column collation and comments
|
||||
$createSql = $this->_conn->fetchAll("SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type = 'table' AND name = '$table'");
|
||||
$createSql = $createSql[0]['sql'] ?? '';
|
||||
$createSql = $this->getCreateTableSQL($table) ?? '';
|
||||
|
||||
foreach ($list as $columnName => $column) {
|
||||
$type = $column->getType();
|
||||
@@ -284,17 +279,19 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
|
||||
$comment = $this->parseColumnCommentFromSQL($columnName, $createSql);
|
||||
|
||||
if ($comment !== null) {
|
||||
$type = $this->extractDoctrineTypeFromComment($comment, null);
|
||||
|
||||
if (null !== $type) {
|
||||
$column->setType(Type::getType($type));
|
||||
|
||||
$comment = $this->removeDoctrineTypeFromComment($comment, $type);
|
||||
}
|
||||
|
||||
$column->setComment($comment);
|
||||
if ($comment === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = $this->extractDoctrineTypeFromComment($comment, null);
|
||||
|
||||
if ($type !== null) {
|
||||
$column->setType(Type::getType($type));
|
||||
|
||||
$comment = $this->removeDoctrineTypeFromComment($comment, $type);
|
||||
}
|
||||
|
||||
$column->setComment($comment);
|
||||
}
|
||||
|
||||
return $list;
|
||||
@@ -305,10 +302,10 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
*/
|
||||
protected function _getPortableTableColumnDefinition($tableColumn)
|
||||
{
|
||||
$parts = explode('(', $tableColumn['type']);
|
||||
$parts = explode('(', $tableColumn['type']);
|
||||
$tableColumn['type'] = trim($parts[0]);
|
||||
if (isset($parts[1])) {
|
||||
$length = trim($parts[1], ')');
|
||||
$length = trim($parts[1], ')');
|
||||
$tableColumn['length'] = $length;
|
||||
}
|
||||
|
||||
@@ -317,14 +314,14 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
$unsigned = false;
|
||||
|
||||
if (strpos($dbType, ' unsigned') !== false) {
|
||||
$dbType = str_replace(' unsigned', '', $dbType);
|
||||
$dbType = str_replace(' unsigned', '', $dbType);
|
||||
$unsigned = true;
|
||||
}
|
||||
|
||||
$fixed = false;
|
||||
$type = $this->_platform->getDoctrineTypeMapping($dbType);
|
||||
$fixed = false;
|
||||
$type = $this->_platform->getDoctrineTypeMapping($dbType);
|
||||
$default = $tableColumn['dflt_value'];
|
||||
if ($default == 'NULL') {
|
||||
if ($default === 'NULL') {
|
||||
$default = null;
|
||||
}
|
||||
if ($default !== null) {
|
||||
@@ -333,12 +330,12 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
}
|
||||
$notnull = (bool) $tableColumn['notnull'];
|
||||
|
||||
if ( ! isset($tableColumn['name'])) {
|
||||
if (! isset($tableColumn['name'])) {
|
||||
$tableColumn['name'] = '';
|
||||
}
|
||||
|
||||
$precision = null;
|
||||
$scale = null;
|
||||
$scale = null;
|
||||
|
||||
switch ($dbType) {
|
||||
case 'char':
|
||||
@@ -351,9 +348,9 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
case 'numeric':
|
||||
if (isset($tableColumn['length'])) {
|
||||
if (strpos($tableColumn['length'], ',') === false) {
|
||||
$tableColumn['length'] .= ",0";
|
||||
$tableColumn['length'] .= ',0';
|
||||
}
|
||||
list($precision, $scale) = array_map('trim', explode(',', $tableColumn['length']));
|
||||
[$precision, $scale] = array_map('trim', explode(',', $tableColumn['length']));
|
||||
}
|
||||
$length = null;
|
||||
break;
|
||||
@@ -370,7 +367,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
'autoincrement' => false,
|
||||
];
|
||||
|
||||
return new Column($tableColumn['name'], \Doctrine\DBAL\Types\Type::getType($type), $options);
|
||||
return new Column($tableColumn['name'], Type::getType($type), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -389,12 +386,12 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
$list = [];
|
||||
foreach ($tableForeignKeys as $value) {
|
||||
$value = array_change_key_case($value, CASE_LOWER);
|
||||
$name = $value['constraint_name'];
|
||||
if ( ! isset($list[$name])) {
|
||||
if ( ! isset($value['on_delete']) || $value['on_delete'] == "RESTRICT") {
|
||||
$name = $value['constraint_name'];
|
||||
if (! isset($list[$name])) {
|
||||
if (! isset($value['on_delete']) || $value['on_delete'] === 'RESTRICT') {
|
||||
$value['on_delete'] = null;
|
||||
}
|
||||
if ( ! isset($value['on_update']) || $value['on_update'] == "RESTRICT") {
|
||||
if (! isset($value['on_update']) || $value['on_update'] === 'RESTRICT') {
|
||||
$value['on_update'] = null;
|
||||
}
|
||||
|
||||
@@ -409,15 +406,17 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
'deferred'=> $value['deferred'],
|
||||
];
|
||||
}
|
||||
$list[$name]['local'][] = $value['from'];
|
||||
$list[$name]['local'][] = $value['from'];
|
||||
$list[$name]['foreign'][] = $value['to'];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($list as $constraint) {
|
||||
$result[] = new ForeignKeyConstraint(
|
||||
array_values($constraint['local']), $constraint['foreignTable'],
|
||||
array_values($constraint['foreign']), $constraint['name'],
|
||||
array_values($constraint['local']),
|
||||
$constraint['foreignTable'],
|
||||
array_values($constraint['foreign']),
|
||||
$constraint['name'],
|
||||
[
|
||||
'onDelete' => $constraint['onDelete'],
|
||||
'onUpdate' => $constraint['onUpdate'],
|
||||
@@ -431,25 +430,24 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey
|
||||
* @param \Doctrine\DBAL\Schema\Table|string $table
|
||||
* @param Table|string $table
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff
|
||||
* @return TableDiff
|
||||
*
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
* @throws DBALException
|
||||
*/
|
||||
private function getTableDiffForAlterForeignKey(ForeignKeyConstraint $foreignKey, $table)
|
||||
{
|
||||
if ( ! $table instanceof Table) {
|
||||
if (! $table instanceof Table) {
|
||||
$tableDetails = $this->tryMethod('listTableDetails', $table);
|
||||
if (false === $table) {
|
||||
if ($table === false) {
|
||||
throw new DBALException(sprintf('Sqlite schema manager requires to modify foreign keys table definition "%s".', $table));
|
||||
}
|
||||
|
||||
$table = $tableDetails;
|
||||
}
|
||||
|
||||
$tableDiff = new TableDiff($table->getName());
|
||||
$tableDiff = new TableDiff($table->getName());
|
||||
$tableDiff->fromTable = $table;
|
||||
|
||||
return $tableDiff;
|
||||
@@ -478,6 +476,26 @@ class SqliteSchemaManager extends AbstractSchemaManager
|
||||
|
||||
$comment = preg_replace('{^\s*--}m', '', rtrim($match[1], "\n"));
|
||||
|
||||
return '' === $comment ? null : $comment;
|
||||
return $comment === '' ? null : $comment;
|
||||
}
|
||||
|
||||
private function getCreateTableSQL(string $table) : ?string
|
||||
{
|
||||
return $this->_conn->fetchColumn(
|
||||
<<<'SQL'
|
||||
SELECT sql
|
||||
FROM (
|
||||
SELECT *
|
||||
FROM sqlite_master
|
||||
UNION ALL
|
||||
SELECT *
|
||||
FROM sqlite_temp_master
|
||||
)
|
||||
WHERE type = 'table'
|
||||
AND name = ?
|
||||
SQL
|
||||
,
|
||||
[$table]
|
||||
) ?: null;
|
||||
}
|
||||
}
|
||||
|
@@ -1,60 +1,38 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema\Synchronizer;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Abstract schema synchronizer with methods for executing batches of SQL.
|
||||
*/
|
||||
abstract class AbstractSchemaSynchronizer implements SchemaSynchronizer
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
/** @var Connection */
|
||||
protected $conn;
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Connection $conn
|
||||
*/
|
||||
public function __construct(Connection $conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sql
|
||||
* @param string[] $sql
|
||||
*/
|
||||
protected function processSqlSafely(array $sql)
|
||||
{
|
||||
foreach ($sql as $s) {
|
||||
try {
|
||||
$this->conn->exec($s);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sql
|
||||
* @param string[] $sql
|
||||
*/
|
||||
protected function processSql(array $sql)
|
||||
{
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema\Synchronizer;
|
||||
|
||||
@@ -24,78 +7,66 @@ use Doctrine\DBAL\Schema\Schema;
|
||||
/**
|
||||
* The synchronizer knows how to synchronize a schema with the configured
|
||||
* database.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
interface SchemaSynchronizer
|
||||
{
|
||||
/**
|
||||
* Gets the SQL statements that can be executed to create the schema.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Schema $createSchema
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
function getCreateSchema(Schema $createSchema);
|
||||
public function getCreateSchema(Schema $createSchema);
|
||||
|
||||
/**
|
||||
* Gets the SQL Statements to update given schema with the underlying db.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Schema $toSchema
|
||||
* @param bool $noDrops
|
||||
* @param bool $noDrops
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
function getUpdateSchema(Schema $toSchema, $noDrops = false);
|
||||
public function getUpdateSchema(Schema $toSchema, $noDrops = false);
|
||||
|
||||
/**
|
||||
* Gets the SQL Statements to drop the given schema from underlying db.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Schema $dropSchema
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
function getDropSchema(Schema $dropSchema);
|
||||
public function getDropSchema(Schema $dropSchema);
|
||||
|
||||
/**
|
||||
* Gets the SQL statements to drop all schema assets from underlying db.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
function getDropAllSchema();
|
||||
public function getDropAllSchema();
|
||||
|
||||
/**
|
||||
* Creates the Schema.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Schema $createSchema
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function createSchema(Schema $createSchema);
|
||||
public function createSchema(Schema $createSchema);
|
||||
|
||||
/**
|
||||
* Updates the Schema to new schema version.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Schema $toSchema
|
||||
* @param bool $noDrops
|
||||
* @param bool $noDrops
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function updateSchema(Schema $toSchema, $noDrops = false);
|
||||
public function updateSchema(Schema $toSchema, $noDrops = false);
|
||||
|
||||
/**
|
||||
* Drops the given database schema from the underlying db.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Schema $dropSchema
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function dropSchema(Schema $dropSchema);
|
||||
public function dropSchema(Schema $dropSchema);
|
||||
|
||||
/**
|
||||
* Drops all assets from the underlying db.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function dropAllSchema();
|
||||
public function dropAllSchema();
|
||||
}
|
||||
|
@@ -1,45 +1,22 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema\Synchronizer;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Schema\Comparator;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* Schema Synchronizer for Default DBAL Connection.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
|
||||
*/
|
||||
/** @var AbstractPlatform */
|
||||
private $platform;
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Connection $conn
|
||||
*/
|
||||
public function __construct(Connection $conn)
|
||||
{
|
||||
parent::__construct($conn);
|
||||
@@ -78,8 +55,8 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
|
||||
*/
|
||||
public function getDropSchema(Schema $dropSchema)
|
||||
{
|
||||
$visitor = new DropSchemaSqlCollector($this->platform);
|
||||
$sm = $this->conn->getSchemaManager();
|
||||
$visitor = new DropSchemaSqlCollector($this->platform);
|
||||
$sm = $this->conn->getSchemaManager();
|
||||
|
||||
$fullSchema = $sm->createSchema();
|
||||
|
||||
@@ -89,11 +66,11 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
|
||||
}
|
||||
|
||||
foreach ($table->getForeignKeys() as $foreignKey) {
|
||||
if ( ! $dropSchema->hasTable($table->getName())) {
|
||||
if (! $dropSchema->hasTable($table->getName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! $dropSchema->hasTable($foreignKey->getForeignTableName())) {
|
||||
if (! $dropSchema->hasTable($foreignKey->getForeignTableName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -101,7 +78,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $this->platform->supportsSequences()) {
|
||||
if (! $this->platform->supportsSequences()) {
|
||||
return $visitor->getQueries();
|
||||
}
|
||||
|
||||
@@ -110,7 +87,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
|
||||
}
|
||||
|
||||
foreach ($dropSchema->getTables() as $table) {
|
||||
if ( ! $table->hasPrimaryKey()) {
|
||||
if (! $table->hasPrimaryKey()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -119,10 +96,12 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
|
||||
continue;
|
||||
}
|
||||
|
||||
$checkSequence = $table->getName() . "_" . $columns[0] . "_seq";
|
||||
if ($fullSchema->hasSequence($checkSequence)) {
|
||||
$visitor->acceptSequence($fullSchema->getSequence($checkSequence));
|
||||
$checkSequence = $table->getName() . '_' . $columns[0] . '_seq';
|
||||
if (! $fullSchema->hasSequence($checkSequence)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$visitor->acceptSequence($fullSchema->getSequence($checkSequence));
|
||||
}
|
||||
|
||||
return $visitor->getQueries();
|
||||
@@ -136,8 +115,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
|
||||
$sm = $this->conn->getSchemaManager();
|
||||
$visitor = new DropSchemaSqlCollector($this->platform);
|
||||
|
||||
/* @var $schema \Doctrine\DBAL\Schema\Schema */
|
||||
$schema = $sm->createSchema();
|
||||
$schema = $sm->createSchema();
|
||||
$schema->visit($visitor);
|
||||
|
||||
return $visitor->getQueries();
|
||||
|
@@ -1,27 +1,10 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Schema\Visitor\Visitor;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\Schema\Visitor\Visitor;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use const ARRAY_FILTER_USE_KEY;
|
||||
use function array_filter;
|
||||
use function array_merge;
|
||||
@@ -34,51 +17,31 @@ use function strtolower;
|
||||
|
||||
/**
|
||||
* Object Representation of a table.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class Table extends AbstractAsset
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
/** @var string */
|
||||
protected $_name = null;
|
||||
|
||||
/**
|
||||
* @var Column[]
|
||||
*/
|
||||
/** @var Column[] */
|
||||
protected $_columns = [];
|
||||
|
||||
/**
|
||||
* @var Index[]
|
||||
*/
|
||||
/** @var Index[] */
|
||||
private $implicitIndexes = [];
|
||||
|
||||
/**
|
||||
* @var Index[]
|
||||
*/
|
||||
/** @var Index[] */
|
||||
protected $_indexes = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
/** @var string */
|
||||
protected $_primaryKeyName = false;
|
||||
|
||||
/**
|
||||
* @var ForeignKeyConstraint[]
|
||||
*/
|
||||
/** @var ForeignKeyConstraint[] */
|
||||
protected $_fkConstraints = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var mixed[] */
|
||||
protected $_options = [];
|
||||
|
||||
/**
|
||||
* @var SchemaConfig|null
|
||||
*/
|
||||
/** @var SchemaConfig|null */
|
||||
protected $_schemaConfig = null;
|
||||
|
||||
/**
|
||||
@@ -87,13 +50,13 @@ class Table extends AbstractAsset
|
||||
* @param Index[] $indexes
|
||||
* @param ForeignKeyConstraint[] $fkConstraints
|
||||
* @param int $idGeneratorType
|
||||
* @param array $options
|
||||
* @param mixed[] $options
|
||||
*
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function __construct($tableName, array $columns=[], array $indexes=[], array $fkConstraints=[], $idGeneratorType = 0, array $options=[])
|
||||
public function __construct($tableName, array $columns = [], array $indexes = [], array $fkConstraints = [], $idGeneratorType = 0, array $options = [])
|
||||
{
|
||||
if (strlen($tableName) == 0) {
|
||||
if (strlen($tableName) === 0) {
|
||||
throw DBALException::invalidTableName($tableName);
|
||||
}
|
||||
|
||||
@@ -115,8 +78,6 @@ class Table extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SchemaConfig $schemaConfig
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setSchemaConfig(SchemaConfig $schemaConfig)
|
||||
@@ -139,14 +100,14 @@ class Table extends AbstractAsset
|
||||
/**
|
||||
* Sets the Primary Key.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param string|boolean $indexName
|
||||
* @param mixed[][] $columns
|
||||
* @param string|bool $indexName
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setPrimaryKey(array $columns, $indexName = false)
|
||||
{
|
||||
$this->_addIndex($this->_createIndex($columns, $indexName ?: "primary", true, true));
|
||||
$this->_addIndex($this->_createIndex($columns, $indexName ?: 'primary', true, true));
|
||||
|
||||
foreach ($columns as $columnName) {
|
||||
$column = $this->getColumn($columnName);
|
||||
@@ -157,18 +118,20 @@ class Table extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $columnNames
|
||||
* @param mixed[][] $columnNames
|
||||
* @param string|null $indexName
|
||||
* @param array $flags
|
||||
* @param array $options
|
||||
* @param string[] $flags
|
||||
* @param mixed[] $options
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function addIndex(array $columnNames, $indexName = null, array $flags = [], array $options = [])
|
||||
{
|
||||
if ($indexName == null) {
|
||||
if ($indexName === null) {
|
||||
$indexName = $this->_generateIdentifierName(
|
||||
array_merge([$this->getName()], $columnNames), "idx", $this->_getMaxIdentifierLength()
|
||||
array_merge([$this->getName()], $columnNames),
|
||||
'idx',
|
||||
$this->_getMaxIdentifierLength()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -198,16 +161,16 @@ class Table extends AbstractAsset
|
||||
public function dropIndex($indexName)
|
||||
{
|
||||
$indexName = $this->normalizeIdentifier($indexName);
|
||||
if ( ! $this->hasIndex($indexName)) {
|
||||
if (! $this->hasIndex($indexName)) {
|
||||
throw SchemaException::indexDoesNotExist($indexName, $this->_name);
|
||||
}
|
||||
unset($this->_indexes[$indexName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $columnNames
|
||||
* @param mixed[][] $columnNames
|
||||
* @param string|null $indexName
|
||||
* @param array $options
|
||||
* @param mixed[] $options
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
@@ -215,7 +178,9 @@ class Table extends AbstractAsset
|
||||
{
|
||||
if ($indexName === null) {
|
||||
$indexName = $this->_generateIdentifierName(
|
||||
array_merge([$this->getName()], $columnNames), "uniq", $this->_getMaxIdentifierLength()
|
||||
array_merge([$this->getName()], $columnNames),
|
||||
'uniq',
|
||||
$this->_getMaxIdentifierLength()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -231,7 +196,7 @@ class Table extends AbstractAsset
|
||||
*
|
||||
* @return self This table instance.
|
||||
*
|
||||
* @throws SchemaException if no index exists for the given current name
|
||||
* @throws SchemaException If no index exists for the given current name
|
||||
* or if an index with the given new name already exists on this table.
|
||||
*/
|
||||
public function renameIndex($oldIndexName, $newIndexName = null)
|
||||
@@ -243,7 +208,7 @@ class Table extends AbstractAsset
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ( ! $this->hasIndex($oldIndexName)) {
|
||||
if (! $this->hasIndex($oldIndexName)) {
|
||||
throw SchemaException::indexDoesNotExist($oldIndexName, $this->_name);
|
||||
}
|
||||
|
||||
@@ -271,14 +236,14 @@ class Table extends AbstractAsset
|
||||
/**
|
||||
* Checks if an index begins in the order of the given columns.
|
||||
*
|
||||
* @param array $columnsNames
|
||||
* @param mixed[][] $columnsNames
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function columnsAreIndexed(array $columnsNames)
|
||||
{
|
||||
foreach ($this->getIndexes() as $index) {
|
||||
/* @var $index Index */
|
||||
/** @var $index Index */
|
||||
if ($index->spansColumns($columnsNames)) {
|
||||
return true;
|
||||
}
|
||||
@@ -288,12 +253,12 @@ class Table extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $columnNames
|
||||
* @param string $indexName
|
||||
* @param bool $isUnique
|
||||
* @param bool $isPrimary
|
||||
* @param array $flags
|
||||
* @param array $options
|
||||
* @param mixed[][] $columnNames
|
||||
* @param string $indexName
|
||||
* @param bool $isUnique
|
||||
* @param bool $isPrimary
|
||||
* @param string[] $flags
|
||||
* @param mixed[] $options
|
||||
*
|
||||
* @return Index
|
||||
*
|
||||
@@ -310,7 +275,7 @@ class Table extends AbstractAsset
|
||||
$columnName = $indexColOptions;
|
||||
}
|
||||
|
||||
if ( ! $this->hasColumn($columnName)) {
|
||||
if (! $this->hasColumn($columnName)) {
|
||||
throw SchemaException::columnDoesNotExist($columnName, $this->_name);
|
||||
}
|
||||
}
|
||||
@@ -319,13 +284,13 @@ class Table extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $columnName
|
||||
* @param string $typeName
|
||||
* @param array $options
|
||||
* @param string $columnName
|
||||
* @param string $typeName
|
||||
* @param mixed[] $options
|
||||
*
|
||||
* @return Column
|
||||
*/
|
||||
public function addColumn($columnName, $typeName, array $options=[])
|
||||
public function addColumn($columnName, $typeName, array $options = [])
|
||||
{
|
||||
$column = new Column($columnName, Type::getType($typeName), $options);
|
||||
|
||||
@@ -337,25 +302,25 @@ class Table extends AbstractAsset
|
||||
/**
|
||||
* Renames a Column.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param string $oldColumnName
|
||||
* @param string $newColumnName
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function renameColumn($oldColumnName, $newColumnName)
|
||||
{
|
||||
throw new DBALException("Table#renameColumn() was removed, because it drops and recreates " .
|
||||
"the column instead. There is no fix available, because a schema diff cannot reliably detect if a " .
|
||||
"column was renamed or one column was created and another one dropped.");
|
||||
throw new DBALException('Table#renameColumn() was removed, because it drops and recreates ' .
|
||||
'the column instead. There is no fix available, because a schema diff cannot reliably detect if a ' .
|
||||
'column was renamed or one column was created and another one dropped.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Column Details.
|
||||
*
|
||||
* @param string $columnName
|
||||
* @param array $options
|
||||
* @param string $columnName
|
||||
* @param mixed[] $options
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
@@ -388,16 +353,16 @@ class Table extends AbstractAsset
|
||||
* Name is inferred from the local columns.
|
||||
*
|
||||
* @param Table|string $foreignTable Table schema instance or table name
|
||||
* @param array $localColumnNames
|
||||
* @param array $foreignColumnNames
|
||||
* @param array $options
|
||||
* @param string[] $localColumnNames
|
||||
* @param string[] $foreignColumnNames
|
||||
* @param mixed[] $options
|
||||
* @param string|null $constraintName
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options=[], $constraintName = null)
|
||||
public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $constraintName = null)
|
||||
{
|
||||
$constraintName = $constraintName ?: $this->_generateIdentifierName(array_merge((array) $this->getName(), $localColumnNames), "fk", $this->_getMaxIdentifierLength());
|
||||
$constraintName = $constraintName ?: $this->_generateIdentifierName(array_merge((array) $this->getName(), $localColumnNames), 'fk', $this->_getMaxIdentifierLength());
|
||||
|
||||
return $this->addNamedForeignKeyConstraint($constraintName, $foreignTable, $localColumnNames, $foreignColumnNames, $options);
|
||||
}
|
||||
@@ -410,13 +375,13 @@ class Table extends AbstractAsset
|
||||
* @deprecated Use {@link addForeignKeyConstraint}
|
||||
*
|
||||
* @param Table|string $foreignTable Table schema instance or table name
|
||||
* @param array $localColumnNames
|
||||
* @param array $foreignColumnNames
|
||||
* @param array $options
|
||||
* @param string[] $localColumnNames
|
||||
* @param string[] $foreignColumnNames
|
||||
* @param mixed[] $options
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function addUnnamedForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options=[])
|
||||
public function addUnnamedForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [])
|
||||
{
|
||||
return $this->addForeignKeyConstraint($foreignTable, $localColumnNames, $foreignColumnNames, $options);
|
||||
}
|
||||
@@ -428,32 +393,36 @@ class Table extends AbstractAsset
|
||||
*
|
||||
* @param string $name
|
||||
* @param Table|string $foreignTable Table schema instance or table name
|
||||
* @param array $localColumnNames
|
||||
* @param array $foreignColumnNames
|
||||
* @param array $options
|
||||
* @param string[] $localColumnNames
|
||||
* @param string[] $foreignColumnNames
|
||||
* @param mixed[] $options
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @throws SchemaException
|
||||
*/
|
||||
public function addNamedForeignKeyConstraint($name, $foreignTable, array $localColumnNames, array $foreignColumnNames, array $options=[])
|
||||
public function addNamedForeignKeyConstraint($name, $foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [])
|
||||
{
|
||||
if ($foreignTable instanceof Table) {
|
||||
foreach ($foreignColumnNames as $columnName) {
|
||||
if ( ! $foreignTable->hasColumn($columnName)) {
|
||||
if (! $foreignTable->hasColumn($columnName)) {
|
||||
throw SchemaException::columnDoesNotExist($columnName, $foreignTable->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($localColumnNames as $columnName) {
|
||||
if ( ! $this->hasColumn($columnName)) {
|
||||
if (! $this->hasColumn($columnName)) {
|
||||
throw SchemaException::columnDoesNotExist($columnName, $this->_name);
|
||||
}
|
||||
}
|
||||
|
||||
$constraint = new ForeignKeyConstraint(
|
||||
$localColumnNames, $foreignTable, $foreignColumnNames, $name, $options
|
||||
$localColumnNames,
|
||||
$foreignTable,
|
||||
$foreignColumnNames,
|
||||
$name,
|
||||
$options
|
||||
);
|
||||
$this->_addForeignKeyConstraint($constraint);
|
||||
|
||||
@@ -474,8 +443,6 @@ class Table extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Column $column
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws SchemaException
|
||||
@@ -495,26 +462,26 @@ class Table extends AbstractAsset
|
||||
/**
|
||||
* Adds an index to the table.
|
||||
*
|
||||
* @param Index $indexCandidate
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @throws SchemaException
|
||||
*/
|
||||
protected function _addIndex(Index $indexCandidate)
|
||||
{
|
||||
$indexName = $indexCandidate->getName();
|
||||
$indexName = $this->normalizeIdentifier($indexName);
|
||||
$indexName = $indexCandidate->getName();
|
||||
$indexName = $this->normalizeIdentifier($indexName);
|
||||
$replacedImplicitIndexes = [];
|
||||
|
||||
foreach ($this->implicitIndexes as $name => $implicitIndex) {
|
||||
if ($implicitIndex->isFullfilledBy($indexCandidate) && isset($this->_indexes[$name])) {
|
||||
$replacedImplicitIndexes[] = $name;
|
||||
if (! $implicitIndex->isFullfilledBy($indexCandidate) || ! isset($this->_indexes[$name])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$replacedImplicitIndexes[] = $name;
|
||||
}
|
||||
|
||||
if ((isset($this->_indexes[$indexName]) && ! in_array($indexName, $replacedImplicitIndexes, true)) ||
|
||||
($this->_primaryKeyName != false && $indexCandidate->isPrimary())
|
||||
($this->_primaryKeyName !== false && $indexCandidate->isPrimary())
|
||||
) {
|
||||
throw SchemaException::indexAlreadyExists($indexName, $this->_name);
|
||||
}
|
||||
@@ -533,8 +500,6 @@ class Table extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ForeignKeyConstraint $constraint
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint)
|
||||
@@ -545,7 +510,9 @@ class Table extends AbstractAsset
|
||||
$name = $constraint->getName();
|
||||
} else {
|
||||
$name = $this->_generateIdentifierName(
|
||||
array_merge((array) $this->getName(), $constraint->getLocalColumns()), "fk", $this->_getMaxIdentifierLength()
|
||||
array_merge((array) $this->getName(), $constraint->getLocalColumns()),
|
||||
'fk',
|
||||
$this->_getMaxIdentifierLength()
|
||||
);
|
||||
}
|
||||
$name = $this->normalizeIdentifier($name);
|
||||
@@ -555,9 +522,9 @@ class Table extends AbstractAsset
|
||||
// add an explicit index on the foreign key columns. If there is already an index that fulfils this requirements drop the request.
|
||||
// In the case of __construct calling this method during hydration from schema-details all the explicitly added indexes
|
||||
// lead to duplicates. This creates computation overhead in this case, however no duplicate indexes are ever added (based on columns).
|
||||
$indexName = $this->_generateIdentifierName(
|
||||
$indexName = $this->_generateIdentifierName(
|
||||
array_merge([$this->getName()], $constraint->getColumns()),
|
||||
"idx",
|
||||
'idx',
|
||||
$this->_getMaxIdentifierLength()
|
||||
);
|
||||
$indexCandidate = $this->_createIndex($constraint->getColumns(), $indexName, false, false);
|
||||
@@ -598,7 +565,7 @@ class Table extends AbstractAsset
|
||||
public function getForeignKey($constraintName)
|
||||
{
|
||||
$constraintName = $this->normalizeIdentifier($constraintName);
|
||||
if (!$this->hasForeignKey($constraintName)) {
|
||||
if (! $this->hasForeignKey($constraintName)) {
|
||||
throw SchemaException::foreignKeyDoesNotExist($constraintName, $this->_name);
|
||||
}
|
||||
|
||||
@@ -617,7 +584,7 @@ class Table extends AbstractAsset
|
||||
public function removeForeignKey($constraintName)
|
||||
{
|
||||
$constraintName = $this->normalizeIdentifier($constraintName);
|
||||
if (!$this->hasForeignKey($constraintName)) {
|
||||
if (! $this->hasForeignKey($constraintName)) {
|
||||
throw SchemaException::foreignKeyDoesNotExist($constraintName, $this->_name);
|
||||
}
|
||||
|
||||
@@ -626,6 +593,7 @@ class Table extends AbstractAsset
|
||||
|
||||
/**
|
||||
* Returns ordered list of columns (primary keys are first, then foreign keys, then the rest)
|
||||
*
|
||||
* @return Column[]
|
||||
*/
|
||||
public function getColumns()
|
||||
@@ -640,13 +608,13 @@ class Table extends AbstractAsset
|
||||
|
||||
/**
|
||||
* Returns foreign key columns
|
||||
*
|
||||
* @return Column[]
|
||||
*/
|
||||
private function getForeignKeyColumns()
|
||||
{
|
||||
$foreignKeyColumns = [];
|
||||
foreach ($this->getForeignKeys() as $foreignKey) {
|
||||
/* @var $foreignKey ForeignKeyConstraint */
|
||||
$foreignKeyColumns = array_merge($foreignKeyColumns, $foreignKey->getColumns());
|
||||
}
|
||||
return $this->filterColumns($foreignKeyColumns);
|
||||
@@ -654,12 +622,14 @@ class Table extends AbstractAsset
|
||||
|
||||
/**
|
||||
* Returns only columns that have specified names
|
||||
* @param array $columnNames
|
||||
*
|
||||
* @param string[] $columnNames
|
||||
*
|
||||
* @return Column[]
|
||||
*/
|
||||
private function filterColumns(array $columnNames)
|
||||
{
|
||||
return array_filter($this->_columns, function ($columnName) use ($columnNames) {
|
||||
return array_filter($this->_columns, static function ($columnName) use ($columnNames) {
|
||||
return in_array($columnName, $columnNames, true);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
}
|
||||
@@ -690,7 +660,7 @@ class Table extends AbstractAsset
|
||||
public function getColumn($columnName)
|
||||
{
|
||||
$columnName = $this->normalizeIdentifier($columnName);
|
||||
if ( ! $this->hasColumn($columnName)) {
|
||||
if (! $this->hasColumn($columnName)) {
|
||||
throw SchemaException::columnDoesNotExist($columnName, $this->_name);
|
||||
}
|
||||
|
||||
@@ -704,7 +674,7 @@ class Table extends AbstractAsset
|
||||
*/
|
||||
public function getPrimaryKey()
|
||||
{
|
||||
if ( ! $this->hasPrimaryKey()) {
|
||||
if (! $this->hasPrimaryKey()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -714,14 +684,14 @@ class Table extends AbstractAsset
|
||||
/**
|
||||
* Returns the primary key columns.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function getPrimaryKeyColumns()
|
||||
{
|
||||
if ( ! $this->hasPrimaryKey()) {
|
||||
throw new DBALException("Table " . $this->getName() . " has no primary key.");
|
||||
if (! $this->hasPrimaryKey()) {
|
||||
throw new DBALException('Table ' . $this->getName() . ' has no primary key.');
|
||||
}
|
||||
return $this->getPrimaryKey()->getColumns();
|
||||
}
|
||||
@@ -733,7 +703,7 @@ class Table extends AbstractAsset
|
||||
*/
|
||||
public function hasPrimaryKey()
|
||||
{
|
||||
return ($this->_primaryKeyName && $this->hasIndex($this->_primaryKeyName));
|
||||
return $this->_primaryKeyName && $this->hasIndex($this->_primaryKeyName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -747,7 +717,7 @@ class Table extends AbstractAsset
|
||||
{
|
||||
$indexName = $this->normalizeIdentifier($indexName);
|
||||
|
||||
return (isset($this->_indexes[$indexName]));
|
||||
return isset($this->_indexes[$indexName]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -762,7 +732,7 @@ class Table extends AbstractAsset
|
||||
public function getIndex($indexName)
|
||||
{
|
||||
$indexName = $this->normalizeIdentifier($indexName);
|
||||
if ( ! $this->hasIndex($indexName)) {
|
||||
if (! $this->hasIndex($indexName)) {
|
||||
throw SchemaException::indexDoesNotExist($indexName, $this->_name);
|
||||
}
|
||||
|
||||
@@ -808,7 +778,7 @@ class Table extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
@@ -816,8 +786,6 @@ class Table extends AbstractAsset
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Visitor $visitor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function visit(Visitor $visitor)
|
||||
|
@@ -1,21 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
@@ -23,76 +6,68 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
|
||||
/**
|
||||
* Table Diff.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class TableDiff
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
/** @var string */
|
||||
public $name = null;
|
||||
|
||||
/**
|
||||
* @var string|boolean
|
||||
*/
|
||||
/** @var string|bool */
|
||||
public $newName = false;
|
||||
|
||||
/**
|
||||
* All added fields.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Column[]
|
||||
* @var Column[]
|
||||
*/
|
||||
public $addedColumns;
|
||||
|
||||
/**
|
||||
* All changed fields.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\ColumnDiff[]
|
||||
* @var ColumnDiff[]
|
||||
*/
|
||||
public $changedColumns = [];
|
||||
|
||||
/**
|
||||
* All removed fields.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Column[]
|
||||
* @var Column[]
|
||||
*/
|
||||
public $removedColumns = [];
|
||||
|
||||
/**
|
||||
* Columns that are only renamed from key to column instance name.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Column[]
|
||||
* @var Column[]
|
||||
*/
|
||||
public $renamedColumns = [];
|
||||
|
||||
/**
|
||||
* All added indexes.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Index[]
|
||||
* @var Index[]
|
||||
*/
|
||||
public $addedIndexes = [];
|
||||
|
||||
/**
|
||||
* All changed indexes.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Index[]
|
||||
* @var Index[]
|
||||
*/
|
||||
public $changedIndexes = [];
|
||||
|
||||
/**
|
||||
* All removed indexes
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Index[]
|
||||
* @var Index[]
|
||||
*/
|
||||
public $removedIndexes = [];
|
||||
|
||||
/**
|
||||
* Indexes that are only renamed but are identical otherwise.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Index[]
|
||||
* @var Index[]
|
||||
*/
|
||||
public $renamedIndexes = [];
|
||||
|
||||
@@ -106,7 +81,7 @@ class TableDiff
|
||||
/**
|
||||
* All changed foreign keys
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
|
||||
* @var ForeignKeyConstraint[]
|
||||
*/
|
||||
public $changedForeignKeys = [];
|
||||
|
||||
@@ -117,41 +92,44 @@ class TableDiff
|
||||
*/
|
||||
public $removedForeignKeys = [];
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Table
|
||||
*/
|
||||
/** @var Table */
|
||||
public $fromTable;
|
||||
|
||||
/**
|
||||
* Constructs an TableDiff object.
|
||||
*
|
||||
* @param string $tableName
|
||||
* @param \Doctrine\DBAL\Schema\Column[] $addedColumns
|
||||
* @param \Doctrine\DBAL\Schema\ColumnDiff[] $changedColumns
|
||||
* @param \Doctrine\DBAL\Schema\Column[] $removedColumns
|
||||
* @param \Doctrine\DBAL\Schema\Index[] $addedIndexes
|
||||
* @param \Doctrine\DBAL\Schema\Index[] $changedIndexes
|
||||
* @param \Doctrine\DBAL\Schema\Index[] $removedIndexes
|
||||
* @param \Doctrine\DBAL\Schema\Table|null $fromTable
|
||||
* @param string $tableName
|
||||
* @param Column[] $addedColumns
|
||||
* @param ColumnDiff[] $changedColumns
|
||||
* @param Column[] $removedColumns
|
||||
* @param Index[] $addedIndexes
|
||||
* @param Index[] $changedIndexes
|
||||
* @param Index[] $removedIndexes
|
||||
*/
|
||||
public function __construct($tableName, $addedColumns = [],
|
||||
$changedColumns = [], $removedColumns = [], $addedIndexes = [],
|
||||
$changedIndexes = [], $removedIndexes = [], Table $fromTable = null)
|
||||
{
|
||||
$this->name = $tableName;
|
||||
$this->addedColumns = $addedColumns;
|
||||
public function __construct(
|
||||
$tableName,
|
||||
$addedColumns = [],
|
||||
$changedColumns = [],
|
||||
$removedColumns = [],
|
||||
$addedIndexes = [],
|
||||
$changedIndexes = [],
|
||||
$removedIndexes = [],
|
||||
?Table $fromTable = null
|
||||
) {
|
||||
$this->name = $tableName;
|
||||
$this->addedColumns = $addedColumns;
|
||||
$this->changedColumns = $changedColumns;
|
||||
$this->removedColumns = $removedColumns;
|
||||
$this->addedIndexes = $addedIndexes;
|
||||
$this->addedIndexes = $addedIndexes;
|
||||
$this->changedIndexes = $changedIndexes;
|
||||
$this->removedIndexes = $removedIndexes;
|
||||
$this->fromTable = $fromTable;
|
||||
$this->fromTable = $fromTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractPlatform $platform The platform to use for retrieving this table diff's name.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Identifier
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getName(AbstractPlatform $platform)
|
||||
{
|
||||
|
@@ -1,37 +1,14 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema;
|
||||
|
||||
/**
|
||||
* Representation of a Database View.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 1.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class View extends AbstractAsset
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_sql;
|
||||
/** @var string */
|
||||
private $sql;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
@@ -40,7 +17,7 @@ class View extends AbstractAsset
|
||||
public function __construct($name, $sql)
|
||||
{
|
||||
$this->_setName($name);
|
||||
$this->_sql = $sql;
|
||||
$this->sql = $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,6 +25,6 @@ class View extends AbstractAsset
|
||||
*/
|
||||
public function getSql()
|
||||
{
|
||||
return $this->_sql;
|
||||
return $this->sql;
|
||||
}
|
||||
}
|
||||
|
@@ -1,39 +1,19 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema\Visitor;
|
||||
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\Index;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
|
||||
/**
|
||||
* Abstract Visitor with empty methods for easy extension.
|
||||
*/
|
||||
class AbstractVisitor implements Visitor, NamespaceVisitor
|
||||
{
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Schema $schema
|
||||
*/
|
||||
public function acceptSchema(Schema $schema)
|
||||
{
|
||||
}
|
||||
@@ -45,40 +25,22 @@ class AbstractVisitor implements Visitor, NamespaceVisitor
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
*/
|
||||
public function acceptTable(Table $table)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
* @param \Doctrine\DBAL\Schema\Column $column
|
||||
*/
|
||||
public function acceptColumn(Table $table, Column $column)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $localTable
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $fkConstraint
|
||||
*/
|
||||
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
* @param \Doctrine\DBAL\Schema\Index $index
|
||||
*/
|
||||
public function acceptIndex(Table $table, Index $index)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
*/
|
||||
public function acceptSequence(Sequence $sequence)
|
||||
{
|
||||
}
|
||||
|
@@ -1,61 +1,30 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema\Visitor;
|
||||
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use function array_merge;
|
||||
|
||||
class CreateSchemaSqlCollector extends AbstractVisitor
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var string[] */
|
||||
private $createNamespaceQueries = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var string[] */
|
||||
private $createTableQueries = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var string[] */
|
||||
private $createSequenceQueries = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var string[] */
|
||||
private $createFkConstraintQueries = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
|
||||
*/
|
||||
/** @var AbstractPlatform */
|
||||
private $platform = null;
|
||||
|
||||
/**
|
||||
* @param AbstractPlatform $platform
|
||||
*/
|
||||
public function __construct(AbstractPlatform $platform)
|
||||
{
|
||||
$this->platform = $platform;
|
||||
@@ -66,9 +35,11 @@ class CreateSchemaSqlCollector extends AbstractVisitor
|
||||
*/
|
||||
public function acceptNamespace($namespaceName)
|
||||
{
|
||||
if ($this->platform->supportsSchemas()) {
|
||||
$this->createNamespaceQueries[] = $this->platform->getCreateSchemaSQL($namespaceName);
|
||||
if (! $this->platform->supportsSchemas()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->createNamespaceQueries[] = $this->platform->getCreateSchemaSQL($namespaceName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,9 +55,11 @@ class CreateSchemaSqlCollector extends AbstractVisitor
|
||||
*/
|
||||
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
|
||||
{
|
||||
if ($this->platform->supportsForeignKeyConstraints()) {
|
||||
$this->createFkConstraintQueries[] = $this->platform->getCreateForeignKeySQL($fkConstraint, $localTable);
|
||||
if (! $this->platform->supportsForeignKeyConstraints()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->createFkConstraintQueries[] = $this->platform->getCreateForeignKeySQL($fkConstraint, $localTable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,16 +75,16 @@ class CreateSchemaSqlCollector extends AbstractVisitor
|
||||
*/
|
||||
public function resetQueries()
|
||||
{
|
||||
$this->createNamespaceQueries = [];
|
||||
$this->createTableQueries = [];
|
||||
$this->createSequenceQueries = [];
|
||||
$this->createNamespaceQueries = [];
|
||||
$this->createTableQueries = [];
|
||||
$this->createSequenceQueries = [];
|
||||
$this->createFkConstraintQueries = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all queries collected so far.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getQueries()
|
||||
{
|
||||
|
@@ -1,63 +1,32 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema\Visitor;
|
||||
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\SchemaException;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use SplObjectStorage;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Gathers SQL statements that allow to completely drop the current schema.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class DropSchemaSqlCollector extends AbstractVisitor
|
||||
{
|
||||
/**
|
||||
* @var \SplObjectStorage
|
||||
*/
|
||||
/** @var SplObjectStorage */
|
||||
private $constraints;
|
||||
|
||||
/**
|
||||
* @var \SplObjectStorage
|
||||
*/
|
||||
/** @var SplObjectStorage */
|
||||
private $sequences;
|
||||
|
||||
/**
|
||||
* @var \SplObjectStorage
|
||||
*/
|
||||
/** @var SplObjectStorage */
|
||||
private $tables;
|
||||
|
||||
/**
|
||||
* @var AbstractPlatform
|
||||
*/
|
||||
/** @var AbstractPlatform */
|
||||
private $platform;
|
||||
|
||||
/**
|
||||
* @param AbstractPlatform $platform
|
||||
*/
|
||||
public function __construct(AbstractPlatform $platform)
|
||||
{
|
||||
$this->platform = $platform;
|
||||
@@ -77,7 +46,7 @@ class DropSchemaSqlCollector extends AbstractVisitor
|
||||
*/
|
||||
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
|
||||
{
|
||||
if (strlen($fkConstraint->getName()) == 0) {
|
||||
if (strlen($fkConstraint->getName()) === 0) {
|
||||
throw SchemaException::namedForeignKeyRequired($localTable, $fkConstraint);
|
||||
}
|
||||
|
||||
@@ -97,13 +66,13 @@ class DropSchemaSqlCollector extends AbstractVisitor
|
||||
*/
|
||||
public function clearQueries()
|
||||
{
|
||||
$this->constraints = new \SplObjectStorage();
|
||||
$this->sequences = new \SplObjectStorage();
|
||||
$this->tables = new \SplObjectStorage();
|
||||
$this->constraints = new SplObjectStorage();
|
||||
$this->sequences = new SplObjectStorage();
|
||||
$this->tables = new SplObjectStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getQueries()
|
||||
{
|
||||
@@ -111,7 +80,7 @@ class DropSchemaSqlCollector extends AbstractVisitor
|
||||
|
||||
foreach ($this->constraints as $fkConstraint) {
|
||||
$localTable = $this->constraints[$fkConstraint];
|
||||
$sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable);
|
||||
$sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable);
|
||||
}
|
||||
|
||||
foreach ($this->sequences as $sequence) {
|
||||
|
@@ -1,27 +1,10 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema\Visitor;
|
||||
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use function current;
|
||||
use function file_put_contents;
|
||||
use function in_array;
|
||||
@@ -34,9 +17,7 @@ use function strtolower;
|
||||
*/
|
||||
class Graphviz extends AbstractVisitor
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
/** @var string */
|
||||
private $output = '';
|
||||
|
||||
/**
|
||||
@@ -45,8 +26,8 @@ class Graphviz extends AbstractVisitor
|
||||
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
|
||||
{
|
||||
$this->output .= $this->createNodeRelation(
|
||||
$fkConstraint->getLocalTableName() . ":col" . current($fkConstraint->getLocalColumns()).":se",
|
||||
$fkConstraint->getForeignTableName() . ":col" . current($fkConstraint->getForeignColumns()).":se",
|
||||
$fkConstraint->getLocalTableName() . ':col' . current($fkConstraint->getLocalColumns()) . ':se',
|
||||
$fkConstraint->getForeignTableName() . ':col' . current($fkConstraint->getForeignColumns()) . ':se',
|
||||
[
|
||||
'dir' => 'back',
|
||||
'arrowtail' => 'dot',
|
||||
@@ -63,7 +44,7 @@ class Graphviz extends AbstractVisitor
|
||||
$this->output = 'digraph "' . sha1(mt_rand()) . '" {' . "\n";
|
||||
$this->output .= 'splines = true;' . "\n";
|
||||
$this->output .= 'overlap = false;' . "\n";
|
||||
$this->output .= 'outputorder=edgesfirst;'."\n";
|
||||
$this->output .= 'outputorder=edgesfirst;' . "\n";
|
||||
$this->output .= 'mindist = 0.6;' . "\n";
|
||||
$this->output .= 'sep = .2;' . "\n";
|
||||
}
|
||||
@@ -83,8 +64,6 @@ class Graphviz extends AbstractVisitor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function createTableLabel(Table $table)
|
||||
@@ -103,7 +82,7 @@ class Graphviz extends AbstractVisitor
|
||||
$label .= '<TD BORDER="0" ALIGN="LEFT" BGCOLOR="#eeeeec">';
|
||||
$label .= '<FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="12">' . $columnLabel . '</FONT>';
|
||||
$label .= '</TD><TD BORDER="0" ALIGN="LEFT" BGCOLOR="#eeeeec"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">' . strtolower($column->getType()) . '</FONT></TD>';
|
||||
$label .= '<TD BORDER="0" ALIGN="RIGHT" BGCOLOR="#eeeeec" PORT="col'.$column->getName().'">';
|
||||
$label .= '<TD BORDER="0" ALIGN="RIGHT" BGCOLOR="#eeeeec" PORT="col' . $column->getName() . '">';
|
||||
if ($table->hasPrimaryKey() && in_array($column->getName(), $table->getPrimaryKey()->getColumns())) {
|
||||
$label .= "\xe2\x9c\xb7";
|
||||
}
|
||||
@@ -117,14 +96,14 @@ class Graphviz extends AbstractVisitor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $options
|
||||
* @param string $name
|
||||
* @param string[] $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function createNode($name, $options)
|
||||
{
|
||||
$node = $name . " [";
|
||||
$node = $name . ' [';
|
||||
foreach ($options as $key => $value) {
|
||||
$node .= $key . '=' . $value . ' ';
|
||||
}
|
||||
@@ -134,9 +113,9 @@ class Graphviz extends AbstractVisitor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $node1
|
||||
* @param string $node2
|
||||
* @param array $options
|
||||
* @param string $node1
|
||||
* @param string $node2
|
||||
* @param string[] $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -158,7 +137,7 @@ class Graphviz extends AbstractVisitor
|
||||
*/
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output . "}";
|
||||
return $this->output . '}';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,30 +1,9 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema\Visitor;
|
||||
|
||||
/**
|
||||
* Visitor that can visit schema namespaces.
|
||||
*
|
||||
* @author Steve Müller <st.mueller@dzh-online.de>
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.5
|
||||
*/
|
||||
interface NamespaceVisitor
|
||||
{
|
||||
|
@@ -1,28 +1,11 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema\Visitor;
|
||||
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
|
||||
/**
|
||||
* Removes assets from a schema that are not in the default namespace.
|
||||
@@ -34,15 +17,10 @@ use Doctrine\DBAL\Schema\Sequence;
|
||||
*
|
||||
* This visitor filters all these non-default namespaced tables and sequences
|
||||
* and removes them from the SChema instance.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @since 2.2
|
||||
*/
|
||||
class RemoveNamespacedAssets extends AbstractVisitor
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Schema
|
||||
*/
|
||||
/** @var Schema */
|
||||
private $schema;
|
||||
|
||||
/**
|
||||
@@ -58,9 +36,11 @@ class RemoveNamespacedAssets extends AbstractVisitor
|
||||
*/
|
||||
public function acceptTable(Table $table)
|
||||
{
|
||||
if ( ! $table->isInDefaultNamespace($this->schema->getName())) {
|
||||
$this->schema->dropTable($table->getName());
|
||||
if ($table->isInDefaultNamespace($this->schema->getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->schema->dropTable($table->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,9 +48,11 @@ class RemoveNamespacedAssets extends AbstractVisitor
|
||||
*/
|
||||
public function acceptSequence(Sequence $sequence)
|
||||
{
|
||||
if ( ! $sequence->isInDefaultNamespace($this->schema->getName())) {
|
||||
$this->schema->dropSequence($sequence->getName());
|
||||
if ($sequence->isInDefaultNamespace($this->schema->getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->schema->dropSequence($sequence->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,14 +63,16 @@ class RemoveNamespacedAssets extends AbstractVisitor
|
||||
// The table may already be deleted in a previous
|
||||
// RemoveNamespacedAssets#acceptTable call. Removing Foreign keys that
|
||||
// point to nowhere.
|
||||
if ( ! $this->schema->hasTable($fkConstraint->getForeignTableName())) {
|
||||
if (! $this->schema->hasTable($fkConstraint->getForeignTableName())) {
|
||||
$localTable->removeForeignKey($fkConstraint->getName());
|
||||
return;
|
||||
}
|
||||
|
||||
$foreignTable = $this->schema->getTable($fkConstraint->getForeignTableName());
|
||||
if ( ! $foreignTable->isInDefaultNamespace($this->schema->getName())) {
|
||||
$localTable->removeForeignKey($fkConstraint->getName());
|
||||
if ($foreignTable->isInDefaultNamespace($this->schema->getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$localTable->removeForeignKey($fkConstraint->getName());
|
||||
}
|
||||
}
|
||||
|
@@ -1,82 +1,39 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema\Visitor;
|
||||
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\TableDiff;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\TableDiff;
|
||||
|
||||
/**
|
||||
* Visit a SchemaDiff.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.4
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
interface SchemaDiffVisitor
|
||||
{
|
||||
/**
|
||||
* Visit an orphaned foreign key whose table was deleted.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey
|
||||
*/
|
||||
function visitOrphanedForeignKey(ForeignKeyConstraint $foreignKey);
|
||||
public function visitOrphanedForeignKey(ForeignKeyConstraint $foreignKey);
|
||||
|
||||
/**
|
||||
* Visit a sequence that has changed.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
*/
|
||||
function visitChangedSequence(Sequence $sequence);
|
||||
public function visitChangedSequence(Sequence $sequence);
|
||||
|
||||
/**
|
||||
* Visit a sequence that has been removed.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
*/
|
||||
function visitRemovedSequence(Sequence $sequence);
|
||||
public function visitRemovedSequence(Sequence $sequence);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
*/
|
||||
function visitNewSequence(Sequence $sequence);
|
||||
public function visitNewSequence(Sequence $sequence);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
*/
|
||||
function visitNewTable(Table $table);
|
||||
public function visitNewTable(Table $table);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey
|
||||
*/
|
||||
function visitNewTableForeignKey(Table $table, ForeignKeyConstraint $foreignKey);
|
||||
public function visitNewTableForeignKey(Table $table, ForeignKeyConstraint $foreignKey);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
*/
|
||||
function visitRemovedTable(Table $table);
|
||||
public function visitRemovedTable(Table $table);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
|
||||
*/
|
||||
function visitChangedTable(TableDiff $tableDiff);
|
||||
public function visitChangedTable(TableDiff $tableDiff);
|
||||
}
|
||||
|
@@ -1,81 +1,45 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Schema\Visitor;
|
||||
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\Index;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
|
||||
/**
|
||||
* Schema Visitor used for Validation or Generation purposes.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
interface Visitor
|
||||
{
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Schema $schema
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function acceptSchema(Schema $schema);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function acceptTable(Table $table);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
* @param \Doctrine\DBAL\Schema\Column $column
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function acceptColumn(Table $table, Column $column);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $localTable
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $fkConstraint
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
* @param \Doctrine\DBAL\Schema\Index $index
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function acceptIndex(Table $table, Index $index);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function acceptSequence(Sequence $sequence);
|
||||
|
Reference in New Issue
Block a user