the whole shebang
This commit is contained in:
226
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractAsset.php
vendored
Normal file
226
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractAsset.php
vendored
Normal file
@@ -0,0 +1,226 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* The abstract asset allows to reset the name of all assets without publishing this to the public userland.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
protected $_name;
|
||||
|
||||
/**
|
||||
* Namespace of the asset. If none isset the default namespace is assumed.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $_namespace = null;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_quoted = false;
|
||||
|
||||
/**
|
||||
* Sets the name of this asset.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _setName($name)
|
||||
{
|
||||
if ($this->isIdentifierQuoted($name)) {
|
||||
$this->_quoted = true;
|
||||
$name = $this->trimQuotes($name);
|
||||
}
|
||||
if (strpos($name, ".") !== false) {
|
||||
$parts = explode(".", $name);
|
||||
$this->_namespace = $parts[0];
|
||||
$name = $parts[1];
|
||||
}
|
||||
$this->_name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this asset in the default namespace?
|
||||
*
|
||||
* @param string $defaultNamespaceName
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isInDefaultNamespace($defaultNamespaceName)
|
||||
{
|
||||
return $this->_namespace == $defaultNamespaceName || $this->_namespace === null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the namespace name of this asset.
|
||||
*
|
||||
* If NULL is returned this means the default namespace is used.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNamespaceName()
|
||||
{
|
||||
return $this->_namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* The shortest name is stripped of the default namespace. All other
|
||||
* namespaced elements are returned as full-qualified names.
|
||||
*
|
||||
* @param string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShortestName($defaultNamespaceName)
|
||||
{
|
||||
$shortestName = $this->getName();
|
||||
if ($this->_namespace == $defaultNamespaceName) {
|
||||
$shortestName = $this->_name;
|
||||
}
|
||||
|
||||
return strtolower($shortestName);
|
||||
}
|
||||
|
||||
/**
|
||||
* The normalized name is full-qualified and lowerspaced. Lowerspacing is
|
||||
* actually wrong, but we have to do it to keep our sanity. If you are
|
||||
* using database objects that only differentiate in the casing (FOO vs
|
||||
* Foo) then you will NOT be able to use Doctrine Schema abstraction.
|
||||
*
|
||||
* Every non-namespaced element is prefixed with the default namespace
|
||||
* name which is passed as argument to this method.
|
||||
*
|
||||
* @param string $defaultNamespaceName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFullQualifiedName($defaultNamespaceName)
|
||||
{
|
||||
$name = $this->getName();
|
||||
if ( ! $this->_namespace) {
|
||||
$name = $defaultNamespaceName . "." . $name;
|
||||
}
|
||||
|
||||
return strtolower($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this asset's name is quoted.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isQuoted()
|
||||
{
|
||||
return $this->_quoted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this identifier is quoted.
|
||||
*
|
||||
* @param string $identifier
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isIdentifierQuoted($identifier)
|
||||
{
|
||||
return (isset($identifier[0]) && ($identifier[0] == '`' || $identifier[0] == '"'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim quotes from the identifier.
|
||||
*
|
||||
* @param string $identifier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function trimQuotes($identifier)
|
||||
{
|
||||
return str_replace(array('`', '"'), '', $identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this schema asset.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
if ($this->_namespace) {
|
||||
return $this->_namespace . "." . $this->_name;
|
||||
}
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
foreach ($parts as $k => $v) {
|
||||
$parts[$k] = ($this->_quoted || $keywords->isKeyword($v)) ? $platform->quoteIdentifier($v) : $v;
|
||||
}
|
||||
|
||||
return implode(".", $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an identifier from a list of column names obeying a certain string length.
|
||||
*
|
||||
* This is especially important for Oracle, since it does not allow identifiers larger than 30 chars,
|
||||
* however building idents automatically for foreign keys, composite keys or such can easily create
|
||||
* very long names.
|
||||
*
|
||||
* @param array $columnNames
|
||||
* @param string $prefix
|
||||
* @param integer $maxSize
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _generateIdentifierName($columnNames, $prefix='', $maxSize=30)
|
||||
{
|
||||
$hash = implode("", array_map(function($column) {
|
||||
return dechex(crc32($column));
|
||||
}, $columnNames));
|
||||
|
||||
return substr(strtoupper($prefix . "_" . $hash), 0, $maxSize);
|
||||
}
|
||||
}
|
1059
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
vendored
Normal file
1059
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
494
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Column.php
vendored
Normal file
494
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Column.php
vendored
Normal file
@@ -0,0 +1,494 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 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 \Doctrine\DBAL\Types\Type
|
||||
*/
|
||||
protected $_type;
|
||||
|
||||
/**
|
||||
* @var integer|null
|
||||
*/
|
||||
protected $_length = null;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $_precision = 10;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $_scale = 0;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_unsigned = false;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_fixed = false;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_notnull = true;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $_default = null;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_autoincrement = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_platformOptions = array();
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $_columnDefinition = null;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $_comment = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_customSchemaOptions = array();
|
||||
|
||||
/**
|
||||
* Creates a new Column.
|
||||
*
|
||||
* @param string $columnName
|
||||
* @param \Doctrine\DBAL\Types\Type $type
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($columnName, Type $type, array $options=array())
|
||||
{
|
||||
$this->_setName($columnName);
|
||||
$this->setType($type);
|
||||
$this->setOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
foreach ($options as $name => $value) {
|
||||
$method = "set".$name;
|
||||
if (method_exists($this, $method)) {
|
||||
$this->$method($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Types\Type $type
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setType(Type $type)
|
||||
{
|
||||
$this->_type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer|null $length
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setLength($length)
|
||||
{
|
||||
if($length !== null) {
|
||||
$this->_length = (int)$length;
|
||||
} else {
|
||||
$this->_length = null;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $precision
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setPrecision($precision)
|
||||
{
|
||||
if (!is_numeric($precision)) {
|
||||
$precision = 10; // defaults to 10 when no valid precision is given.
|
||||
}
|
||||
|
||||
$this->_precision = (int)$precision;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $scale
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setScale($scale)
|
||||
{
|
||||
if (!is_numeric($scale)) {
|
||||
$scale = 0;
|
||||
}
|
||||
|
||||
$this->_scale = (int)$scale;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $unsigned
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setUnsigned($unsigned)
|
||||
{
|
||||
$this->_unsigned = (bool)$unsigned;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $fixed
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setFixed($fixed)
|
||||
{
|
||||
$this->_fixed = (bool)$fixed;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $notnull
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setNotnull($notnull)
|
||||
{
|
||||
$this->_notnull = (bool)$notnull;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setDefault($default)
|
||||
{
|
||||
$this->_default = $default;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $platformOptions
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setPlatformOptions(array $platformOptions)
|
||||
{
|
||||
$this->_platformOptions = $platformOptions;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setPlatformOption($name, $value)
|
||||
{
|
||||
$this->_platformOptions[$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setColumnDefinition($value)
|
||||
{
|
||||
$this->_columnDefinition = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Doctrine\DBAL\Types\Type
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer|null
|
||||
*/
|
||||
public function getLength()
|
||||
{
|
||||
return $this->_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getPrecision()
|
||||
{
|
||||
return $this->_precision;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getScale()
|
||||
{
|
||||
return $this->_scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getUnsigned()
|
||||
{
|
||||
return $this->_unsigned;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getFixed()
|
||||
{
|
||||
return $this->_fixed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getNotnull()
|
||||
{
|
||||
return $this->_notnull;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
return $this->_default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getPlatformOptions()
|
||||
{
|
||||
return $this->_platformOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasPlatformOption($name)
|
||||
{
|
||||
return isset($this->_platformOptions[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPlatformOption($name)
|
||||
{
|
||||
return $this->_platformOptions[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getColumnDefinition()
|
||||
{
|
||||
return $this->_columnDefinition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getAutoincrement()
|
||||
{
|
||||
return $this->_autoincrement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $flag
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setAutoincrement($flag)
|
||||
{
|
||||
$this->_autoincrement = $flag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $comment
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setComment($comment)
|
||||
{
|
||||
$this->_comment = $comment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return $this->_comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setCustomSchemaOption($name, $value)
|
||||
{
|
||||
$this->_customSchemaOptions[$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasCustomSchemaOption($name)
|
||||
{
|
||||
return isset($this->_customSchemaOptions[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCustomSchemaOption($name)
|
||||
{
|
||||
return $this->_customSchemaOptions[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $customSchemaOptions
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function setCustomSchemaOptions(array $customSchemaOptions)
|
||||
{
|
||||
$this->_customSchemaOptions = $customSchemaOptions;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomSchemaOptions()
|
||||
{
|
||||
return $this->_customSchemaOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Visitor\Visitor $visitor
|
||||
*/
|
||||
public function visit(Visitor $visitor)
|
||||
{
|
||||
$visitor->accept($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return array_merge(array(
|
||||
'name' => $this->_name,
|
||||
'type' => $this->_type,
|
||||
'default' => $this->_default,
|
||||
'notnull' => $this->_notnull,
|
||||
'length' => $this->_length,
|
||||
'precision' => $this->_precision,
|
||||
'scale' => $this->_scale,
|
||||
'fixed' => $this->_fixed,
|
||||
'unsigned' => $this->_unsigned,
|
||||
'autoincrement' => $this->_autoincrement,
|
||||
'columnDefinition' => $this->_columnDefinition,
|
||||
'comment' => $this->_comment,
|
||||
), $this->_platformOptions, $this->_customSchemaOptions);
|
||||
}
|
||||
}
|
74
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/ColumnDiff.php
vendored
Normal file
74
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/ColumnDiff.php
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Represents the change of a column.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class ColumnDiff
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $oldColumnName;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public $column;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $changedProperties = array();
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public $fromColumn;
|
||||
|
||||
/**
|
||||
* @param string $oldColumnName
|
||||
* @param \Doctrine\DBAL\Schema\Column $column
|
||||
* @param array $changedProperties
|
||||
* @param \Doctrine\DBAL\Schema\Column $fromColumn
|
||||
*/
|
||||
public function __construct($oldColumnName, Column $column, array $changedProperties = array(), Column $fromColumn = null)
|
||||
{
|
||||
$this->oldColumnName = $oldColumnName;
|
||||
$this->column = $column;
|
||||
$this->changedProperties = $changedProperties;
|
||||
$this->fromColumn = $fromColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $propertyName
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasChanged($propertyName)
|
||||
{
|
||||
return in_array($propertyName, $this->changedProperties);
|
||||
}
|
||||
}
|
446
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Comparator.php
vendored
Normal file
446
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Comparator.php
vendored
Normal file
@@ -0,0 +1,446 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
static public function compareSchemas(Schema $fromSchema, Schema $toSchema)
|
||||
{
|
||||
$c = new self();
|
||||
|
||||
return $c->compare($fromSchema, $toSchema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SchemaDiff object containing the differences between the schemas $fromSchema and $toSchema.
|
||||
*
|
||||
* The returned differences are returned in such a way that they contain the
|
||||
* 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
|
||||
*/
|
||||
public function compare(Schema $fromSchema, Schema $toSchema)
|
||||
{
|
||||
$diff = new SchemaDiff();
|
||||
$diff->fromSchema = $fromSchema;
|
||||
|
||||
$foreignKeysToTable = array();
|
||||
|
||||
foreach ( $toSchema->getTables() as $table ) {
|
||||
$tableName = $table->getShortestName($toSchema->getName());
|
||||
if ( ! $fromSchema->hasTable($tableName)) {
|
||||
$diff->newTables[$tableName] = $toSchema->getTable($tableName);
|
||||
} else {
|
||||
$tableDifferences = $this->diffTable($fromSchema->getTable($tableName), $toSchema->getTable($tableName));
|
||||
if ($tableDifferences !== false) {
|
||||
$diff->changedTables[$tableName] = $tableDifferences;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if there are tables removed */
|
||||
foreach ($fromSchema->getTables() as $table) {
|
||||
$tableName = $table->getShortestName($fromSchema->getName());
|
||||
|
||||
$table = $fromSchema->getTable($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])) {
|
||||
$foreignKeysToTable[$foreignTable] = array();
|
||||
}
|
||||
$foreignKeysToTable[$foreignTable][] = $foreignKey;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($diff->removedTables as $tableName => $table) {
|
||||
if (isset($foreignKeysToTable[$tableName])) {
|
||||
$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])) {
|
||||
foreach ($diff->changedTables[$localTableName]->removedForeignKeys as $key => $removedForeignKey) {
|
||||
unset($diff->changedTables[$localTableName]->removedForeignKeys[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($toSchema->getSequences() as $sequence) {
|
||||
$sequenceName = $sequence->getShortestName($toSchema->getName());
|
||||
if ( ! $fromSchema->hasSequence($sequenceName)) {
|
||||
$diff->newSequences[] = $sequence;
|
||||
} else {
|
||||
if ($this->diffSequence($sequence, $fromSchema->getSequence($sequenceName))) {
|
||||
$diff->changedSequences[] = $toSchema->getSequence($sequenceName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($fromSchema->getSequences() as $sequence) {
|
||||
if ($this->isAutoIncrementSequenceInSchema($toSchema, $sequence)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sequenceName = $sequence->getShortestName($fromSchema->getName());
|
||||
|
||||
if ( ! $toSchema->hasSequence($sequenceName)) {
|
||||
$diff->removedSequences[] = $sequence;
|
||||
}
|
||||
}
|
||||
|
||||
return $diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Schema $schema
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function isAutoIncrementSequenceInSchema($schema, $sequence)
|
||||
{
|
||||
foreach ($schema->getTables() as $table) {
|
||||
if ($sequence->isAutoIncrementsFor($table)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence1
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence2
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function diffSequence(Sequence $sequence1, Sequence $sequence2)
|
||||
{
|
||||
if($sequence1->getAllocationSize() != $sequence2->getAllocationSize()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if($sequence1->getInitialValue() != $sequence2->getInitialValue()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the difference between the tables $table1 and $table2.
|
||||
*
|
||||
* If there are no differences this method returns the boolean false.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Table $table1
|
||||
* @param \Doctrine\DBAL\Schema\Table $table2
|
||||
*
|
||||
* @return boolean|\Doctrine\DBAL\Schema\TableDiff
|
||||
*/
|
||||
public function diffTable(Table $table1, Table $table2)
|
||||
{
|
||||
$changes = 0;
|
||||
$tableDifferences = new TableDiff($table1->getName());
|
||||
$tableDifferences->fromTable = $table1;
|
||||
|
||||
$table1Columns = $table1->getColumns();
|
||||
$table2Columns = $table2->getColumns();
|
||||
|
||||
/* 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++;
|
||||
}
|
||||
}
|
||||
/* See if there are any removed fields in table 2 */
|
||||
foreach ( $table1Columns as $columnName => $column ) {
|
||||
if ( !$table2->hasColumn($columnName) ) {
|
||||
$tableDifferences->removedColumns[$columnName] = $column;
|
||||
$changes++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $table1Columns as $columnName => $column ) {
|
||||
if ( $table2->hasColumn($columnName) ) {
|
||||
$changedProperties = $this->diffColumn( $column, $table2->getColumn($columnName) );
|
||||
if (count($changedProperties) ) {
|
||||
$columnDiff = new ColumnDiff($column->getName(), $table2->getColumn($columnName), $changedProperties);
|
||||
$columnDiff->fromColumn = $column;
|
||||
$tableDifferences->changedColumns[$column->getName()] = $columnDiff;
|
||||
$changes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->detectColumnRenamings($tableDifferences);
|
||||
|
||||
$table1Indexes = $table1->getIndexes();
|
||||
$table2Indexes = $table2->getIndexes();
|
||||
|
||||
foreach ($table2Indexes as $index2Name => $index2Definition) {
|
||||
foreach ($table1Indexes as $index1Name => $index1Definition) {
|
||||
if ($this->diffIndex($index1Definition, $index2Definition) === false) {
|
||||
unset($table1Indexes[$index1Name]);
|
||||
unset($table2Indexes[$index2Name]);
|
||||
} else {
|
||||
if ($index1Name == $index2Name) {
|
||||
$tableDifferences->changedIndexes[$index2Name] = $table2Indexes[$index2Name];
|
||||
unset($table1Indexes[$index1Name]);
|
||||
unset($table2Indexes[$index2Name]);
|
||||
$changes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($table1Indexes as $index1Name => $index1Definition) {
|
||||
$tableDifferences->removedIndexes[$index1Name] = $index1Definition;
|
||||
$changes++;
|
||||
}
|
||||
|
||||
foreach ($table2Indexes as $index2Name => $index2Definition) {
|
||||
$tableDifferences->addedIndexes[$index2Name] = $index2Definition;
|
||||
$changes++;
|
||||
}
|
||||
|
||||
$fromFkeys = $table1->getForeignKeys();
|
||||
$toFkeys = $table2->getForeignKeys();
|
||||
|
||||
foreach ($fromFkeys as $key1 => $constraint1) {
|
||||
foreach ($toFkeys as $key2 => $constraint2) {
|
||||
if($this->diffForeignKey($constraint1, $constraint2) === false) {
|
||||
unset($fromFkeys[$key1]);
|
||||
unset($toFkeys[$key2]);
|
||||
} else {
|
||||
if (strtolower($constraint1->getName()) == strtolower($constraint2->getName())) {
|
||||
$tableDifferences->changedForeignKeys[] = $constraint2;
|
||||
$changes++;
|
||||
unset($fromFkeys[$key1]);
|
||||
unset($toFkeys[$key2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($fromFkeys as $constraint1) {
|
||||
$tableDifferences->removedForeignKeys[] = $constraint1;
|
||||
$changes++;
|
||||
}
|
||||
|
||||
foreach ($toFkeys as $constraint2) {
|
||||
$tableDifferences->addedForeignKeys[] = $constraint2;
|
||||
$changes++;
|
||||
}
|
||||
|
||||
return $changes ? $tableDifferences : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to find columns that only changed their name, rename operations maybe cheaper than add/drop
|
||||
* however ambiguities between different possibilities should not lead to renaming at all.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\TableDiff $tableDifferences
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function detectColumnRenamings(TableDiff $tableDifferences)
|
||||
{
|
||||
$renameCandidates = array();
|
||||
foreach ($tableDifferences->addedColumns as $addedColumnName => $addedColumn) {
|
||||
foreach ($tableDifferences->removedColumns as $removedColumn) {
|
||||
if (count($this->diffColumn($addedColumn, $removedColumn)) == 0) {
|
||||
$renameCandidates[$addedColumn->getName()][] = array($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]);
|
||||
unset($tableDifferences->removedColumns[$removedColumnName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $key1
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $key2
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2)
|
||||
{
|
||||
if (array_map('strtolower', $key1->getLocalColumns()) != array_map('strtolower', $key2->getLocalColumns())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (array_map('strtolower', $key1->getForeignColumns()) != array_map('strtolower', $key2->getForeignColumns())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($key1->getUnqualifiedForeignTableName() !== $key2->getUnqualifiedForeignTableName()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($key1->onUpdate() != $key2->onUpdate()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($key1->onDelete() != $key2->onDelete()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the difference between the fields $field1 and $field2.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
public function diffColumn(Column $column1, Column $column2)
|
||||
{
|
||||
$changedProperties = array();
|
||||
if ( $column1->getType() != $column2->getType() ) {
|
||||
$changedProperties[] = 'type';
|
||||
}
|
||||
|
||||
if ($column1->getNotnull() != $column2->getNotnull()) {
|
||||
$changedProperties[] = 'notnull';
|
||||
}
|
||||
|
||||
if ($column1->getDefault() != $column2->getDefault()) {
|
||||
$changedProperties[] = 'default';
|
||||
}
|
||||
|
||||
if ($column1->getUnsigned() != $column2->getUnsigned()) {
|
||||
$changedProperties[] = 'unsigned';
|
||||
}
|
||||
|
||||
if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) {
|
||||
// check if value of length is set at all, default value assumed otherwise.
|
||||
$length1 = $column1->getLength() ?: 255;
|
||||
$length2 = $column2->getLength() ?: 255;
|
||||
if ($length1 != $length2) {
|
||||
$changedProperties[] = 'length';
|
||||
}
|
||||
|
||||
if ($column1->getFixed() != $column2->getFixed()) {
|
||||
$changedProperties[] = 'fixed';
|
||||
}
|
||||
}
|
||||
|
||||
if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) {
|
||||
if (($column1->getPrecision()?:10) != ($column2->getPrecision()?:10)) {
|
||||
$changedProperties[] = 'precision';
|
||||
}
|
||||
if ($column1->getScale() != $column2->getScale()) {
|
||||
$changedProperties[] = 'scale';
|
||||
}
|
||||
}
|
||||
|
||||
if ($column1->getAutoincrement() != $column2->getAutoincrement()) {
|
||||
$changedProperties[] = 'autoincrement';
|
||||
}
|
||||
|
||||
// only allow to delete comment if its set to '' not to null.
|
||||
if ($column1->getComment() !== null && $column1->getComment() != $column2->getComment()) {
|
||||
$changedProperties[] = 'comment';
|
||||
}
|
||||
|
||||
$options1 = $column1->getCustomSchemaOptions();
|
||||
$options2 = $column2->getCustomSchemaOptions();
|
||||
|
||||
$commonKeys = array_keys(array_intersect_key($options1, $options2));
|
||||
|
||||
foreach ($commonKeys as $key) {
|
||||
if ($options1[$key] !== $options2[$key]) {
|
||||
$changedProperties[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
$diffKeys = array_keys(array_diff_key($options1, $options2) + array_diff_key($options2, $options1));
|
||||
|
||||
$changedProperties = array_merge($changedProperties, $diffKeys);
|
||||
|
||||
return $changedProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the difference between the indexes $index1 and $index2.
|
||||
*
|
||||
* 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 boolean
|
||||
*/
|
||||
public function diffIndex(Index $index1, Index $index2)
|
||||
{
|
||||
if ($index1->isFullfilledBy($index2) && $index2->isFullfilledBy($index1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
66
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Constraint.php
vendored
Normal file
66
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Constraint.php
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Marker interface for contraints.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
interface Constraint
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQuotedName(AbstractPlatform $platform);
|
||||
|
||||
/**
|
||||
* Returns the names of the referencing table columns
|
||||
* the constraint is associated with.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns();
|
||||
|
||||
/**
|
||||
* Returns the quoted representation of the column names
|
||||
* the constraint is associated with.
|
||||
*
|
||||
* But only if they were defined with one or a column name
|
||||
* 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.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getQuotedColumns(AbstractPlatform $platform);
|
||||
}
|
216
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php
vendored
Normal file
216
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
<?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\Event\SchemaIndexDefinitionEventArgs;
|
||||
use Doctrine\DBAL\Events;
|
||||
|
||||
/**
|
||||
* IBM Db2 Schema Manager.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 1.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class DB2SchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Apparently creator is the schema not the user who created it:
|
||||
* {@link http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.sqlref/db2z_sysibmsystablestable.htm}
|
||||
*/
|
||||
public function listTableNames()
|
||||
{
|
||||
$sql = $this->_platform->getListTablesSQL();
|
||||
$sql .= " AND CREATOR = UPPER('".$this->_conn->getUsername()."')";
|
||||
|
||||
$tables = $this->_conn->fetchAll($sql);
|
||||
|
||||
return $this->_getPortableTablesList($tables);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableColumnDefinition($tableColumn)
|
||||
{
|
||||
$tableColumn = array_change_key_case($tableColumn, \CASE_LOWER);
|
||||
|
||||
$length = null;
|
||||
$fixed = null;
|
||||
$unsigned = false;
|
||||
$scale = false;
|
||||
$precision = false;
|
||||
|
||||
$type = $this->_platform->getDoctrineTypeMapping($tableColumn['typename']);
|
||||
|
||||
switch (strtolower($tableColumn['typename'])) {
|
||||
case 'varchar':
|
||||
$length = $tableColumn['length'];
|
||||
$fixed = false;
|
||||
break;
|
||||
case 'character':
|
||||
$length = $tableColumn['length'];
|
||||
$fixed = true;
|
||||
break;
|
||||
case 'clob':
|
||||
$length = $tableColumn['length'];
|
||||
break;
|
||||
case 'decimal':
|
||||
case 'double':
|
||||
case 'real':
|
||||
$scale = $tableColumn['scale'];
|
||||
$precision = $tableColumn['length'];
|
||||
break;
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'length' => $length,
|
||||
'unsigned' => (bool)$unsigned,
|
||||
'fixed' => (bool)$fixed,
|
||||
'default' => ($tableColumn['default'] == "NULL") ? null : $tableColumn['default'],
|
||||
'notnull' => (bool) ($tableColumn['nulls'] == 'N'),
|
||||
'scale' => null,
|
||||
'precision' => null,
|
||||
'platformOptions' => array(),
|
||||
);
|
||||
|
||||
if ($scale !== null && $precision !== null) {
|
||||
$options['scale'] = $scale;
|
||||
$options['precision'] = $precision;
|
||||
}
|
||||
|
||||
return new Column($tableColumn['colname'], \Doctrine\DBAL\Types\Type::getType($type), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTablesList($tables)
|
||||
{
|
||||
$tableNames = array();
|
||||
foreach ($tables as $tableRow) {
|
||||
$tableRow = array_change_key_case($tableRow, \CASE_LOWER);
|
||||
$tableNames[] = $tableRow['name'];
|
||||
}
|
||||
|
||||
return $tableNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
|
||||
{
|
||||
$eventManager = $this->_platform->getEventManager();
|
||||
|
||||
$indexes = array();
|
||||
foreach($tableIndexes as $indexKey => $data) {
|
||||
$data = array_change_key_case($data, \CASE_LOWER);
|
||||
$unique = ($data['uniquerule'] == "D") ? false : true;
|
||||
$primary = ($data['uniquerule'] == "P");
|
||||
|
||||
$indexName = strtolower($data['name']);
|
||||
|
||||
$data = array(
|
||||
'name' => $indexName,
|
||||
'columns' => explode("+", ltrim($data['colnames'], '+')),
|
||||
'unique' => $unique,
|
||||
'primary' => $primary
|
||||
);
|
||||
|
||||
$index = null;
|
||||
$defaultPrevented = false;
|
||||
|
||||
if (null !== $eventManager && $eventManager->hasListeners(Events::onSchemaIndexDefinition)) {
|
||||
$eventArgs = new SchemaIndexDefinitionEventArgs($data, $tableName, $this->_conn);
|
||||
$eventManager->dispatchEvent(Events::onSchemaIndexDefinition, $eventArgs);
|
||||
|
||||
$defaultPrevented = $eventArgs->isDefaultPrevented();
|
||||
$index = $eventArgs->getIndex();
|
||||
}
|
||||
|
||||
if ( ! $defaultPrevented) {
|
||||
$index = new Index($data['name'], $data['columns'], $data['unique'], $data['primary']);
|
||||
}
|
||||
|
||||
if ($index) {
|
||||
$indexes[$indexKey] = $index;
|
||||
}
|
||||
}
|
||||
|
||||
return $indexes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
|
||||
{
|
||||
$tableForeignKey = array_change_key_case($tableForeignKey, CASE_LOWER);
|
||||
|
||||
$tableForeignKey['deleterule'] = $this->_getPortableForeignKeyRuleDef($tableForeignKey['deleterule']);
|
||||
$tableForeignKey['updaterule'] = $this->_getPortableForeignKeyRuleDef($tableForeignKey['updaterule']);
|
||||
|
||||
return new ForeignKeyConstraint(
|
||||
array_map('trim', (array)$tableForeignKey['fkcolnames']),
|
||||
$tableForeignKey['reftbname'],
|
||||
array_map('trim', (array)$tableForeignKey['pkcolnames']),
|
||||
$tableForeignKey['relname'],
|
||||
array(
|
||||
'onUpdate' => $tableForeignKey['updaterule'],
|
||||
'onDelete' => $tableForeignKey['deleterule'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableForeignKeyRuleDef($def)
|
||||
{
|
||||
if ($def == "C") {
|
||||
return "CASCADE";
|
||||
} else if ($def == "N") {
|
||||
return "SET NULL";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableViewDefinition($view)
|
||||
{
|
||||
$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'])) {
|
||||
$pos = strpos($view['text'], ' AS ');
|
||||
$sql = substr($view['text'], $pos+4);
|
||||
} else {
|
||||
$sql = '';
|
||||
}
|
||||
|
||||
return new View($view['name'], $sql);
|
||||
}
|
||||
}
|
110
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php
vendored
Normal file
110
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Schema manager for the Drizzle RDBMS.
|
||||
*
|
||||
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
|
||||
*/
|
||||
class DrizzleSchemaManager extends AbstractSchemaManager
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableColumnDefinition($tableColumn)
|
||||
{
|
||||
$tableName = $tableColumn['COLUMN_NAME'];
|
||||
$dbType = strtolower($tableColumn['DATA_TYPE']);
|
||||
|
||||
$type = $this->_platform->getDoctrineTypeMapping($dbType);
|
||||
$type = $this->extractDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
|
||||
$tableColumn['COLUMN_COMMENT'] = $this->removeDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
|
||||
|
||||
$options = array(
|
||||
'notnull' => !(bool)$tableColumn['IS_NULLABLE'],
|
||||
'length' => (int)$tableColumn['CHARACTER_MAXIMUM_LENGTH'],
|
||||
'default' => empty($tableColumn['COLUMN_DEFAULT']) ? null : $tableColumn['COLUMN_DEFAULT'],
|
||||
'autoincrement' => (bool)$tableColumn['IS_AUTO_INCREMENT'],
|
||||
'scale' => (int)$tableColumn['NUMERIC_SCALE'],
|
||||
'precision' => (int)$tableColumn['NUMERIC_PRECISION'],
|
||||
'comment' => (isset($tableColumn['COLUMN_COMMENT']) ? $tableColumn['COLUMN_COMMENT'] : null),
|
||||
);
|
||||
|
||||
return new Column($tableName, \Doctrine\DBAL\Types\Type::getType($type), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableDatabaseDefinition($database)
|
||||
{
|
||||
return $database['SCHEMA_NAME'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableDefinition($table)
|
||||
{
|
||||
return $table['TABLE_NAME'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function _getPortableTableForeignKeyDefinition($tableForeignKey)
|
||||
{
|
||||
$columns = array();
|
||||
foreach (explode(',', $tableForeignKey['CONSTRAINT_COLUMNS']) as $value) {
|
||||
$columns[] = trim($value, ' `');
|
||||
}
|
||||
|
||||
$ref_columns = array();
|
||||
foreach (explode(',', $tableForeignKey['REFERENCED_TABLE_COLUMNS']) as $value) {
|
||||
$ref_columns[] = trim($value, ' `');
|
||||
}
|
||||
|
||||
return new ForeignKeyConstraint(
|
||||
$columns,
|
||||
$tableForeignKey['REFERENCED_TABLE_NAME'],
|
||||
$ref_columns,
|
||||
$tableForeignKey['CONSTRAINT_NAME'],
|
||||
array(
|
||||
'onUpdate' => $tableForeignKey['UPDATE_RULE'],
|
||||
'onDelete' => $tableForeignKey['DELETE_RULE'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableIndexesList($tableIndexes, $tableName = null)
|
||||
{
|
||||
$indexes = array();
|
||||
foreach ($tableIndexes as $k) {
|
||||
$k['primary'] = (boolean)$k['primary'];
|
||||
$indexes[] = $k;
|
||||
}
|
||||
|
||||
return parent::_getPortableTableIndexesList($indexes, $tableName);
|
||||
}
|
||||
}
|
346
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php
vendored
Normal file
346
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php
vendored
Normal file
@@ -0,0 +1,346 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
protected $_localTable;
|
||||
|
||||
/**
|
||||
* Asset identifier instances of the referencing table column names the foreign key constraint is associated with.
|
||||
* array($columnName => Identifier)
|
||||
*
|
||||
* @var Identifier[]
|
||||
*/
|
||||
protected $_localColumnNames;
|
||||
|
||||
/**
|
||||
* Table or asset identifier instance of the referenced table name the foreign key constraint is associated with.
|
||||
*
|
||||
* @var Table|Identifier
|
||||
*/
|
||||
protected $_foreignTableName;
|
||||
|
||||
/**
|
||||
* Asset identifier instances of the referenced table column names the foreign key constraint is associated with.
|
||||
* array($columnName => Identifier)
|
||||
*
|
||||
* @var Identifier[]
|
||||
*/
|
||||
protected $_foreignColumnNames;
|
||||
|
||||
/**
|
||||
* @var array Options associated with the foreign key constraint.
|
||||
*/
|
||||
protected $_options;
|
||||
|
||||
/**
|
||||
* Initializes the foreign key constraint.
|
||||
*
|
||||
* @param array $localColumnNames Names of the referencing table columns.
|
||||
* @param Table|string $foreignTableName Referenced table.
|
||||
* @param array $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.
|
||||
*/
|
||||
public function __construct(array $localColumnNames, $foreignTableName, array $foreignColumnNames, $name = null, array $options = array())
|
||||
{
|
||||
$this->_setName($name);
|
||||
$identifierConstructorCallback = function ($column) {
|
||||
return new Identifier($column);
|
||||
};
|
||||
$this->_localColumnNames = $localColumnNames
|
||||
? array_combine($localColumnNames, array_map($identifierConstructorCallback, $localColumnNames))
|
||||
: array();
|
||||
|
||||
if ($foreignTableName instanceof Table) {
|
||||
$this->_foreignTableName = $foreignTableName;
|
||||
} else {
|
||||
$this->_foreignTableName = new Identifier($foreignTableName);
|
||||
}
|
||||
|
||||
$this->_foreignColumnNames = $foreignColumnNames
|
||||
? array_combine($foreignColumnNames, array_map($identifierConstructorCallback, $foreignColumnNames))
|
||||
: array();
|
||||
$this->_options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the referencing table
|
||||
* the foreign key constraint is associated with.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocalTableName()
|
||||
{
|
||||
return $this->_localTable->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setLocalTable(Table $table)
|
||||
{
|
||||
$this->_localTable = $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Table
|
||||
*/
|
||||
public function getLocalTable()
|
||||
{
|
||||
return $this->_localTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the names of the referencing table columns
|
||||
* the foreign key constraint is associated with.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLocalColumns()
|
||||
{
|
||||
return array_keys($this->_localColumnNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the quoted representation of the referencing table column names
|
||||
* the foreign key constraint is associated with.
|
||||
*
|
||||
* But only if they were defined with one or the referencing table column name
|
||||
* 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.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getQuotedLocalColumns(AbstractPlatform $platform)
|
||||
{
|
||||
$columns = array();
|
||||
|
||||
foreach ($this->_localColumnNames as $column) {
|
||||
$columns[] = $column->getQuotedName($platform);
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see getLocalColumns
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return $this->getLocalColumns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the quoted representation of the referencing table column names
|
||||
* the foreign key constraint is associated with.
|
||||
*
|
||||
* But only if they were defined with one or the referencing table column name
|
||||
* 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
|
||||
*/
|
||||
public function getQuotedColumns(AbstractPlatform $platform)
|
||||
{
|
||||
return $this->getQuotedLocalColumns($platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the referenced table
|
||||
* the foreign key constraint is associated with.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getForeignTableName()
|
||||
{
|
||||
return $this->_foreignTableName->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the non-schema qualified foreign table name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUnqualifiedForeignTableName()
|
||||
{
|
||||
$parts = explode(".", $this->_foreignTableName->getName());
|
||||
return strtolower(end($parts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the quoted representation of the referenced table name
|
||||
* the foreign key constraint is associated with.
|
||||
*
|
||||
* But only if it was defined with one or the referenced table name
|
||||
* 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.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQuotedForeignTableName(AbstractPlatform $platform)
|
||||
{
|
||||
return $this->_foreignTableName->getQuotedName($platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the names of the referenced table columns
|
||||
* the foreign key constraint is associated with.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getForeignColumns()
|
||||
{
|
||||
return array_keys($this->_foreignColumnNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the quoted representation of the referenced table column names
|
||||
* the foreign key constraint is associated with.
|
||||
*
|
||||
* But only if they were defined with one or the referenced table column name
|
||||
* 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.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getQuotedForeignColumns(AbstractPlatform $platform)
|
||||
{
|
||||
$columns = array();
|
||||
|
||||
foreach ($this->_foreignColumnNames as $column) {
|
||||
$columns[] = $column->getQuotedName($platform);
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not a given option
|
||||
* is associated with the foreign key constraint.
|
||||
*
|
||||
* @param string $name Name of the option to check.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasOption($name)
|
||||
{
|
||||
return isset($this->_options[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an option associated with the foreign key constraint.
|
||||
*
|
||||
* @param string $name Name of the option the foreign key constraint is associated with.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOption($name)
|
||||
{
|
||||
return $this->_options[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the options associated with the foreign key constraint.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the referential action for UPDATE operations
|
||||
* on the referenced table the foreign key constraint is associated with.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function onUpdate()
|
||||
{
|
||||
return $this->onEvent('onUpdate');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the referential action for DELETE operations
|
||||
* on the referenced table the foreign key constraint is associated with.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function onDelete()
|
||||
{
|
||||
return $this->onEvent('onDelete');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the referential action for a given database operation
|
||||
* on the referenced table the foreign key constraint is associated with.
|
||||
*
|
||||
* @param string $event Name of the database operation/event to return the referential action for.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function onEvent($event)
|
||||
{
|
||||
if (isset($this->_options[$event])) {
|
||||
$onEvent = strtoupper($this->_options[$event]);
|
||||
|
||||
if ( ! in_array($onEvent, array('NO ACTION', 'RESTRICT'))) {
|
||||
return $onEvent;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
45
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Identifier.php
vendored
Normal file
45
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Identifier.php
vendored
Normal file
@@ -0,0 +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;
|
||||
|
||||
use Doctrine\DBAL\Schema\AbstractAsset;
|
||||
|
||||
/**
|
||||
* An abstraction class for an asset identifier.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
public function __construct($identifier)
|
||||
{
|
||||
$this->_setName($identifier);
|
||||
}
|
||||
}
|
290
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Index.php
vendored
Normal file
290
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Index.php
vendored
Normal file
@@ -0,0 +1,290 @@
|
||||
<?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;
|
||||
|
||||
class Index extends AbstractAsset implements Constraint
|
||||
{
|
||||
/**
|
||||
* Asset identifier instances of the column names the index is associated with.
|
||||
* array($columnName => Identifier)
|
||||
*
|
||||
* @var Identifier[]
|
||||
*/
|
||||
protected $_columns;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_isUnique = false;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_isPrimary = false;
|
||||
|
||||
/**
|
||||
* Platform specific flags for indexes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_flags = array();
|
||||
|
||||
/**
|
||||
* @param string $indexName
|
||||
* @param array $columns
|
||||
* @param boolean $isUnique
|
||||
* @param boolean $isPrimary
|
||||
* @param array $flags
|
||||
*/
|
||||
public function __construct($indexName, array $columns, $isUnique = false, $isPrimary = false, array $flags = array())
|
||||
{
|
||||
$isUnique = ($isPrimary)?true:$isUnique;
|
||||
|
||||
$this->_setName($indexName);
|
||||
$this->_isUnique = $isUnique;
|
||||
$this->_isPrimary = $isPrimary;
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$this->_addColumn($column);
|
||||
}
|
||||
foreach ($flags as $flag) {
|
||||
$this->addFlag($flag);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @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");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array_keys($this->_columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuotedColumns(AbstractPlatform $platform)
|
||||
{
|
||||
$columns = array();
|
||||
|
||||
foreach ($this->_columns as $column) {
|
||||
$columns[] = $column->getQuotedName($platform);
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getUnquotedColumns()
|
||||
{
|
||||
return array_map(array($this, 'trimQuotes'), $this->getColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the index neither unique nor primary key?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSimpleIndex()
|
||||
{
|
||||
return !$this->_isPrimary && !$this->_isUnique;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isUnique()
|
||||
{
|
||||
return $this->_isUnique;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isPrimary()
|
||||
{
|
||||
return $this->_isPrimary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $columnName
|
||||
* @param integer $pos
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasColumnAtPosition($columnName, $pos = 0)
|
||||
{
|
||||
$columnName = $this->trimQuotes(strtolower($columnName));
|
||||
$indexColumns = array_map('strtolower', $this->getUnquotedColumns());
|
||||
|
||||
return array_search($columnName, $indexColumns) === $pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this index exactly spans the given column names in the correct order.
|
||||
*
|
||||
* @param array $columnNames
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function spansColumns(array $columnNames)
|
||||
{
|
||||
$columns = $this->getColumns();
|
||||
$numberOfColumns = count($columns);
|
||||
$sameColumns = true;
|
||||
|
||||
for ($i = 0; $i < $numberOfColumns; $i++) {
|
||||
if ( ! isset($columnNames[$i]) || $this->trimQuotes(strtolower($columns[$i])) !== $this->trimQuotes(strtolower($columnNames[$i]))) {
|
||||
$sameColumns = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $sameColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the other index already fulfills all the indexing and constraint needs of the current one.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Index $other
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
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())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if columns are the same, and even in the same order
|
||||
$sameColumns = $this->spansColumns($other->getColumns());
|
||||
|
||||
if ($sameColumns) {
|
||||
if ( ! $this->isUnique() && !$this->isPrimary()) {
|
||||
// this is a special case: If the current key is neither primary or unique, any uniqe 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
|
||||
// index that has no constraints.
|
||||
return true;
|
||||
} else if ($other->isPrimary() != $this->isPrimary()) {
|
||||
return false;
|
||||
} else if ($other->isUnique() != $this->isUnique()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if the other index is a non-unique, non primary index that can be overwritten by this one.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Index $other
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function overrules(Index $other)
|
||||
{
|
||||
if ($other->isPrimary()) {
|
||||
return false;
|
||||
} else if ($this->isSimpleIndex() && $other->isUnique()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->spansColumns($other->getColumns()) && ($this->isPrimary() || $this->isUnique())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns platform specific flags for indexes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFlags()
|
||||
{
|
||||
return array_keys($this->_flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Flag for an index that translates to platform specific handling.
|
||||
*
|
||||
* @example $index->addFlag('CLUSTERED')
|
||||
*
|
||||
* @param string $flag
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Index
|
||||
*/
|
||||
public function addFlag($flag)
|
||||
{
|
||||
$this->flags[strtolower($flag)] = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this index have a specific flag?
|
||||
*
|
||||
* @param string $flag
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasFlag($flag)
|
||||
{
|
||||
return isset($this->flags[strtolower($flag)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a flag.
|
||||
*
|
||||
* @param string $flag
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeFlag($flag)
|
||||
{
|
||||
unset($this->flags[strtolower($flag)]);
|
||||
}
|
||||
}
|
224
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
vendored
Normal file
224
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
vendored
Normal file
@@ -0,0 +1,224 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableViewDefinition($view)
|
||||
{
|
||||
return new View($view['TABLE_NAME'], $view['VIEW_DEFINITION']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableDefinition($table)
|
||||
{
|
||||
return array_shift($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableUserDefinition($user)
|
||||
{
|
||||
return array(
|
||||
'user' => $user['User'],
|
||||
'password' => $user['Password'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
|
||||
{
|
||||
foreach($tableIndexes as $k => $v) {
|
||||
$v = array_change_key_case($v, CASE_LOWER);
|
||||
if($v['key_name'] == 'PRIMARY') {
|
||||
$v['primary'] = true;
|
||||
} else {
|
||||
$v['primary'] = false;
|
||||
}
|
||||
if (strpos($v['index_type'], 'FULLTEXT') !== false) {
|
||||
$v['flags'] = array('FULLTEXT');
|
||||
}
|
||||
$tableIndexes[$k] = $v;
|
||||
}
|
||||
|
||||
return parent::_getPortableTableIndexesList($tableIndexes, $tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableSequenceDefinition($sequence)
|
||||
{
|
||||
return end($sequence);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableDatabaseDefinition($database)
|
||||
{
|
||||
return $database['Database'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableColumnDefinition($tableColumn)
|
||||
{
|
||||
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
|
||||
|
||||
$dbType = strtolower($tableColumn['type']);
|
||||
$dbType = strtok($dbType, '(), ');
|
||||
if (isset($tableColumn['length'])) {
|
||||
$length = $tableColumn['length'];
|
||||
} else {
|
||||
$length = strtok('(), ');
|
||||
}
|
||||
|
||||
$fixed = null;
|
||||
|
||||
if ( ! isset($tableColumn['name'])) {
|
||||
$tableColumn['name'] = '';
|
||||
}
|
||||
|
||||
$scale = null;
|
||||
$precision = null;
|
||||
|
||||
$type = $this->_platform->getDoctrineTypeMapping($dbType);
|
||||
|
||||
// In cases where not connected to a database DESCRIBE $table does not return 'Comment'
|
||||
if (isset($tableColumn['comment'])) {
|
||||
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
|
||||
$tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
|
||||
}
|
||||
|
||||
switch ($dbType) {
|
||||
case 'char':
|
||||
$fixed = true;
|
||||
break;
|
||||
case 'float':
|
||||
case 'double':
|
||||
case 'real':
|
||||
case 'numeric':
|
||||
case 'decimal':
|
||||
if(preg_match('([A-Za-z]+\(([0-9]+)\,([0-9]+)\))', $tableColumn['type'], $match)) {
|
||||
$precision = $match[1];
|
||||
$scale = $match[2];
|
||||
$length = null;
|
||||
}
|
||||
break;
|
||||
case 'tinyint':
|
||||
case 'smallint':
|
||||
case 'mediumint':
|
||||
case 'int':
|
||||
case 'integer':
|
||||
case 'bigint':
|
||||
case 'tinyblob':
|
||||
case 'mediumblob':
|
||||
case 'longblob':
|
||||
case 'blob':
|
||||
case 'year':
|
||||
$length = null;
|
||||
break;
|
||||
}
|
||||
|
||||
$length = ((int) $length == 0) ? null : (int) $length;
|
||||
|
||||
$options = array(
|
||||
'length' => $length,
|
||||
'unsigned' => (bool) (strpos($tableColumn['type'], 'unsigned') !== false),
|
||||
'fixed' => (bool) $fixed,
|
||||
'default' => isset($tableColumn['default']) ? $tableColumn['default'] : null,
|
||||
'notnull' => (bool) ($tableColumn['null'] != 'YES'),
|
||||
'scale' => null,
|
||||
'precision' => null,
|
||||
'autoincrement' => (bool) (strpos($tableColumn['extra'], 'auto_increment') !== false),
|
||||
'comment' => (isset($tableColumn['comment'])) ? $tableColumn['comment'] : null
|
||||
);
|
||||
|
||||
if ($scale !== null && $precision !== null) {
|
||||
$options['scale'] = $scale;
|
||||
$options['precision'] = $precision;
|
||||
}
|
||||
|
||||
return new Column($tableColumn['field'], \Doctrine\DBAL\Types\Type::getType($type), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableForeignKeysList($tableForeignKeys)
|
||||
{
|
||||
$list = array();
|
||||
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") {
|
||||
$value['delete_rule'] = null;
|
||||
}
|
||||
if (!isset($value['update_rule']) || $value['update_rule'] == "RESTRICT") {
|
||||
$value['update_rule'] = null;
|
||||
}
|
||||
|
||||
$list[$value['constraint_name']] = array(
|
||||
'name' => $value['constraint_name'],
|
||||
'local' => array(),
|
||||
'foreign' => array(),
|
||||
'foreignTable' => $value['referenced_table_name'],
|
||||
'onDelete' => $value['delete_rule'],
|
||||
'onUpdate' => $value['update_rule'],
|
||||
);
|
||||
}
|
||||
$list[$value['constraint_name']]['local'][] = $value['column_name'];
|
||||
$list[$value['constraint_name']]['foreign'][] = $value['referenced_column_name'];
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach($list as $constraint) {
|
||||
$result[] = new ForeignKeyConstraint(
|
||||
array_values($constraint['local']), $constraint['foreignTable'],
|
||||
array_values($constraint['foreign']), $constraint['name'],
|
||||
array(
|
||||
'onDelete' => $constraint['onDelete'],
|
||||
'onUpdate' => $constraint['onUpdate'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
316
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php
vendored
Normal file
316
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php
vendored
Normal file
@@ -0,0 +1,316 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableViewDefinition($view)
|
||||
{
|
||||
$view = \array_change_key_case($view, CASE_LOWER);
|
||||
|
||||
return new View($view['view_name'], $view['text']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableUserDefinition($user)
|
||||
{
|
||||
$user = \array_change_key_case($user, CASE_LOWER);
|
||||
|
||||
return array(
|
||||
'user' => $user['username'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableDefinition($table)
|
||||
{
|
||||
$table = \array_change_key_case($table, CASE_LOWER);
|
||||
|
||||
return $table['table_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @license New BSD License
|
||||
* @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html
|
||||
*/
|
||||
protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
|
||||
{
|
||||
$indexBuffer = array();
|
||||
foreach ( $tableIndexes as $tableIndex ) {
|
||||
$tableIndex = \array_change_key_case($tableIndex, CASE_LOWER);
|
||||
|
||||
$keyName = strtolower($tableIndex['name']);
|
||||
|
||||
if ( strtolower($tableIndex['is_primary']) == "p" ) {
|
||||
$keyName = 'primary';
|
||||
$buffer['primary'] = true;
|
||||
$buffer['non_unique'] = false;
|
||||
} else {
|
||||
$buffer['primary'] = false;
|
||||
$buffer['non_unique'] = ( $tableIndex['is_unique'] == 0 ) ? true : false;
|
||||
}
|
||||
$buffer['key_name'] = $keyName;
|
||||
$buffer['column_name'] = $tableIndex['column_name'];
|
||||
$indexBuffer[] = $buffer;
|
||||
}
|
||||
|
||||
return parent::_getPortableTableIndexesList($indexBuffer, $tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableColumnDefinition($tableColumn)
|
||||
{
|
||||
$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";
|
||||
} else {
|
||||
$dbType = "timestamp";
|
||||
}
|
||||
}
|
||||
|
||||
$unsigned = $fixed = null;
|
||||
|
||||
if ( ! isset($tableColumn['column_name'])) {
|
||||
$tableColumn['column_name'] = '';
|
||||
}
|
||||
|
||||
if (stripos($tableColumn['data_default'], 'NULL') !== null) {
|
||||
$tableColumn['data_default'] = null;
|
||||
}
|
||||
|
||||
$precision = null;
|
||||
$scale = null;
|
||||
|
||||
$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) {
|
||||
$precision = 20;
|
||||
$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) {
|
||||
$precision = 1;
|
||||
$scale = 0;
|
||||
$type = 'boolean';
|
||||
} elseif ($tableColumn['data_scale'] > 0) {
|
||||
$precision = $tableColumn['data_precision'];
|
||||
$scale = $tableColumn['data_scale'];
|
||||
$type = 'decimal';
|
||||
}
|
||||
$length = null;
|
||||
break;
|
||||
case 'pls_integer':
|
||||
case 'binary_integer':
|
||||
$length = null;
|
||||
break;
|
||||
case 'varchar':
|
||||
case 'varchar2':
|
||||
case 'nvarchar2':
|
||||
$length = $tableColumn['char_length'];
|
||||
$fixed = false;
|
||||
break;
|
||||
case 'char':
|
||||
case 'nchar':
|
||||
$length = $tableColumn['char_length'];
|
||||
$fixed = true;
|
||||
break;
|
||||
case 'date':
|
||||
case 'timestamp':
|
||||
$length = null;
|
||||
break;
|
||||
case 'float':
|
||||
$precision = $tableColumn['data_precision'];
|
||||
$scale = $tableColumn['data_scale'];
|
||||
$length = null;
|
||||
break;
|
||||
case 'clob':
|
||||
case 'nclob':
|
||||
$length = null;
|
||||
break;
|
||||
case 'blob':
|
||||
case 'raw':
|
||||
case 'long raw':
|
||||
case 'bfile':
|
||||
$length = null;
|
||||
break;
|
||||
case 'rowid':
|
||||
case 'urowid':
|
||||
default:
|
||||
$length = null;
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'notnull' => (bool) ($tableColumn['nullable'] === 'N'),
|
||||
'fixed' => (bool) $fixed,
|
||||
'unsigned' => (bool) $unsigned,
|
||||
'default' => $tableColumn['data_default'],
|
||||
'length' => $length,
|
||||
'precision' => $precision,
|
||||
'scale' => $scale,
|
||||
'comment' => (isset($tableColumn['comments'])) ? $tableColumn['comments'] : null,
|
||||
'platformDetails' => array(),
|
||||
);
|
||||
|
||||
return new Column($tableColumn['column_name'], \Doctrine\DBAL\Types\Type::getType($type), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableForeignKeysList($tableForeignKeys)
|
||||
{
|
||||
$list = array();
|
||||
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['delete_rule'] = null;
|
||||
}
|
||||
|
||||
$list[$value['constraint_name']] = array(
|
||||
'name' => $value['constraint_name'],
|
||||
'local' => array(),
|
||||
'foreign' => array(),
|
||||
'foreignTable' => $value['references_table'],
|
||||
'onDelete' => $value['delete_rule'],
|
||||
);
|
||||
}
|
||||
$list[$value['constraint_name']]['local'][$value['position']] = $value['local_column'];
|
||||
$list[$value['constraint_name']]['foreign'][$value['position']] = $value['foreign_column'];
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach($list as $constraint) {
|
||||
$result[] = new ForeignKeyConstraint(
|
||||
array_values($constraint['local']), $constraint['foreignTable'],
|
||||
array_values($constraint['foreign']), $constraint['name'],
|
||||
array('onDelete' => $constraint['onDelete'])
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableSequenceDefinition($sequence)
|
||||
{
|
||||
$sequence = \array_change_key_case($sequence, CASE_LOWER);
|
||||
|
||||
return new Sequence($sequence['sequence_name'], $sequence['increment_by'], $sequence['min_value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableFunctionDefinition($function)
|
||||
{
|
||||
$function = \array_change_key_case($function, CASE_LOWER);
|
||||
|
||||
return $function['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableDatabaseDefinition($database)
|
||||
{
|
||||
$database = \array_change_key_case($database, CASE_LOWER);
|
||||
|
||||
return $database['username'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createDatabase($database = null)
|
||||
{
|
||||
if (is_null($database)) {
|
||||
$database = $this->_conn->getDatabase();
|
||||
}
|
||||
|
||||
$params = $this->_conn->getParams();
|
||||
$username = $database;
|
||||
$password = $params['password'];
|
||||
|
||||
$query = 'CREATE USER ' . $username . ' IDENTIFIED BY ' . $password;
|
||||
$this->_conn->executeUpdate($query);
|
||||
|
||||
$query = 'GRANT CREATE SESSION, CREATE TABLE, UNLIMITED TABLESPACE, CREATE SEQUENCE, CREATE TRIGGER TO ' . $username;
|
||||
$this->_conn->executeUpdate($query);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function dropAutoincrement($table)
|
||||
{
|
||||
$sql = $this->_platform->getDropAutoincrementSql($table);
|
||||
foreach ($sql as $query) {
|
||||
$this->_conn->executeUpdate($query);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dropTable($name)
|
||||
{
|
||||
$this->dropAutoincrement($name);
|
||||
|
||||
parent::dropTable($name);
|
||||
}
|
||||
}
|
399
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
vendored
Normal file
399
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
vendored
Normal file
@@ -0,0 +1,399 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private $existingSchemaPaths;
|
||||
|
||||
/**
|
||||
* Gets all the existing schema names.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSchemaNames()
|
||||
{
|
||||
$rows = $this->_conn->fetchAll("SELECT nspname as schema_name FROM pg_namespace WHERE nspname !~ '^pg_.*' and nspname != 'information_schema'");
|
||||
|
||||
return array_map(function($v) { return $v['schema_name']; }, $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of schema search paths.
|
||||
*
|
||||
* This is a PostgreSQL only function.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSchemaSearchPaths()
|
||||
{
|
||||
$params = $this->_conn->getParams();
|
||||
$schema = explode(",", $this->_conn->fetchColumn('SHOW search_path'));
|
||||
|
||||
if (isset($params['user'])) {
|
||||
$schema = str_replace('"$user"', $params['user'], $schema);
|
||||
}
|
||||
|
||||
return array_map('trim', $schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets names of all existing schemas in the current users search path.
|
||||
*
|
||||
* This is a PostgreSQL only function.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExistingSchemaSearchPaths()
|
||||
{
|
||||
if ($this->existingSchemaPaths === null) {
|
||||
$this->determineExistingSchemaSearchPaths();
|
||||
}
|
||||
|
||||
return $this->existingSchemaPaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets or resets the order of the existing schemas in the current search path of the user.
|
||||
*
|
||||
* This is a PostgreSQL only function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function determineExistingSchemaSearchPaths()
|
||||
{
|
||||
$names = $this->getSchemaNames();
|
||||
$paths = $this->getSchemaSearchPaths();
|
||||
|
||||
$this->existingSchemaPaths = array_filter($paths, function ($v) use ($names) {
|
||||
return in_array($v, $names);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
|
||||
{
|
||||
$onUpdate = null;
|
||||
$onDelete = null;
|
||||
|
||||
if (preg_match('(ON UPDATE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) {
|
||||
$onUpdate = $match[1];
|
||||
}
|
||||
if (preg_match('(ON DELETE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) {
|
||||
$onDelete = $match[1];
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
return new ForeignKeyConstraint(
|
||||
$localColumns, $foreignTable, $foreignColumns, $tableForeignKey['conname'],
|
||||
array('onUpdate' => $onUpdate, 'onDelete' => $onDelete)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dropDatabase($database)
|
||||
{
|
||||
$params = $this->_conn->getParams();
|
||||
$params["dbname"] = "postgres";
|
||||
$tmpPlatform = $this->_platform;
|
||||
$tmpConn = $this->_conn;
|
||||
|
||||
$this->_conn = \Doctrine\DBAL\DriverManager::getConnection($params);
|
||||
$this->_platform = $this->_conn->getDatabasePlatform();
|
||||
|
||||
parent::dropDatabase($database);
|
||||
|
||||
$this->_conn->close();
|
||||
|
||||
$this->_platform = $tmpPlatform;
|
||||
$this->_conn = $tmpConn;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createDatabase($database)
|
||||
{
|
||||
$params = $this->_conn->getParams();
|
||||
$params["dbname"] = "postgres";
|
||||
$tmpPlatform = $this->_platform;
|
||||
$tmpConn = $this->_conn;
|
||||
|
||||
$this->_conn = \Doctrine\DBAL\DriverManager::getConnection($params);
|
||||
$this->_platform = $this->_conn->getDatabasePlatform();
|
||||
|
||||
parent::createDatabase($database);
|
||||
|
||||
$this->_conn->close();
|
||||
|
||||
$this->_platform = $tmpPlatform;
|
||||
$this->_conn = $tmpConn;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTriggerDefinition($trigger)
|
||||
{
|
||||
return $trigger['trigger_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableViewDefinition($view)
|
||||
{
|
||||
return new View($view['viewname'], $view['definition']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableUserDefinition($user)
|
||||
{
|
||||
return array(
|
||||
'user' => $user['usename'],
|
||||
'password' => $user['passwd']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableDefinition($table)
|
||||
{
|
||||
$schemas = $this->getExistingSchemaSearchPaths();
|
||||
$firstSchema = array_shift($schemas);
|
||||
|
||||
if ($table['schema_name'] == $firstSchema) {
|
||||
return $table['table_name'];
|
||||
} else {
|
||||
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)
|
||||
{
|
||||
$buffer = array();
|
||||
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;";
|
||||
|
||||
$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[] = array(
|
||||
'key_name' => $row['relname'],
|
||||
'column_name' => trim($colRow['attname']),
|
||||
'non_unique' => !$row['indisunique'],
|
||||
'primary' => $row['indisprimary']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent::_getPortableTableIndexesList($buffer, $tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableDatabaseDefinition($database)
|
||||
{
|
||||
return $database['datname'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableSequenceDefinition($sequence)
|
||||
{
|
||||
if ($sequence['schemaname'] != 'public') {
|
||||
$sequenceName = $sequence['schemaname'] . "." . $sequence['relname'];
|
||||
} else {
|
||||
$sequenceName = $sequence['relname'];
|
||||
}
|
||||
|
||||
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));
|
||||
|
||||
return new Sequence($sequenceName, $data[0]['increment_by'], $data[0]['min_value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableColumnDefinition($tableColumn)
|
||||
{
|
||||
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
|
||||
|
||||
if (strtolower($tableColumn['type']) === 'varchar') {
|
||||
// get length from varchar definition
|
||||
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $tableColumn['complete_type']);
|
||||
$tableColumn['length'] = $length;
|
||||
}
|
||||
|
||||
$matches = array();
|
||||
|
||||
$autoincrement = false;
|
||||
if (preg_match("/^nextval\('(.*)'(::.*)?\)$/", $tableColumn['default'], $matches)) {
|
||||
$tableColumn['sequence'] = $matches[1];
|
||||
$tableColumn['default'] = null;
|
||||
$autoincrement = true;
|
||||
}
|
||||
|
||||
if (preg_match("/^'(.*)'::.*$/", $tableColumn['default'], $matches)) {
|
||||
$tableColumn['default'] = $matches[1];
|
||||
}
|
||||
|
||||
if (stripos($tableColumn['default'], 'NULL') === 0) {
|
||||
$tableColumn['default'] = null;
|
||||
}
|
||||
|
||||
$length = (isset($tableColumn['length'])) ? $tableColumn['length'] : null;
|
||||
if ($length == '-1' && isset($tableColumn['atttypmod'])) {
|
||||
$length = $tableColumn['atttypmod'] - 4;
|
||||
}
|
||||
if ((int) $length <= 0) {
|
||||
$length = null;
|
||||
}
|
||||
$fixed = null;
|
||||
|
||||
if (!isset($tableColumn['name'])) {
|
||||
$tableColumn['name'] = '';
|
||||
}
|
||||
|
||||
$precision = null;
|
||||
$scale = null;
|
||||
|
||||
$dbType = strtolower($tableColumn['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);
|
||||
$tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
|
||||
|
||||
switch ($dbType) {
|
||||
case 'smallint':
|
||||
case 'int2':
|
||||
$length = null;
|
||||
break;
|
||||
case 'int':
|
||||
case 'int4':
|
||||
case 'integer':
|
||||
$length = null;
|
||||
break;
|
||||
case 'bigint':
|
||||
case 'int8':
|
||||
$length = null;
|
||||
break;
|
||||
case 'bool':
|
||||
case 'boolean':
|
||||
$length = null;
|
||||
break;
|
||||
case 'text':
|
||||
$fixed = false;
|
||||
break;
|
||||
case 'varchar':
|
||||
case 'interval':
|
||||
case '_varchar':
|
||||
$fixed = false;
|
||||
break;
|
||||
case 'char':
|
||||
case 'bpchar':
|
||||
$fixed = true;
|
||||
break;
|
||||
case 'float':
|
||||
case 'float4':
|
||||
case 'float8':
|
||||
case 'double':
|
||||
case 'double precision':
|
||||
case 'real':
|
||||
case 'decimal':
|
||||
case 'money':
|
||||
case 'numeric':
|
||||
if (preg_match('([A-Za-z]+\(([0-9]+)\,([0-9]+)\))', $tableColumn['complete_type'], $match)) {
|
||||
$precision = $match[1];
|
||||
$scale = $match[2];
|
||||
$length = null;
|
||||
}
|
||||
break;
|
||||
case 'year':
|
||||
$length = null;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($tableColumn['default'] && preg_match("('([^']+)'::)", $tableColumn['default'], $match)) {
|
||||
$tableColumn['default'] = $match[1];
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'length' => $length,
|
||||
'notnull' => (bool) $tableColumn['isnotnull'],
|
||||
'default' => $tableColumn['default'],
|
||||
'primary' => (bool) ($tableColumn['pri'] == 't'),
|
||||
'precision' => $precision,
|
||||
'scale' => $scale,
|
||||
'fixed' => $fixed,
|
||||
'unsigned' => false,
|
||||
'autoincrement' => $autoincrement,
|
||||
'comment' => $tableColumn['comment'],
|
||||
);
|
||||
|
||||
return new Column($tableColumn['field'], \Doctrine\DBAL\Types\Type::getType($type), $options);
|
||||
}
|
||||
}
|
256
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
vendored
Normal file
256
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
vendored
Normal file
@@ -0,0 +1,256 @@
|
||||
<?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\Driver\SQLSrv\SQLSrvException;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
/**
|
||||
* SQL Server Schema Manager.
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @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
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableSequenceDefinition($sequence)
|
||||
{
|
||||
return new Sequence($sequence['name'], $sequence['increment'], $sequence['start_value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableColumnDefinition($tableColumn)
|
||||
{
|
||||
$dbType = strtok($tableColumn['type'], '(), ');
|
||||
$fixed = null;
|
||||
$length = (int) $tableColumn['length'];
|
||||
$default = $tableColumn['default'];
|
||||
|
||||
if (!isset($tableColumn['name'])) {
|
||||
$tableColumn['name'] = '';
|
||||
}
|
||||
|
||||
while ($default != ($default2 = preg_replace("/^\((.*)\)$/", '$1', $default))) {
|
||||
$default = trim($default2, "'");
|
||||
|
||||
if ($default == 'getdate()') {
|
||||
$default = $this->_platform->getCurrentTimestampSQL();
|
||||
}
|
||||
}
|
||||
|
||||
switch ($dbType) {
|
||||
case 'nchar':
|
||||
case 'nvarchar':
|
||||
case 'ntext':
|
||||
// Unicode data requires 2 bytes per character
|
||||
$length = $length / 2;
|
||||
break;
|
||||
case 'varchar':
|
||||
// TEXT type is returned as VARCHAR(MAX) with a length of -1
|
||||
if ($length == -1) {
|
||||
$dbType = 'text';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$type = $this->_platform->getDoctrineTypeMapping($dbType);
|
||||
|
||||
switch ($type) {
|
||||
case 'char':
|
||||
$fixed = true;
|
||||
break;
|
||||
case 'text':
|
||||
$fixed = false;
|
||||
break;
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'length' => ($length == 0 || !in_array($type, array('text', 'string'))) ? null : $length,
|
||||
'unsigned' => false,
|
||||
'fixed' => (bool) $fixed,
|
||||
'default' => $default !== 'NULL' ? $default : null,
|
||||
'notnull' => (bool) $tableColumn['notnull'],
|
||||
'scale' => $tableColumn['scale'],
|
||||
'precision' => $tableColumn['precision'],
|
||||
'autoincrement' => (bool) $tableColumn['autoincrement'],
|
||||
);
|
||||
|
||||
$platformOptions = array(
|
||||
'collate' => $tableColumn['collation'] == 'NULL' ? null : $tableColumn['collation']
|
||||
);
|
||||
|
||||
$column = new Column($tableColumn['name'], Type::getType($type), $options);
|
||||
$column->setPlatformOptions($platformOptions);
|
||||
|
||||
return $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableForeignKeysList($tableForeignKeys)
|
||||
{
|
||||
$foreignKeys = array();
|
||||
|
||||
foreach ($tableForeignKeys as $tableForeignKey) {
|
||||
if ( ! isset($foreignKeys[$tableForeignKey['ForeignKey']])) {
|
||||
$foreignKeys[$tableForeignKey['ForeignKey']] = array(
|
||||
'local_columns' => array($tableForeignKey['ColumnName']),
|
||||
'foreign_table' => $tableForeignKey['ReferenceTableName'],
|
||||
'foreign_columns' => array($tableForeignKey['ReferenceColumnName']),
|
||||
'name' => $tableForeignKey['ForeignKey'],
|
||||
'options' => array(
|
||||
'onUpdate' => str_replace('_', ' ', $tableForeignKey['update_referential_action_desc']),
|
||||
'onDelete' => str_replace('_', ' ', $tableForeignKey['delete_referential_action_desc'])
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$foreignKeys[$tableForeignKey['ForeignKey']]['local_columns'][] = $tableForeignKey['ColumnName'];
|
||||
$foreignKeys[$tableForeignKey['ForeignKey']]['foreign_columns'][] = $tableForeignKey['ReferenceColumnName'];
|
||||
}
|
||||
}
|
||||
|
||||
return parent::_getPortableTableForeignKeysList($foreignKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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'] ? array($tableIndex['flags']) : null;
|
||||
}
|
||||
|
||||
return parent::_getPortableTableIndexesList($tableIndexRows, $tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
|
||||
{
|
||||
return new ForeignKeyConstraint(
|
||||
$tableForeignKey['local_columns'],
|
||||
$tableForeignKey['foreign_table'],
|
||||
$tableForeignKey['foreign_columns'],
|
||||
$tableForeignKey['name'],
|
||||
$tableForeignKey['options']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableDefinition($table)
|
||||
{
|
||||
return $table['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableDatabaseDefinition($database)
|
||||
{
|
||||
return $database['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableViewDefinition($view)
|
||||
{
|
||||
// @todo
|
||||
return new View($view['name'], null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listTableIndexes($table)
|
||||
{
|
||||
$sql = $this->_platform->getListTableIndexesSQL($table, $this->_conn->getDatabase());
|
||||
|
||||
try {
|
||||
$tableIndexes = $this->_conn->fetchAll($sql);
|
||||
} catch(\PDOException $e) {
|
||||
if ($e->getCode() == "IMSSP") {
|
||||
return array();
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
} catch(SQLSrvException $e) {
|
||||
if (strpos($e->getMessage(), 'SQLSTATE [01000, 15472]') === 0) {
|
||||
return array();
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_getPortableTableIndexesList($tableIndexes, $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function alterTable(TableDiff $tableDiff)
|
||||
{
|
||||
if(count($tableDiff->removedColumns) > 0) {
|
||||
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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parent::alterTable($tableDiff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL to retrieve the constraints for a given column.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getColumnConstraintSQL($table, $column)
|
||||
{
|
||||
return "SELECT SysObjects.[Name]
|
||||
FROM SysObjects INNER JOIN (SELECT [Name],[ID] FROM SysObjects WHERE XType = 'U') AS Tab
|
||||
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]";
|
||||
}
|
||||
}
|
414
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Schema.php
vendored
Normal file
414
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Schema.php
vendored
Normal file
@@ -0,0 +1,414 @@
|
||||
<?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\Schema\Visitor\CreateSchemaSqlCollector;
|
||||
use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector;
|
||||
use Doctrine\DBAL\Schema\Visitor\Visitor;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
|
||||
/**
|
||||
* Object representation of a database schema.
|
||||
*
|
||||
* Different vendors have very inconsistent naming with regard to the concept
|
||||
* of a "schema". Doctrine understands a schema as the entity that conceptually
|
||||
* wraps a set of database objects such as tables, sequences, indexes and
|
||||
* foreign keys that belong to each other into a namespace. A Doctrine Schema
|
||||
* has nothing to do with the "SCHEMA" defined as in PostgreSQL, it is more
|
||||
* related to the concept of "DATABASE" that exists in MySQL and PostgreSQL.
|
||||
*
|
||||
* Every asset in the doctrine schema has a name. A name consists of either a
|
||||
* namespace.local name pair or just a local unqualified name.
|
||||
*
|
||||
* The abstraction layer that covers a PostgreSQL schema is the namespace of an
|
||||
* database object (asset). A schema can have a name, which will be used as
|
||||
* default namespace for the unqualified database objects that are created in
|
||||
* the schema.
|
||||
*
|
||||
* In the case of MySQL where cross-database queries are allowed this leads to
|
||||
* databases being "misinterpreted" as namespaces. This is intentional, however
|
||||
* 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
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Table[]
|
||||
*/
|
||||
protected $_tables = array();
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Sequence[]
|
||||
*/
|
||||
protected $_sequences = array();
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\SchemaConfig
|
||||
*/
|
||||
protected $_schemaConfig = false;
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table[] $tables
|
||||
* @param \Doctrine\DBAL\Schema\Sequence[] $sequences
|
||||
* @param \Doctrine\DBAL\Schema\SchemaConfig $schemaConfig
|
||||
*/
|
||||
public function __construct(array $tables=array(), array $sequences=array(), SchemaConfig $schemaConfig=null)
|
||||
{
|
||||
if ($schemaConfig == null) {
|
||||
$schemaConfig = new SchemaConfig();
|
||||
}
|
||||
$this->_schemaConfig = $schemaConfig;
|
||||
$this->_setName($schemaConfig->getName() ?: 'public');
|
||||
|
||||
foreach ($tables as $table) {
|
||||
$this->_addTable($table);
|
||||
}
|
||||
|
||||
foreach ($sequences as $sequence) {
|
||||
$this->_addSequence($sequence);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasExplicitForeignKeyIndexes()
|
||||
{
|
||||
return $this->_schemaConfig->hasExplicitForeignKeyIndexes();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
protected function _addTable(Table $table)
|
||||
{
|
||||
$tableName = $table->getFullQualifiedName($this->getName());
|
||||
if(isset($this->_tables[$tableName])) {
|
||||
throw SchemaException::tableAlreadyExists($tableName);
|
||||
}
|
||||
|
||||
$this->_tables[$tableName] = $table;
|
||||
$table->setSchemaConfig($this->_schemaConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
protected function _addSequence(Sequence $sequence)
|
||||
{
|
||||
$seqName = $sequence->getFullQualifiedName($this->getName());
|
||||
if (isset($this->_sequences[$seqName])) {
|
||||
throw SchemaException::sequenceAlreadyExists($seqName);
|
||||
}
|
||||
$this->_sequences[$seqName] = $sequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all tables of this schema.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table[]
|
||||
*/
|
||||
public function getTables()
|
||||
{
|
||||
return $this->_tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
public function getTable($tableName)
|
||||
{
|
||||
$tableName = $this->getFullQualifiedAssetName($tableName);
|
||||
if (!isset($this->_tables[$tableName])) {
|
||||
throw SchemaException::tableDoesNotExist($tableName);
|
||||
}
|
||||
|
||||
return $this->_tables[$tableName];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFullQualifiedAssetName($name)
|
||||
{
|
||||
if ($this->isIdentifierQuoted($name)) {
|
||||
$name = $this->trimQuotes($name);
|
||||
}
|
||||
if (strpos($name, ".") === false) {
|
||||
$name = $this->getName() . "." . $name;
|
||||
}
|
||||
|
||||
return strtolower($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this schema have a table with the given name?
|
||||
*
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasTable($tableName)
|
||||
{
|
||||
$tableName = $this->getFullQualifiedAssetName($tableName);
|
||||
|
||||
return isset($this->_tables[$tableName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all table names, prefixed with a schema name, even the default one if present.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTableNames()
|
||||
{
|
||||
return array_keys($this->_tables);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sequenceName
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasSequence($sequenceName)
|
||||
{
|
||||
$sequenceName = $this->getFullQualifiedAssetName($sequenceName);
|
||||
|
||||
return isset($this->_sequences[$sequenceName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sequenceName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Sequence
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
public function getSequence($sequenceName)
|
||||
{
|
||||
$sequenceName = $this->getFullQualifiedAssetName($sequenceName);
|
||||
if(!$this->hasSequence($sequenceName)) {
|
||||
throw SchemaException::sequenceDoesNotExist($sequenceName);
|
||||
}
|
||||
|
||||
return $this->_sequences[$sequenceName];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Doctrine\DBAL\Schema\Sequence[]
|
||||
*/
|
||||
public function getSequences()
|
||||
{
|
||||
return $this->_sequences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new table.
|
||||
*
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*/
|
||||
public function createTable($tableName)
|
||||
{
|
||||
$table = new Table($tableName);
|
||||
$this->_addTable($table);
|
||||
|
||||
foreach ($this->_schemaConfig->getDefaultTableOptions() as $name => $value) {
|
||||
$table->addOption($name, $value);
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renames a table.
|
||||
*
|
||||
* @param string $oldTableName
|
||||
* @param string $newTableName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Schema
|
||||
*/
|
||||
public function renameTable($oldTableName, $newTableName)
|
||||
{
|
||||
$table = $this->getTable($oldTableName);
|
||||
$table->_setName($newTableName);
|
||||
|
||||
$this->dropTable($oldTableName);
|
||||
$this->_addTable($table);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops a table from the schema.
|
||||
*
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Schema
|
||||
*/
|
||||
public function dropTable($tableName)
|
||||
{
|
||||
$tableName = $this->getFullQualifiedAssetName($tableName);
|
||||
$this->getTable($tableName);
|
||||
unset($this->_tables[$tableName]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new sequence.
|
||||
*
|
||||
* @param string $sequenceName
|
||||
* @param integer $allocationSize
|
||||
* @param integer $initialValue
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Sequence
|
||||
*/
|
||||
public function createSequence($sequenceName, $allocationSize=1, $initialValue=1)
|
||||
{
|
||||
$seq = new Sequence($sequenceName, $allocationSize, $initialValue);
|
||||
$this->_addSequence($seq);
|
||||
|
||||
return $seq;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sequenceName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Schema
|
||||
*/
|
||||
public function dropSequence($sequenceName)
|
||||
{
|
||||
$sequenceName = $this->getFullQualifiedAssetName($sequenceName);
|
||||
unset($this->_sequences[$sequenceName]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of necessary SQL queries to create the schema on the given platform.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toSql(AbstractPlatform $platform)
|
||||
{
|
||||
$sqlCollector = new CreateSchemaSqlCollector($platform);
|
||||
$this->visit($sqlCollector);
|
||||
|
||||
return $sqlCollector->getQueries();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of necessary SQL queries to drop the schema on the given platform.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toDropSql(AbstractPlatform $platform)
|
||||
{
|
||||
$dropSqlCollector = new DropSchemaSqlCollector($platform);
|
||||
$this->visit($dropSqlCollector);
|
||||
|
||||
return $dropSqlCollector->getQueries();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Schema $toSchema
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform)
|
||||
{
|
||||
$comparator = new Comparator();
|
||||
$schemaDiff = $comparator->compare($this, $toSchema);
|
||||
|
||||
return $schemaDiff->toSql($platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Schema $fromSchema
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform)
|
||||
{
|
||||
$comparator = new Comparator();
|
||||
$schemaDiff = $comparator->compare($fromSchema, $this);
|
||||
|
||||
return $schemaDiff->toSql($platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Visitor\Visitor $visitor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function visit(Visitor $visitor)
|
||||
{
|
||||
$visitor->acceptSchema($this);
|
||||
|
||||
foreach ($this->_tables as $table) {
|
||||
$table->visit($visitor);
|
||||
}
|
||||
foreach ($this->_sequences as $sequence) {
|
||||
$sequence->visit($visitor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cloning a Schema triggers a deep clone of all related assets.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
foreach ($this->_tables as $k => $table) {
|
||||
$this->_tables[$k] = clone $table;
|
||||
}
|
||||
foreach ($this->_sequences as $k => $sequence) {
|
||||
$this->_sequences[$k] = clone $sequence;
|
||||
}
|
||||
}
|
||||
}
|
129
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaConfig.php
vendored
Normal file
129
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaConfig.php
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
<?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 boolean
|
||||
*/
|
||||
protected $hasExplicitForeignKeyIndexes = false;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $maxIdentifierLength = 63;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultTableOptions = array();
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasExplicitForeignKeyIndexes()
|
||||
{
|
||||
return $this->hasExplicitForeignKeyIndexes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $flag
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setExplicitForeignKeyIndexes($flag)
|
||||
{
|
||||
$this->hasExplicitForeignKeyIndexes = (bool)$flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $length
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMaxIdentifierLength($length)
|
||||
{
|
||||
$this->maxIdentifierLength = (int)$length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getMaxIdentifierLength()
|
||||
{
|
||||
return $this->maxIdentifierLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default namespace of schema objects.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default namespace name of schema objects.
|
||||
*
|
||||
* @param string $name The value to set.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default options that are passed to Table instances created with
|
||||
* Schema#createTable().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDefaultTableOptions()
|
||||
{
|
||||
return $this->defaultTableOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $defaultTableOptions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultTableOptions(array $defaultTableOptions)
|
||||
{
|
||||
$this->defaultTableOptions = $defaultTableOptions;
|
||||
}
|
||||
}
|
184
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaDiff.php
vendored
Normal file
184
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaDiff.php
vendored
Normal file
@@ -0,0 +1,184 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public $fromSchema;
|
||||
|
||||
/**
|
||||
* All added tables.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Table[]
|
||||
*/
|
||||
public $newTables = array();
|
||||
|
||||
/**
|
||||
* All changed tables.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\TableDiff[]
|
||||
*/
|
||||
public $changedTables = array();
|
||||
|
||||
/**
|
||||
* All removed tables.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Table[]
|
||||
*/
|
||||
public $removedTables = array();
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Sequence[]
|
||||
*/
|
||||
public $newSequences = array();
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Sequence[]
|
||||
*/
|
||||
public $changedSequences = array();
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Sequence[]
|
||||
*/
|
||||
public $removedSequences = array();
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
|
||||
*/
|
||||
public $orphanedForeignKeys = array();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function __construct($newTables = array(), $changedTables = array(), $removedTables = array(), Schema $fromSchema = null)
|
||||
{
|
||||
$this->newTables = $newTables;
|
||||
$this->changedTables = $changedTables;
|
||||
$this->removedTables = $removedTables;
|
||||
$this->fromSchema = $fromSchema;
|
||||
}
|
||||
|
||||
/**
|
||||
* The to save sql mode ensures that the following things don't happen:
|
||||
*
|
||||
* 1. Tables are deleted
|
||||
* 2. Sequences are deleted
|
||||
* 3. Foreign Keys which reference tables that would otherwise be deleted.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
public function toSaveSql(AbstractPlatform $platform)
|
||||
{
|
||||
return $this->_toSql($platform, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toSql(AbstractPlatform $platform)
|
||||
{
|
||||
return $this->_toSql($platform, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
* @param boolean $saveMode
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _toSql(AbstractPlatform $platform, $saveMode = false)
|
||||
{
|
||||
$sql = array();
|
||||
|
||||
if ($platform->supportsForeignKeyConstraints() && $saveMode == false) {
|
||||
foreach ($this->orphanedForeignKeys as $orphanedForeignKey) {
|
||||
$sql[] = $platform->getDropForeignKeySQL($orphanedForeignKey, $orphanedForeignKey->getLocalTableName());
|
||||
}
|
||||
}
|
||||
|
||||
if ($platform->supportsSequences() == true) {
|
||||
foreach ($this->changedSequences as $sequence) {
|
||||
$sql[] = $platform->getAlterSequenceSQL($sequence);
|
||||
}
|
||||
|
||||
if ($saveMode === false) {
|
||||
foreach ($this->removedSequences as $sequence) {
|
||||
$sql[] = $platform->getDropSequenceSQL($sequence);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->newSequences as $sequence) {
|
||||
$sql[] = $platform->getCreateSequenceSQL($sequence);
|
||||
}
|
||||
}
|
||||
|
||||
$foreignKeySql = array();
|
||||
foreach ($this->newTables as $table) {
|
||||
$sql = array_merge(
|
||||
$sql,
|
||||
$platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES)
|
||||
);
|
||||
|
||||
if ($platform->supportsForeignKeyConstraints()) {
|
||||
foreach ($table->getForeignKeys() as $foreignKey) {
|
||||
$foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table);
|
||||
}
|
||||
}
|
||||
}
|
||||
$sql = array_merge($sql, $foreignKeySql);
|
||||
|
||||
if ($saveMode === false) {
|
||||
foreach ($this->removedTables as $table) {
|
||||
$sql[] = $platform->getDropTableSQL($table);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->changedTables as $tableDiff) {
|
||||
$sql = array_merge($sql, $platform->getAlterTableSQL($tableDiff));
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
}
|
167
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaException.php
vendored
Normal file
167
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaException.php
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
<?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;
|
||||
|
||||
class SchemaException extends \Doctrine\DBAL\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;
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
static public function tableDoesNotExist($tableName)
|
||||
{
|
||||
return new self("There is no table with name '".$tableName."' in the schema.", self::TABLE_DOESNT_EXIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $indexName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
static public function indexNameInvalid($indexName)
|
||||
{
|
||||
return new self("Invalid index-name $indexName given, has to be [a-zA-Z0-9_]", self::INDEX_INVALID_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $indexName
|
||||
* @param string $table
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
static public function indexDoesNotExist($indexName, $table)
|
||||
{
|
||||
return new self("Index '$indexName' does not exist on table '$table'.", self::INDEX_DOESNT_EXIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $indexName
|
||||
* @param string $table
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
static public function indexAlreadyExists($indexName, $table)
|
||||
{
|
||||
return new self("An index with name '$indexName' was already defined on table '$table'.", self::INDEX_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $columnName
|
||||
* @param string $table
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
static public function columnDoesNotExist($columnName, $table)
|
||||
{
|
||||
return new self("There is no column with name '$columnName' on table '$table'.", self::COLUMN_DOESNT_EXIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
static public function tableAlreadyExists($tableName)
|
||||
{
|
||||
return new self("The table with name '".$tableName."' already exists.", self::TABLE_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
* @param string $columnName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
static public function columnAlreadyExists($tableName, $columnName)
|
||||
{
|
||||
return new self(
|
||||
"The column '".$columnName."' on table '".$tableName."' already exists.", self::COLUMN_ALREADY_EXISTS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sequenceName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
static public function sequenceAlreadyExists($sequenceName)
|
||||
{
|
||||
return new self("The sequence '".$sequenceName."' already exists.", self::SEQUENCE_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sequenceName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
static public function sequenceDoesNotExist($sequenceName)
|
||||
{
|
||||
return new self("There exists no sequence with the name '".$sequenceName."'.", self::SEQUENCE_DOENST_EXIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fkName
|
||||
* @param string $table
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
static public function foreignKeyDoesNotExist($fkName, $table)
|
||||
{
|
||||
return new self("There exists no foreign key with the name '$fkName' on table '$table'.", self::FOREIGNKEY_DOESNT_EXIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $localTable
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
static public 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."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $changeName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
static public function alterTableChangeNotSupported($changeName)
|
||||
{
|
||||
return new self ("Alter table change not supported, given '$changeName'");
|
||||
}
|
||||
}
|
135
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Sequence.php
vendored
Normal file
135
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Sequence.php
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
<?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\Schema\Visitor\Visitor;
|
||||
|
||||
/**
|
||||
* Sequence structure.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class Sequence extends AbstractAsset
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $_allocationSize = 1;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $_initialValue = 1;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param integer $allocationSize
|
||||
* @param integer $initialValue
|
||||
*/
|
||||
public function __construct($name, $allocationSize=1, $initialValue=1)
|
||||
{
|
||||
$this->_setName($name);
|
||||
$this->_allocationSize = (is_numeric($allocationSize))?$allocationSize:1;
|
||||
$this->_initialValue = (is_numeric($initialValue))?$initialValue:1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getAllocationSize()
|
||||
{
|
||||
return $this->_allocationSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getInitialValue()
|
||||
{
|
||||
return $this->_initialValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $allocationSize
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAllocationSize($allocationSize)
|
||||
{
|
||||
$this->_allocationSize = (is_numeric($allocationSize))?$allocationSize:1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $initialValue
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setInitialValue($initialValue)
|
||||
{
|
||||
$this->_initialValue = (is_numeric($initialValue))?$initialValue:1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this sequence is an autoincrement sequence for a given table.
|
||||
*
|
||||
* 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 boolean
|
||||
*/
|
||||
public function isAutoIncrementsFor(Table $table)
|
||||
{
|
||||
if ( ! $table->hasPrimaryKey()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$pkColumns = $table->getPrimaryKey()->getColumns();
|
||||
|
||||
if (count($pkColumns) != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$column = $table->getColumn($pkColumns[0]);
|
||||
|
||||
if ( ! $column->getAutoincrement()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sequenceName = $this->getShortestName($table->getNamespaceName());
|
||||
$tableName = $table->getShortestName($table->getNamespaceName());
|
||||
$tableSequenceName = sprintf('%s_%s_seq', $tableName, $pkColumns[0]);
|
||||
|
||||
return $tableSequenceName === $sequenceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Visitor\Visitor $visitor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function visit(Visitor $visitor)
|
||||
{
|
||||
$visitor->acceptSequence($this);
|
||||
}
|
||||
}
|
390
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php
vendored
Normal file
390
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php
vendored
Normal file
@@ -0,0 +1,390 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dropDatabase($database)
|
||||
{
|
||||
if (file_exists($database)) {
|
||||
unlink($database);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createDatabase($database)
|
||||
{
|
||||
$params = $this->_conn->getParams();
|
||||
$driver = $params['driver'];
|
||||
$options = array(
|
||||
'driver' => $driver,
|
||||
'path' => $database
|
||||
);
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
||||
$conn->connect();
|
||||
$conn->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function renameTable($name, $newName)
|
||||
{
|
||||
$tableDiff = new TableDiff($name);
|
||||
$tableDiff->fromTable = $this->listTableDetails($name);
|
||||
$tableDiff->newName = $newName;
|
||||
$this->alterTable($tableDiff);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createForeignKey(ForeignKeyConstraint $foreignKey, $table)
|
||||
{
|
||||
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table);
|
||||
$tableDiff->addedForeignKeys[] = $foreignKey;
|
||||
|
||||
$this->alterTable($tableDiff);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table)
|
||||
{
|
||||
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table);
|
||||
$tableDiff->changedForeignKeys[] = $foreignKey;
|
||||
|
||||
$this->alterTable($tableDiff);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dropForeignKey($foreignKey, $table)
|
||||
{
|
||||
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table);
|
||||
$tableDiff->removedForeignKeys[] = $foreignKey;
|
||||
|
||||
$this->alterTable($tableDiff);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listTableForeignKeys($table, $database = null)
|
||||
{
|
||||
if (null === $database) {
|
||||
$database = $this->_conn->getDatabase();
|
||||
}
|
||||
$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 = isset($createSql[0]['sql']) ? $createSql[0]['sql'] : '';
|
||||
if (preg_match_all('#
|
||||
(?:CONSTRAINT\s+([^\s]+)\s+)?
|
||||
(?:FOREIGN\s+KEY[^\)]+\)\s*)?
|
||||
REFERENCES\s+[^\s]+\s+(?:\([^\)]+\))?
|
||||
(?:
|
||||
[^,]*?
|
||||
(NOT\s+DEFERRABLE|DEFERRABLE)
|
||||
(?:\s+INITIALLY\s+(DEFERRED|IMMEDIATE))?
|
||||
)?#isx',
|
||||
$createSql, $match)) {
|
||||
|
||||
$names = array_reverse($match[1]);
|
||||
$deferrable = array_reverse($match[2]);
|
||||
$deferred = array_reverse($match[3]);
|
||||
} else {
|
||||
$names = $deferrable = $deferred = array();
|
||||
}
|
||||
|
||||
foreach ($tableForeignKeys as $key => $value) {
|
||||
$id = $value['id'];
|
||||
$tableForeignKeys[$key]['constraint_name'] = isset($names[$id]) && '' != $names[$id] ? $names[$id] : $id;
|
||||
$tableForeignKeys[$key]['deferrable'] = isset($deferrable[$id]) && 'deferrable' == strtolower($deferrable[$id]) ? true : false;
|
||||
$tableForeignKeys[$key]['deferred'] = isset($deferred[$id]) && 'deferred' == strtolower($deferred[$id]) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_getPortableTableForeignKeysList($tableForeignKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableDefinition($table)
|
||||
{
|
||||
return $table['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @license New BSD License
|
||||
* @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html
|
||||
*/
|
||||
protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
|
||||
{
|
||||
$indexBuffer = array();
|
||||
|
||||
// fetch primary
|
||||
$stmt = $this->_conn->executeQuery( "PRAGMA TABLE_INFO ('$tableName')" );
|
||||
$indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
foreach($indexArray as $indexColumnRow) {
|
||||
if($indexColumnRow['pk'] == "1") {
|
||||
$indexBuffer[] = array(
|
||||
'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 = array();
|
||||
$idx['key_name'] = $keyName;
|
||||
$idx['primary'] = false;
|
||||
$idx['non_unique'] = $tableIndex['unique']?false:true;
|
||||
|
||||
$stmt = $this->_conn->executeQuery( "PRAGMA INDEX_INFO ( '{$keyName}' )" );
|
||||
$indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ( $indexArray as $indexColumnRow ) {
|
||||
$idx['column_name'] = $indexColumnRow['name'];
|
||||
$indexBuffer[] = $idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent::_getPortableTableIndexesList($indexBuffer, $tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableIndexDefinition($tableIndex)
|
||||
{
|
||||
return array(
|
||||
'name' => $tableIndex['name'],
|
||||
'unique' => (bool) $tableIndex['unique']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableColumnList($table, $database, $tableColumns)
|
||||
{
|
||||
$list = parent::_getPortableTableColumnList($table, $database, $tableColumns);
|
||||
$autoincrementColumn = null;
|
||||
$autoincrementCount = 0;
|
||||
foreach ($tableColumns as $tableColumn) {
|
||||
if ('1' == $tableColumn['pk']) {
|
||||
$autoincrementCount++;
|
||||
if (null === $autoincrementColumn && 'integer' == strtolower($tableColumn['type'])) {
|
||||
$autoincrementColumn = $tableColumn['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (1 == $autoincrementCount && null !== $autoincrementColumn) {
|
||||
foreach ($list as $column) {
|
||||
if ($autoincrementColumn == $column->getName()) {
|
||||
$column->setAutoincrement(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableColumnDefinition($tableColumn)
|
||||
{
|
||||
$e = explode('(', $tableColumn['type']);
|
||||
$tableColumn['type'] = $e[0];
|
||||
if (isset($e[1])) {
|
||||
$length = trim($e[1], ')');
|
||||
$tableColumn['length'] = $length;
|
||||
}
|
||||
|
||||
$dbType = strtolower($tableColumn['type']);
|
||||
$length = isset($tableColumn['length']) ? $tableColumn['length'] : null;
|
||||
$unsigned = (boolean) isset($tableColumn['unsigned']) ? $tableColumn['unsigned'] : false;
|
||||
$fixed = false;
|
||||
$type = $this->_platform->getDoctrineTypeMapping($dbType);
|
||||
$default = $tableColumn['dflt_value'];
|
||||
if ($default == 'NULL') {
|
||||
$default = null;
|
||||
}
|
||||
if ($default !== null) {
|
||||
// SQLite returns strings wrapped in single quotes, so we need to strip them
|
||||
$default = preg_replace("/^'(.*)'$/", '\1', $default);
|
||||
}
|
||||
$notnull = (bool) $tableColumn['notnull'];
|
||||
|
||||
if ( ! isset($tableColumn['name'])) {
|
||||
$tableColumn['name'] = '';
|
||||
}
|
||||
|
||||
$precision = null;
|
||||
$scale = null;
|
||||
|
||||
switch ($dbType) {
|
||||
case 'char':
|
||||
$fixed = true;
|
||||
break;
|
||||
case 'float':
|
||||
case 'double':
|
||||
case 'real':
|
||||
case 'decimal':
|
||||
case 'numeric':
|
||||
if (isset($tableColumn['length'])) {
|
||||
if (strpos($tableColumn['length'], ',') === false) {
|
||||
$tableColumn['length'] .= ",0";
|
||||
}
|
||||
list($precision, $scale) = array_map('trim', explode(',', $tableColumn['length']));
|
||||
}
|
||||
$length = null;
|
||||
break;
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'length' => $length,
|
||||
'unsigned' => (bool) $unsigned,
|
||||
'fixed' => $fixed,
|
||||
'notnull' => $notnull,
|
||||
'default' => $default,
|
||||
'precision' => $precision,
|
||||
'scale' => $scale,
|
||||
'autoincrement' => false,
|
||||
);
|
||||
|
||||
return new Column($tableColumn['name'], \Doctrine\DBAL\Types\Type::getType($type), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableViewDefinition($view)
|
||||
{
|
||||
return new View($view['name'], $view['sql']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getPortableTableForeignKeysList($tableForeignKeys)
|
||||
{
|
||||
$list = array();
|
||||
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") {
|
||||
$value['on_delete'] = null;
|
||||
}
|
||||
if ( ! isset($value['on_update']) || $value['on_update'] == "RESTRICT") {
|
||||
$value['on_update'] = null;
|
||||
}
|
||||
|
||||
$list[$name] = array(
|
||||
'name' => $name,
|
||||
'local' => array(),
|
||||
'foreign' => array(),
|
||||
'foreignTable' => $value['table'],
|
||||
'onDelete' => $value['on_delete'],
|
||||
'onUpdate' => $value['on_update'],
|
||||
'deferrable' => $value['deferrable'],
|
||||
'deferred'=> $value['deferred'],
|
||||
);
|
||||
}
|
||||
$list[$name]['local'][] = $value['from'];
|
||||
$list[$name]['foreign'][] = $value['to'];
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach($list as $constraint) {
|
||||
$result[] = new ForeignKeyConstraint(
|
||||
array_values($constraint['local']), $constraint['foreignTable'],
|
||||
array_values($constraint['foreign']), $constraint['name'],
|
||||
array(
|
||||
'onDelete' => $constraint['onDelete'],
|
||||
'onUpdate' => $constraint['onUpdate'],
|
||||
'deferrable' => $constraint['deferrable'],
|
||||
'deferred'=> $constraint['deferred'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey
|
||||
* @param \Doctrine\DBAL\Schema\Table|string $table
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff
|
||||
*
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
private function getTableDiffForAlterForeignKey(ForeignKeyConstraint $foreignKey, $table)
|
||||
{
|
||||
if ( ! $table instanceof Table) {
|
||||
$tableDetails = $this->tryMethod('listTableDetails', $table);
|
||||
if (false === $table) {
|
||||
throw new DBALException(sprintf('Sqlite schema manager requires to modify foreign keys table definition "%s".', $table));
|
||||
}
|
||||
|
||||
$table = $tableDetails;
|
||||
}
|
||||
|
||||
$tableDiff = new TableDiff($table->getName());
|
||||
$tableDiff->fromTable = $table;
|
||||
|
||||
return $tableDiff;
|
||||
}
|
||||
}
|
65
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php
vendored
Normal file
65
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Abstract schema synchronizer with methods for executing batches of SQL.
|
||||
*/
|
||||
abstract class AbstractSchemaSynchronizer implements SchemaSynchronizer
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $conn;
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Connection $conn
|
||||
*/
|
||||
public function __construct(Connection $conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sql
|
||||
*/
|
||||
protected function processSqlSafely(array $sql)
|
||||
{
|
||||
foreach ($sql as $s) {
|
||||
try {
|
||||
$this->conn->exec($s);
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sql
|
||||
*/
|
||||
protected function processSql(array $sql)
|
||||
{
|
||||
foreach ($sql as $s) {
|
||||
$this->conn->exec($s);
|
||||
}
|
||||
}
|
||||
}
|
101
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php
vendored
Normal file
101
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
<?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\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
|
||||
*/
|
||||
function getCreateSchema(Schema $createSchema);
|
||||
|
||||
/**
|
||||
* Gets the SQL Statements to update given schema with the underlying db.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Schema $toSchema
|
||||
* @param boolean $noDrops
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
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
|
||||
*/
|
||||
function getDropSchema(Schema $dropSchema);
|
||||
|
||||
/**
|
||||
* Gets the SQL statements to drop all schema assets from underlying db.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getDropAllSchema();
|
||||
|
||||
/**
|
||||
* Creates the Schema.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Schema $createSchema
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function createSchema(Schema $createSchema);
|
||||
|
||||
/**
|
||||
* Updates the Schema to new schema version.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Schema $toSchema
|
||||
* @param boolean $noDrops
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Drops all assets from the underlying db.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function dropAllSchema();
|
||||
}
|
176
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php
vendored
Normal file
176
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
<?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\Schema\Comparator;
|
||||
use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector;
|
||||
|
||||
/**
|
||||
* Schema Synchronizer for Default DBAL Connection.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
|
||||
*/
|
||||
private $platform;
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Connection $conn
|
||||
*/
|
||||
public function __construct(Connection $conn)
|
||||
{
|
||||
parent::__construct($conn);
|
||||
$this->platform = $conn->getDatabasePlatform();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCreateSchema(Schema $createSchema)
|
||||
{
|
||||
return $createSchema->toSql($this->platform);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getUpdateSchema(Schema $toSchema, $noDrops = false)
|
||||
{
|
||||
$comparator = new Comparator();
|
||||
$sm = $this->conn->getSchemaManager();
|
||||
|
||||
$fromSchema = $sm->createSchema();
|
||||
$schemaDiff = $comparator->compare($fromSchema, $toSchema);
|
||||
|
||||
if ($noDrops) {
|
||||
return $schemaDiff->toSaveSql($this->platform);
|
||||
}
|
||||
|
||||
return $schemaDiff->toSql($this->platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDropSchema(Schema $dropSchema)
|
||||
{
|
||||
$visitor = new DropSchemaSqlCollector($this->platform);
|
||||
$sm = $this->conn->getSchemaManager();
|
||||
|
||||
$fullSchema = $sm->createSchema();
|
||||
|
||||
foreach ($fullSchema->getTables() as $table) {
|
||||
if ( $dropSchema->hasTable($table->getName())) {
|
||||
$visitor->acceptTable($table);
|
||||
}
|
||||
|
||||
foreach ($table->getForeignKeys() as $foreignKey) {
|
||||
if ( ! $dropSchema->hasTable($table->getName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! $dropSchema->hasTable($foreignKey->getForeignTableName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$visitor->acceptForeignKey($table, $foreignKey);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $this->platform->supportsSequences()) {
|
||||
return $visitor->getQueries();
|
||||
}
|
||||
|
||||
foreach ($dropSchema->getSequences() as $sequence) {
|
||||
$visitor->acceptSequence($sequence);
|
||||
}
|
||||
|
||||
foreach ($dropSchema->getTables() as $table) {
|
||||
if ( ! $table->hasPrimaryKey()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$columns = $table->getPrimaryKey()->getColumns();
|
||||
if (count($columns) > 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$checkSequence = $table->getName() . "_" . $columns[0] . "_seq";
|
||||
if ($fullSchema->hasSequence($checkSequence)) {
|
||||
$visitor->acceptSequence($fullSchema->getSequence($checkSequence));
|
||||
}
|
||||
}
|
||||
|
||||
return $visitor->getQueries();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDropAllSchema()
|
||||
{
|
||||
$sm = $this->conn->getSchemaManager();
|
||||
$visitor = new DropSchemaSqlCollector($this->platform);
|
||||
|
||||
/* @var $schema \Doctrine\DBAL\Schema\Schema */
|
||||
$schema = $sm->createSchema();
|
||||
$schema->visit($visitor);
|
||||
|
||||
return $visitor->getQueries();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createSchema(Schema $createSchema)
|
||||
{
|
||||
$this->processSql($this->getCreateSchema($createSchema));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateSchema(Schema $toSchema, $noDrops = false)
|
||||
{
|
||||
$this->processSql($this->getUpdateSchema($toSchema, $noDrops));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dropSchema(Schema $dropSchema)
|
||||
{
|
||||
$this->processSqlSafely($this->getDropSchema($dropSchema));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dropAllSchema()
|
||||
{
|
||||
$this->processSql($this->getDropAllSchema());
|
||||
}
|
||||
}
|
771
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Table.php
vendored
Normal file
771
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Table.php
vendored
Normal file
@@ -0,0 +1,771 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
protected $_name = null;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Column[]
|
||||
*/
|
||||
protected $_columns = array();
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Index[]
|
||||
*/
|
||||
protected $_indexes = array();
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_primaryKeyName = false;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
|
||||
*/
|
||||
protected $_fkConstraints = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_options = array();
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\SchemaConfig
|
||||
*/
|
||||
protected $_schemaConfig = null;
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
* @param array $columns
|
||||
* @param array $indexes
|
||||
* @param array $fkConstraints
|
||||
* @param integer $idGeneratorType
|
||||
* @param array $options
|
||||
*
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function __construct($tableName, array $columns=array(), array $indexes=array(), array $fkConstraints=array(), $idGeneratorType = 0, array $options=array())
|
||||
{
|
||||
if (strlen($tableName) == 0) {
|
||||
throw DBALException::invalidTableName($tableName);
|
||||
}
|
||||
|
||||
$this->_setName($tableName);
|
||||
$this->_idGeneratorType = $idGeneratorType;
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$this->_addColumn($column);
|
||||
}
|
||||
|
||||
foreach ($indexes as $idx) {
|
||||
$this->_addIndex($idx);
|
||||
}
|
||||
|
||||
foreach ($fkConstraints as $constraint) {
|
||||
$this->_addForeignKeyConstraint($constraint);
|
||||
}
|
||||
|
||||
$this->_options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\SchemaConfig $schemaConfig
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setSchemaConfig(SchemaConfig $schemaConfig)
|
||||
{
|
||||
$this->_schemaConfig = $schemaConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
protected function _getMaxIdentifierLength()
|
||||
{
|
||||
if ($this->_schemaConfig instanceof SchemaConfig) {
|
||||
return $this->_schemaConfig->getMaxIdentifierLength();
|
||||
} else {
|
||||
return 63;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Primary Key.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param string|boolean $indexName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*/
|
||||
public function setPrimaryKey(array $columns, $indexName = false)
|
||||
{
|
||||
$primaryKey = $this->_createIndex($columns, $indexName ?: "primary", true, true);
|
||||
|
||||
foreach ($columns as $columnName) {
|
||||
$column = $this->getColumn($columnName);
|
||||
$column->setNotnull(true);
|
||||
}
|
||||
|
||||
return $primaryKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $columnNames
|
||||
* @param string|null $indexName
|
||||
* @param array $flags
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*/
|
||||
public function addIndex(array $columnNames, $indexName = null, array $flags = array())
|
||||
{
|
||||
if($indexName == null) {
|
||||
$indexName = $this->_generateIdentifierName(
|
||||
array_merge(array($this->getName()), $columnNames), "idx", $this->_getMaxIdentifierLength()
|
||||
);
|
||||
}
|
||||
|
||||
return $this->_createIndex($columnNames, $indexName, false, false, $flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops the primary key from this table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dropPrimaryKey()
|
||||
{
|
||||
$this->dropIndex($this->_primaryKeyName);
|
||||
$this->_primaryKeyName = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops an index from this table.
|
||||
*
|
||||
* @param string $indexName The index name.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException If the index does not exist.
|
||||
*/
|
||||
public function dropIndex($indexName)
|
||||
{
|
||||
$indexName = strtolower($indexName);
|
||||
if ( ! $this->hasIndex($indexName)) {
|
||||
throw SchemaException::indexDoesNotExist($indexName, $this->_name);
|
||||
}
|
||||
unset($this->_indexes[$indexName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $columnNames
|
||||
* @param string|null $indexName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*/
|
||||
public function addUniqueIndex(array $columnNames, $indexName = null)
|
||||
{
|
||||
if ($indexName === null) {
|
||||
$indexName = $this->_generateIdentifierName(
|
||||
array_merge(array($this->getName()), $columnNames), "uniq", $this->_getMaxIdentifierLength()
|
||||
);
|
||||
}
|
||||
|
||||
return $this->_createIndex($columnNames, $indexName, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an index begins in the order of the given columns.
|
||||
*
|
||||
* @param array $columnsNames
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function columnsAreIndexed(array $columnsNames)
|
||||
{
|
||||
foreach ($this->getIndexes() as $index) {
|
||||
/* @var $index Index */
|
||||
if ($index->spansColumns($columnsNames)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $columnNames
|
||||
* @param string $indexName
|
||||
* @param boolean $isUnique
|
||||
* @param boolean $isPrimary
|
||||
* @param array $flags
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
private function _createIndex(array $columnNames, $indexName, $isUnique, $isPrimary, array $flags = array())
|
||||
{
|
||||
if (preg_match('(([^a-zA-Z0-9_]+))', $indexName)) {
|
||||
throw SchemaException::indexNameInvalid($indexName);
|
||||
}
|
||||
|
||||
foreach ($columnNames as $columnName => $indexColOptions) {
|
||||
if (is_numeric($columnName) && is_string($indexColOptions)) {
|
||||
$columnName = $indexColOptions;
|
||||
}
|
||||
|
||||
if ( ! $this->hasColumn($columnName)) {
|
||||
throw SchemaException::columnDoesNotExist($columnName, $this->_name);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_addIndex(new Index($indexName, $columnNames, $isUnique, $isPrimary, $flags));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $columnName
|
||||
* @param string $typeName
|
||||
* @param array $options
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function addColumn($columnName, $typeName, array $options=array())
|
||||
{
|
||||
$column = new Column($columnName, Type::getType($typeName), $options);
|
||||
|
||||
$this->_addColumn($column);
|
||||
|
||||
return $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renames a Column.
|
||||
*
|
||||
* @param string $oldColumnName
|
||||
* @param string $newColumnName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*
|
||||
* @throws \Doctrine\DBAL\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.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Column Details.
|
||||
*
|
||||
* @param string $columnName
|
||||
* @param array $options
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*/
|
||||
public function changeColumn($columnName, array $options)
|
||||
{
|
||||
$column = $this->getColumn($columnName);
|
||||
$column->setOptions($options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops a Column from the Table.
|
||||
*
|
||||
* @param string $columnName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*/
|
||||
public function dropColumn($columnName)
|
||||
{
|
||||
$columnName = strtolower($columnName);
|
||||
unset($this->_columns[$columnName]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a foreign key constraint.
|
||||
*
|
||||
* Name is inferred from the local columns.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Table $foreignTable
|
||||
* @param array $localColumnNames
|
||||
* @param array $foreignColumnNames
|
||||
* @param array $options
|
||||
* @param string|null $constraintName
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*/
|
||||
public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options=array(), $constraintName = null)
|
||||
{
|
||||
$constraintName = $constraintName ?: $this->_generateIdentifierName(array_merge((array)$this->getName(), $localColumnNames), "fk", $this->_getMaxIdentifierLength());
|
||||
|
||||
return $this->addNamedForeignKeyConstraint($constraintName, $foreignTable, $localColumnNames, $foreignColumnNames, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a foreign key constraint.
|
||||
*
|
||||
* Name is to be generated by the database itself.
|
||||
*
|
||||
* @deprecated Use {@link addForeignKeyConstraint}
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Table $foreignTable
|
||||
* @param array $localColumnNames
|
||||
* @param array $foreignColumnNames
|
||||
* @param array $options
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*/
|
||||
public function addUnnamedForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options=array())
|
||||
{
|
||||
return $this->addForeignKeyConstraint($foreignTable, $localColumnNames, $foreignColumnNames, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a foreign key constraint with a given name.
|
||||
*
|
||||
* @deprecated Use {@link addForeignKeyConstraint}
|
||||
*
|
||||
* @param string $name
|
||||
* @param \Doctrine\DBAL\Schema\Table $foreignTable
|
||||
* @param array $localColumnNames
|
||||
* @param array $foreignColumnNames
|
||||
* @param array $options
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
public function addNamedForeignKeyConstraint($name, $foreignTable, array $localColumnNames, array $foreignColumnNames, array $options=array())
|
||||
{
|
||||
if ($foreignTable instanceof Table) {
|
||||
foreach ($foreignColumnNames as $columnName) {
|
||||
if ( ! $foreignTable->hasColumn($columnName)) {
|
||||
throw SchemaException::columnDoesNotExist($columnName, $foreignTable->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($localColumnNames as $columnName) {
|
||||
if ( ! $this->hasColumn($columnName)) {
|
||||
throw SchemaException::columnDoesNotExist($columnName, $this->_name);
|
||||
}
|
||||
}
|
||||
|
||||
$constraint = new ForeignKeyConstraint(
|
||||
$localColumnNames, $foreignTable, $foreignColumnNames, $name, $options
|
||||
);
|
||||
$this->_addForeignKeyConstraint($constraint);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*/
|
||||
public function addOption($name, $value)
|
||||
{
|
||||
$this->_options[$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Column $column
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
protected function _addColumn(Column $column)
|
||||
{
|
||||
$columnName = $column->getName();
|
||||
$columnName = strtolower($columnName);
|
||||
|
||||
if (isset($this->_columns[$columnName])) {
|
||||
throw SchemaException::columnAlreadyExists($this->getName(), $columnName);
|
||||
}
|
||||
|
||||
$this->_columns[$columnName] = $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an index to the table.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Index $indexCandidate
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
protected function _addIndex(Index $indexCandidate)
|
||||
{
|
||||
// check for duplicates
|
||||
foreach ($this->_indexes as $existingIndex) {
|
||||
if ($indexCandidate->isFullfilledBy($existingIndex)) {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
$indexName = $indexCandidate->getName();
|
||||
$indexName = strtolower($indexName);
|
||||
|
||||
if (isset($this->_indexes[$indexName]) || ($this->_primaryKeyName != false && $indexCandidate->isPrimary())) {
|
||||
throw SchemaException::indexAlreadyExists($indexName, $this->_name);
|
||||
}
|
||||
|
||||
// remove overruled indexes
|
||||
foreach ($this->_indexes as $idxKey => $existingIndex) {
|
||||
if ($indexCandidate->overrules($existingIndex)) {
|
||||
unset($this->_indexes[$idxKey]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($indexCandidate->isPrimary()) {
|
||||
$this->_primaryKeyName = $indexName;
|
||||
}
|
||||
|
||||
$this->_indexes[$indexName] = $indexCandidate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $constraint
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint)
|
||||
{
|
||||
$constraint->setLocalTable($this);
|
||||
|
||||
if(strlen($constraint->getName())) {
|
||||
$name = $constraint->getName();
|
||||
} else {
|
||||
$name = $this->_generateIdentifierName(
|
||||
array_merge((array)$this->getName(), $constraint->getLocalColumns()), "fk", $this->_getMaxIdentifierLength()
|
||||
);
|
||||
}
|
||||
$name = strtolower($name);
|
||||
|
||||
$this->_fkConstraints[$name] = $constraint;
|
||||
// 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).
|
||||
$this->addIndex($constraint->getColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this table has a foreign key constraint with the given name.
|
||||
*
|
||||
* @param string $constraintName
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasForeignKey($constraintName)
|
||||
{
|
||||
$constraintName = strtolower($constraintName);
|
||||
|
||||
return isset($this->_fkConstraints[$constraintName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the foreign key constraint with the given name.
|
||||
*
|
||||
* @param string $constraintName The constraint name.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\ForeignKeyConstraint
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException If the foreign key does not exist.
|
||||
*/
|
||||
public function getForeignKey($constraintName)
|
||||
{
|
||||
$constraintName = strtolower($constraintName);
|
||||
if(!$this->hasForeignKey($constraintName)) {
|
||||
throw SchemaException::foreignKeyDoesNotExist($constraintName, $this->_name);
|
||||
}
|
||||
|
||||
return $this->_fkConstraints[$constraintName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the foreign key constraint with the given name.
|
||||
*
|
||||
* @param string $constraintName The constraint name.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
public function removeForeignKey($constraintName)
|
||||
{
|
||||
$constraintName = strtolower($constraintName);
|
||||
if(!$this->hasForeignKey($constraintName)) {
|
||||
throw SchemaException::foreignKeyDoesNotExist($constraintName, $this->_name);
|
||||
}
|
||||
|
||||
unset($this->_fkConstraints[$constraintName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Doctrine\DBAL\Schema\Column[]
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
$columns = $this->_columns;
|
||||
|
||||
$pkCols = array();
|
||||
$fkCols = array();
|
||||
|
||||
if ($this->hasPrimaryKey()) {
|
||||
$pkCols = $this->getPrimaryKey()->getColumns();
|
||||
}
|
||||
foreach ($this->getForeignKeys() as $fk) {
|
||||
/* @var $fk ForeignKeyConstraint */
|
||||
$fkCols = array_merge($fkCols, $fk->getColumns());
|
||||
}
|
||||
$colNames = array_unique(array_merge($pkCols, $fkCols, array_keys($columns)));
|
||||
|
||||
uksort($columns, function($a, $b) use($colNames) {
|
||||
return (array_search($a, $colNames) >= array_search($b, $colNames));
|
||||
});
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this table has a Column with the given name.
|
||||
*
|
||||
* @param string $columnName The column name.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasColumn($columnName)
|
||||
{
|
||||
$columnName = $this->trimQuotes(strtolower($columnName));
|
||||
|
||||
return isset($this->_columns[$columnName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Column with the given name.
|
||||
*
|
||||
* @param string $columnName The column name.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException If the column does not exist.
|
||||
*/
|
||||
public function getColumn($columnName)
|
||||
{
|
||||
$columnName = strtolower($this->trimQuotes($columnName));
|
||||
if ( ! $this->hasColumn($columnName)) {
|
||||
throw SchemaException::columnDoesNotExist($columnName, $this->_name);
|
||||
}
|
||||
|
||||
return $this->_columns[$columnName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primary key.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Index|null The primary key, or null if this Table has no primary key.
|
||||
*/
|
||||
public function getPrimaryKey()
|
||||
{
|
||||
if ( ! $this->hasPrimaryKey()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->getIndex($this->_primaryKeyName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primary key columns.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function getPrimaryKeyColumns()
|
||||
{
|
||||
if ( ! $this->hasPrimaryKey()) {
|
||||
throw new DBALException("Table " . $this->getName() . " has no primary key.");
|
||||
}
|
||||
|
||||
return $this->getPrimaryKey()->getColumns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this table has a primary key.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasPrimaryKey()
|
||||
{
|
||||
return ($this->_primaryKeyName && $this->hasIndex($this->_primaryKeyName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this table has an Index with the given name.
|
||||
*
|
||||
* @param string $indexName The index name.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasIndex($indexName)
|
||||
{
|
||||
$indexName = strtolower($indexName);
|
||||
|
||||
return (isset($this->_indexes[$indexName]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Index with the given name.
|
||||
*
|
||||
* @param string $indexName The index name.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\Index
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException If the index does not exist.
|
||||
*/
|
||||
public function getIndex($indexName)
|
||||
{
|
||||
$indexName = strtolower($indexName);
|
||||
if ( ! $this->hasIndex($indexName)) {
|
||||
throw SchemaException::indexDoesNotExist($indexName, $this->_name);
|
||||
}
|
||||
|
||||
return $this->_indexes[$indexName];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Doctrine\DBAL\Schema\Index[]
|
||||
*/
|
||||
public function getIndexes()
|
||||
{
|
||||
return $this->_indexes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the foreign key constraints.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
|
||||
*/
|
||||
public function getForeignKeys()
|
||||
{
|
||||
return $this->_fkConstraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasOption($name)
|
||||
{
|
||||
return isset($this->_options[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOption($name)
|
||||
{
|
||||
return $this->_options[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Visitor\Visitor $visitor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function visit(Visitor $visitor)
|
||||
{
|
||||
$visitor->acceptTable($this);
|
||||
|
||||
foreach ($this->getColumns() as $column) {
|
||||
$visitor->acceptColumn($this, $column);
|
||||
}
|
||||
|
||||
foreach ($this->getIndexes() as $index) {
|
||||
$visitor->acceptIndex($this, $index);
|
||||
}
|
||||
|
||||
foreach ($this->getForeignKeys() as $constraint) {
|
||||
$visitor->acceptForeignKey($this, $constraint);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone of a Table triggers a deep clone of all affected assets.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
foreach ($this->_columns as $k => $column) {
|
||||
$this->_columns[$k] = clone $column;
|
||||
}
|
||||
foreach ($this->_indexes as $k => $index) {
|
||||
$this->_indexes[$k] = clone $index;
|
||||
}
|
||||
foreach ($this->_fkConstraints as $k => $fk) {
|
||||
$this->_fkConstraints[$k] = clone $fk;
|
||||
$this->_fkConstraints[$k]->setLocalTable($this);
|
||||
}
|
||||
}
|
||||
}
|
141
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/TableDiff.php
vendored
Normal file
141
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/TableDiff.php
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Table Diff.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class TableDiff
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name = null;
|
||||
|
||||
/**
|
||||
* @var string|boolean
|
||||
*/
|
||||
public $newName = false;
|
||||
|
||||
/**
|
||||
* All added fields.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Column[]
|
||||
*/
|
||||
public $addedColumns;
|
||||
|
||||
/**
|
||||
* All changed fields.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Column[]
|
||||
*/
|
||||
public $changedColumns = array();
|
||||
|
||||
/**
|
||||
* All removed fields.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Column[]
|
||||
*/
|
||||
public $removedColumns = array();
|
||||
|
||||
/**
|
||||
* Columns that are only renamed from key to column instance name.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Column[]
|
||||
*/
|
||||
public $renamedColumns = array();
|
||||
|
||||
/**
|
||||
* All added indexes.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Index[]
|
||||
*/
|
||||
public $addedIndexes = array();
|
||||
|
||||
/**
|
||||
* All changed indexes.
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Index[]
|
||||
*/
|
||||
public $changedIndexes = array();
|
||||
|
||||
/**
|
||||
* All removed indexes
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\Index[]
|
||||
*/
|
||||
public $removedIndexes = array();
|
||||
|
||||
/**
|
||||
* All added foreign key definitions
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
|
||||
*/
|
||||
public $addedForeignKeys = array();
|
||||
|
||||
/**
|
||||
* All changed foreign keys
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
|
||||
*/
|
||||
public $changedForeignKeys = array();
|
||||
|
||||
/**
|
||||
* All removed foreign keys
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
|
||||
*/
|
||||
public $removedForeignKeys = array();
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\Table
|
||||
*/
|
||||
public $fromTable;
|
||||
|
||||
/**
|
||||
* Constructs an TableDiff object.
|
||||
*
|
||||
* @param string $tableName
|
||||
* @param \Doctrine\DBAL\Schema\Column[] $addedColumns
|
||||
* @param \Doctrine\DBAL\Schema\Column[] $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
|
||||
*/
|
||||
public function __construct($tableName, $addedColumns = array(),
|
||||
$changedColumns = array(), $removedColumns = array(), $addedIndexes = array(),
|
||||
$changedIndexes = array(), $removedIndexes = array(), Table $fromTable = null)
|
||||
{
|
||||
$this->name = $tableName;
|
||||
$this->addedColumns = $addedColumns;
|
||||
$this->changedColumns = $changedColumns;
|
||||
$this->removedColumns = $removedColumns;
|
||||
$this->addedIndexes = $addedIndexes;
|
||||
$this->changedIndexes = $changedIndexes;
|
||||
$this->removedIndexes = $removedIndexes;
|
||||
$this->fromTable = $fromTable;
|
||||
}
|
||||
}
|
53
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/View.php
vendored
Normal file
53
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/View.php
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $sql
|
||||
*/
|
||||
public function __construct($name, $sql)
|
||||
{
|
||||
$this->_setName($name);
|
||||
$this->_sql = $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSql()
|
||||
{
|
||||
return $this->_sql;
|
||||
}
|
||||
}
|
79
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php
vendored
Normal file
79
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
<?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\Schema;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\Index;
|
||||
|
||||
/**
|
||||
* Abstract Visitor with empty methods for easy extension.
|
||||
*/
|
||||
class AbstractVisitor implements Visitor
|
||||
{
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Schema $schema
|
||||
*/
|
||||
public function acceptSchema(Schema $schema)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
}
|
||||
}
|
159
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php
vendored
Normal file
159
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
<?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;
|
||||
|
||||
class CreateSchemaSqlCollector extends AbstractVisitor
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $createTableQueries = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $createSequenceQueries = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $createFkConstraintQueries = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
|
||||
*/
|
||||
private $platform = null;
|
||||
|
||||
/**
|
||||
* @param AbstractPlatform $platform
|
||||
*/
|
||||
public function __construct(AbstractPlatform $platform)
|
||||
{
|
||||
$this->platform = $platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function acceptTable(Table $table)
|
||||
{
|
||||
$namespace = $this->getNamespace($table);
|
||||
|
||||
$this->createTableQueries[$namespace] = array_merge(
|
||||
$this->createTableQueries[$namespace],
|
||||
$this->platform->getCreateTableSQL($table)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
|
||||
{
|
||||
$namespace = $this->getNamespace($localTable);
|
||||
|
||||
if ($this->platform->supportsForeignKeyConstraints()) {
|
||||
$this->createFkConstraintQueries[$namespace] = array_merge(
|
||||
$this->createFkConstraintQueries[$namespace],
|
||||
(array) $this->platform->getCreateForeignKeySQL(
|
||||
$fkConstraint, $localTable
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function acceptSequence(Sequence $sequence)
|
||||
{
|
||||
$namespace = $this->getNamespace($sequence);
|
||||
|
||||
$this->createSequenceQueries[$namespace] = array_merge(
|
||||
$this->createSequenceQueries[$namespace],
|
||||
(array)$this->platform->getCreateSequenceSQL($sequence)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\AbstractAsset $asset
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getNamespace($asset)
|
||||
{
|
||||
$namespace = $asset->getNamespaceName() ?: 'default';
|
||||
|
||||
if ( !isset($this->createTableQueries[$namespace])) {
|
||||
$this->createTableQueries[$namespace] = array();
|
||||
$this->createSequenceQueries[$namespace] = array();
|
||||
$this->createFkConstraintQueries[$namespace] = array();
|
||||
}
|
||||
|
||||
return $namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function resetQueries()
|
||||
{
|
||||
$this->createTableQueries = array();
|
||||
$this->createSequenceQueries = array();
|
||||
$this->createFkConstraintQueries = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all queries collected so far.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getQueries()
|
||||
{
|
||||
$sql = array();
|
||||
|
||||
foreach (array_keys($this->createTableQueries) as $namespace) {
|
||||
if ($this->platform->supportsSchemas() && $this->platform->schemaNeedsCreation($namespace)) {
|
||||
$query = $this->platform->getCreateSchemaSQL($namespace);
|
||||
array_push($sql, $query);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->createTableQueries as $schemaSql) {
|
||||
$sql = array_merge($sql, $schemaSql);
|
||||
}
|
||||
|
||||
foreach ($this->createSequenceQueries as $schemaSql) {
|
||||
$sql = array_merge($sql, $schemaSql);
|
||||
}
|
||||
|
||||
foreach ($this->createFkConstraintQueries as $schemaSql) {
|
||||
$sql = array_merge($sql, $schemaSql);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
}
|
127
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php
vendored
Normal file
127
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private $constraints;
|
||||
|
||||
/**
|
||||
* @var \SplObjectStorage
|
||||
*/
|
||||
private $sequences;
|
||||
|
||||
/**
|
||||
* @var \SplObjectStorage
|
||||
*/
|
||||
private $tables;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
|
||||
*/
|
||||
private $platform;
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
|
||||
*/
|
||||
public function __construct(AbstractPlatform $platform)
|
||||
{
|
||||
$this->platform = $platform;
|
||||
$this->clearQueries();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function acceptTable(Table $table)
|
||||
{
|
||||
$this->tables->attach($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
|
||||
{
|
||||
if (strlen($fkConstraint->getName()) == 0) {
|
||||
throw SchemaException::namedForeignKeyRequired($localTable, $fkConstraint);
|
||||
}
|
||||
|
||||
$this->constraints->attach($fkConstraint);
|
||||
$this->constraints[$fkConstraint] = $localTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function acceptSequence(Sequence $sequence)
|
||||
{
|
||||
$this->sequences->attach($sequence);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function clearQueries()
|
||||
{
|
||||
$this->constraints = new \SplObjectStorage();
|
||||
$this->sequences = new \SplObjectStorage();
|
||||
$this->tables = new \SplObjectStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getQueries()
|
||||
{
|
||||
$sql = array();
|
||||
|
||||
foreach ($this->constraints as $fkConstraint) {
|
||||
$localTable = $this->constraints[$fkConstraint];
|
||||
$sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable);
|
||||
}
|
||||
|
||||
foreach ($this->sequences as $sequence) {
|
||||
$sql[] = $this->platform->getDropSequenceSQL($sequence);
|
||||
}
|
||||
|
||||
foreach ($this->tables as $table) {
|
||||
$sql[] = $this->platform->getDropTableSQL($table);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
}
|
177
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php
vendored
Normal file
177
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
<?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\Schema;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
|
||||
/**
|
||||
* Create a Graphviz output of a Schema.
|
||||
*/
|
||||
class Graphviz extends AbstractVisitor
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $output = '';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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",
|
||||
array(
|
||||
'dir' => 'back',
|
||||
'arrowtail' => 'dot',
|
||||
'arrowhead' => 'normal',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function acceptSchema(Schema $schema)
|
||||
{
|
||||
$this->output = 'digraph "' . sha1( mt_rand() ) . '" {' . "\n";
|
||||
$this->output .= 'splines = true;' . "\n";
|
||||
$this->output .= 'overlap = false;' . "\n";
|
||||
$this->output .= 'outputorder=edgesfirst;'."\n";
|
||||
$this->output .= 'mindist = 0.6;' . "\n";
|
||||
$this->output .= 'sep = .2;' . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function acceptTable(Table $table)
|
||||
{
|
||||
$this->output .= $this->createNode(
|
||||
$table->getName(),
|
||||
array(
|
||||
'label' => $this->createTableLabel( $table ),
|
||||
'shape' => 'plaintext',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function createTableLabel(Table $table)
|
||||
{
|
||||
// Start the table
|
||||
$label = '<<TABLE CELLSPACING="0" BORDER="1" ALIGN="LEFT">';
|
||||
|
||||
// The title
|
||||
$label .= '<TR><TD BORDER="1" COLSPAN="3" ALIGN="CENTER" BGCOLOR="#fcaf3e"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="12">' . $table->getName() . '</FONT></TD></TR>';
|
||||
|
||||
// The attributes block
|
||||
foreach( $table->getColumns() as $column ) {
|
||||
$columnLabel = $column->getName();
|
||||
|
||||
$label .= '<TR>';
|
||||
$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().'">';
|
||||
if ($table->hasPrimaryKey() && in_array($column->getName(), $table->getPrimaryKey()->getColumns())) {
|
||||
$label .= "\xe2\x9c\xb7";
|
||||
}
|
||||
$label .= '</TD></TR>';
|
||||
}
|
||||
|
||||
// End the table
|
||||
$label .= '</TABLE>>';
|
||||
|
||||
return $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function createNode($name, $options)
|
||||
{
|
||||
$node = $name . " [";
|
||||
foreach( $options as $key => $value )
|
||||
{
|
||||
$node .= $key . '=' . $value . ' ';
|
||||
}
|
||||
$node .= "]\n";
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $node1
|
||||
* @param string $node2
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function createNodeRelation($node1, $node2, $options)
|
||||
{
|
||||
$relation = $node1 . ' -> ' . $node2 . ' [';
|
||||
foreach( $options as $key => $value )
|
||||
{
|
||||
$relation .= $key . '=' . $value . ' ';
|
||||
}
|
||||
$relation .= "]\n";
|
||||
|
||||
return $relation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Graphviz Output
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output . "}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes dot language output to a file. This should usually be a *.dot file.
|
||||
*
|
||||
* You have to convert the output into a viewable format. For example use "neato" on linux systems
|
||||
* and execute:
|
||||
*
|
||||
* neato -Tpng -o er.png er.dot
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function write($filename)
|
||||
{
|
||||
file_put_contents($filename, $this->getOutput());
|
||||
}
|
||||
}
|
95
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php
vendored
Normal file
95
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
<?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\Schema;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
|
||||
/**
|
||||
* Removes assets from a schema that are not in the default namespace.
|
||||
*
|
||||
* Some databases such as MySQL support cross databases joins, but don't
|
||||
* allow to call DDLs to a database from another connected database.
|
||||
* Before a schema is serialized into SQL this visitor can cleanup schemas with
|
||||
* non default namespaces.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
private $schema;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function acceptSchema(Schema $schema)
|
||||
{
|
||||
$this->schema = $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function acceptTable(Table $table)
|
||||
{
|
||||
if ( ! $table->isInDefaultNamespace($this->schema->getName()) ) {
|
||||
$this->schema->dropTable($table->getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function acceptSequence(Sequence $sequence)
|
||||
{
|
||||
if ( ! $sequence->isInDefaultNamespace($this->schema->getName()) ) {
|
||||
$this->schema->dropSequence($sequence->getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
|
||||
{
|
||||
// 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())) {
|
||||
$localTable->removeForeignKey($fkConstraint->getName());
|
||||
return;
|
||||
}
|
||||
|
||||
$foreignTable = $this->schema->getTable($fkConstraint->getForeignTableName());
|
||||
if ( ! $foreignTable->isInDefaultNamespace($this->schema->getName()) ) {
|
||||
$localTable->removeForeignKey($fkConstraint->getName());
|
||||
}
|
||||
}
|
||||
}
|
84
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php
vendored
Normal file
84
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
<?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\TableDiff;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\SchemaException;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Visit a sequence that has changed.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
*/
|
||||
function visitChangedSequence(Sequence $sequence);
|
||||
|
||||
/**
|
||||
* Visit a sequence that has been removed.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
*/
|
||||
function visitRemovedSequence(Sequence $sequence);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||
*/
|
||||
function visitNewSequence(Sequence $sequence);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
*/
|
||||
function visitNewTable(Table $table);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey
|
||||
*/
|
||||
function visitNewTableForeignKey(Table $table, ForeignKeyConstraint $foreignKey);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
*/
|
||||
function visitRemovedTable(Table $table);
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
|
||||
*/
|
||||
function visitChangedTable(TableDiff $tableDiff);
|
||||
}
|
83
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php
vendored
Normal file
83
vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
<?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\Schema;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\Index;
|
||||
|
||||
/**
|
||||
* 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