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;
|
||||
|
||||
@@ -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']);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user