|
@@ -130,7 +130,7 @@ class MysqlSchema extends BaseSchema
|
|
|
}
|
|
}
|
|
|
if (strpos($col, 'text') !== false) {
|
|
if (strpos($col, 'text') !== false) {
|
|
|
$lengthName = substr($col, 0, -4);
|
|
$lengthName = substr($col, 0, -4);
|
|
|
- $length = isset(Table::$columnLengths[$lengthName]) ? Table::$columnLengths[$lengthName] : null;
|
|
|
|
|
|
|
+ $length = isset(TableSchema::$columnLengths[$lengthName]) ? TableSchema::$columnLengths[$lengthName] : null;
|
|
|
|
|
|
|
|
return ['type' => TableSchema::TYPE_TEXT, 'length' => $length];
|
|
return ['type' => TableSchema::TYPE_TEXT, 'length' => $length];
|
|
|
}
|
|
}
|
|
@@ -139,7 +139,7 @@ class MysqlSchema extends BaseSchema
|
|
|
}
|
|
}
|
|
|
if (strpos($col, 'blob') !== false || $col === 'binary') {
|
|
if (strpos($col, 'blob') !== false || $col === 'binary') {
|
|
|
$lengthName = substr($col, 0, -4);
|
|
$lengthName = substr($col, 0, -4);
|
|
|
- $length = isset(Table::$columnLengths[$lengthName]) ? Table::$columnLengths[$lengthName] : null;
|
|
|
|
|
|
|
+ $length = isset(TableSchema::$columnLengths[$lengthName]) ? TableSchema::$columnLengths[$lengthName] : null;
|
|
|
|
|
|
|
|
return ['type' => TableSchema::TYPE_BINARY, 'length' => $length];
|
|
return ['type' => TableSchema::TYPE_BINARY, 'length' => $length];
|
|
|
}
|
|
}
|
|
@@ -195,25 +195,25 @@ class MysqlSchema extends BaseSchema
|
|
|
|
|
|
|
|
$name = $row['Key_name'];
|
|
$name = $row['Key_name'];
|
|
|
if ($name === 'PRIMARY') {
|
|
if ($name === 'PRIMARY') {
|
|
|
- $name = $type = Table::CONSTRAINT_PRIMARY;
|
|
|
|
|
|
|
+ $name = $type = TableSchema::CONSTRAINT_PRIMARY;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$columns[] = $row['Column_name'];
|
|
$columns[] = $row['Column_name'];
|
|
|
|
|
|
|
|
if ($row['Index_type'] === 'FULLTEXT') {
|
|
if ($row['Index_type'] === 'FULLTEXT') {
|
|
|
- $type = Table::INDEX_FULLTEXT;
|
|
|
|
|
|
|
+ $type = TableSchema::INDEX_FULLTEXT;
|
|
|
} elseif ($row['Non_unique'] == 0 && $type !== 'primary') {
|
|
} elseif ($row['Non_unique'] == 0 && $type !== 'primary') {
|
|
|
- $type = Table::CONSTRAINT_UNIQUE;
|
|
|
|
|
|
|
+ $type = TableSchema::CONSTRAINT_UNIQUE;
|
|
|
} elseif ($type !== 'primary') {
|
|
} elseif ($type !== 'primary') {
|
|
|
- $type = Table::INDEX_INDEX;
|
|
|
|
|
|
|
+ $type = TableSchema::INDEX_INDEX;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!empty($row['Sub_part'])) {
|
|
if (!empty($row['Sub_part'])) {
|
|
|
$length[$row['Column_name']] = $row['Sub_part'];
|
|
$length[$row['Column_name']] = $row['Sub_part'];
|
|
|
}
|
|
}
|
|
|
$isIndex = (
|
|
$isIndex = (
|
|
|
- $type === Table::INDEX_INDEX ||
|
|
|
|
|
- $type === Table::INDEX_FULLTEXT
|
|
|
|
|
|
|
+ $type === TableSchema::INDEX_INDEX ||
|
|
|
|
|
+ $type === TableSchema::INDEX_FULLTEXT
|
|
|
);
|
|
);
|
|
|
if ($isIndex) {
|
|
if ($isIndex) {
|
|
|
$existing = $schema->getIndex($name);
|
|
$existing = $schema->getIndex($name);
|
|
@@ -263,7 +263,7 @@ class MysqlSchema extends BaseSchema
|
|
|
public function convertForeignKeyDescription(TableSchema $schema, $row)
|
|
public function convertForeignKeyDescription(TableSchema $schema, $row)
|
|
|
{
|
|
{
|
|
|
$data = [
|
|
$data = [
|
|
|
- 'type' => Table::CONSTRAINT_FOREIGN,
|
|
|
|
|
|
|
+ 'type' => TableSchema::CONSTRAINT_FOREIGN,
|
|
|
'columns' => [$row['COLUMN_NAME']],
|
|
'columns' => [$row['COLUMN_NAME']],
|
|
|
'references' => [$row['REFERENCED_TABLE_NAME'], $row['REFERENCED_COLUMN_NAME']],
|
|
'references' => [$row['REFERENCED_TABLE_NAME'], $row['REFERENCED_COLUMN_NAME']],
|
|
|
'update' => $this->_convertOnClause($row['UPDATE_RULE']),
|
|
'update' => $this->_convertOnClause($row['UPDATE_RULE']),
|
|
@@ -345,27 +345,27 @@ class MysqlSchema extends BaseSchema
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case TableSchema::TYPE_TEXT:
|
|
case TableSchema::TYPE_TEXT:
|
|
|
- $isKnownLength = in_array($data['length'], Table::$columnLengths);
|
|
|
|
|
|
|
+ $isKnownLength = in_array($data['length'], TableSchema::$columnLengths);
|
|
|
if (empty($data['length']) || !$isKnownLength) {
|
|
if (empty($data['length']) || !$isKnownLength) {
|
|
|
$out .= ' TEXT';
|
|
$out .= ' TEXT';
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if ($isKnownLength) {
|
|
if ($isKnownLength) {
|
|
|
- $length = array_search($data['length'], Table::$columnLengths);
|
|
|
|
|
|
|
+ $length = array_search($data['length'], TableSchema::$columnLengths);
|
|
|
$out .= ' ' . strtoupper($length) . 'TEXT';
|
|
$out .= ' ' . strtoupper($length) . 'TEXT';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
|
case TableSchema::TYPE_BINARY:
|
|
case TableSchema::TYPE_BINARY:
|
|
|
- $isKnownLength = in_array($data['length'], Table::$columnLengths);
|
|
|
|
|
|
|
+ $isKnownLength = in_array($data['length'], TableSchema::$columnLengths);
|
|
|
if (empty($data['length']) || !$isKnownLength) {
|
|
if (empty($data['length']) || !$isKnownLength) {
|
|
|
$out .= ' BLOB';
|
|
$out .= ' BLOB';
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if ($isKnownLength) {
|
|
if ($isKnownLength) {
|
|
|
- $length = array_search($data['length'], Table::$columnLengths);
|
|
|
|
|
|
|
+ $length = array_search($data['length'], TableSchema::$columnLengths);
|
|
|
$out .= ' ' . strtoupper($length) . 'BLOB';
|
|
$out .= ' ' . strtoupper($length) . 'BLOB';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -452,7 +452,7 @@ class MysqlSchema extends BaseSchema
|
|
|
public function constraintSql(TableSchema $schema, $name)
|
|
public function constraintSql(TableSchema $schema, $name)
|
|
|
{
|
|
{
|
|
|
$data = $schema->getConstraint($name);
|
|
$data = $schema->getConstraint($name);
|
|
|
- if ($data['type'] === Table::CONSTRAINT_PRIMARY) {
|
|
|
|
|
|
|
+ if ($data['type'] === TableSchema::CONSTRAINT_PRIMARY) {
|
|
|
$columns = array_map(
|
|
$columns = array_map(
|
|
|
[$this->_driver, 'quoteIdentifier'],
|
|
[$this->_driver, 'quoteIdentifier'],
|
|
|
$data['columns']
|
|
$data['columns']
|
|
@@ -462,10 +462,10 @@ class MysqlSchema extends BaseSchema
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$out = '';
|
|
$out = '';
|
|
|
- if ($data['type'] === Table::CONSTRAINT_UNIQUE) {
|
|
|
|
|
|
|
+ if ($data['type'] === TableSchema::CONSTRAINT_UNIQUE) {
|
|
|
$out = 'UNIQUE KEY ';
|
|
$out = 'UNIQUE KEY ';
|
|
|
}
|
|
}
|
|
|
- if ($data['type'] === Table::CONSTRAINT_FOREIGN) {
|
|
|
|
|
|
|
+ if ($data['type'] === TableSchema::CONSTRAINT_FOREIGN) {
|
|
|
$out = 'CONSTRAINT ';
|
|
$out = 'CONSTRAINT ';
|
|
|
}
|
|
}
|
|
|
$out .= $this->_driver->quoteIdentifier($name);
|
|
$out .= $this->_driver->quoteIdentifier($name);
|
|
@@ -483,7 +483,7 @@ class MysqlSchema extends BaseSchema
|
|
|
|
|
|
|
|
foreach ($schema->constraints() as $name) {
|
|
foreach ($schema->constraints() as $name) {
|
|
|
$constraint = $schema->getConstraint($name);
|
|
$constraint = $schema->getConstraint($name);
|
|
|
- if ($constraint['type'] === Table::CONSTRAINT_FOREIGN) {
|
|
|
|
|
|
|
+ if ($constraint['type'] === TableSchema::CONSTRAINT_FOREIGN) {
|
|
|
$tableName = $this->_driver->quoteIdentifier($schema->name());
|
|
$tableName = $this->_driver->quoteIdentifier($schema->name());
|
|
|
$sql[] = sprintf($sqlPattern, $tableName, $this->constraintSql($schema, $name));
|
|
$sql[] = sprintf($sqlPattern, $tableName, $this->constraintSql($schema, $name));
|
|
|
}
|
|
}
|
|
@@ -502,7 +502,7 @@ class MysqlSchema extends BaseSchema
|
|
|
|
|
|
|
|
foreach ($schema->constraints() as $name) {
|
|
foreach ($schema->constraints() as $name) {
|
|
|
$constraint = $schema->getConstraint($name);
|
|
$constraint = $schema->getConstraint($name);
|
|
|
- if ($constraint['type'] === Table::CONSTRAINT_FOREIGN) {
|
|
|
|
|
|
|
+ if ($constraint['type'] === TableSchema::CONSTRAINT_FOREIGN) {
|
|
|
$tableName = $this->_driver->quoteIdentifier($schema->name());
|
|
$tableName = $this->_driver->quoteIdentifier($schema->name());
|
|
|
$constraintName = $this->_driver->quoteIdentifier($name);
|
|
$constraintName = $this->_driver->quoteIdentifier($name);
|
|
|
$sql[] = sprintf($sqlPattern, $tableName, $constraintName);
|
|
$sql[] = sprintf($sqlPattern, $tableName, $constraintName);
|
|
@@ -519,10 +519,10 @@ class MysqlSchema extends BaseSchema
|
|
|
{
|
|
{
|
|
|
$data = $schema->getIndex($name);
|
|
$data = $schema->getIndex($name);
|
|
|
$out = '';
|
|
$out = '';
|
|
|
- if ($data['type'] === Table::INDEX_INDEX) {
|
|
|
|
|
|
|
+ if ($data['type'] === TableSchema::INDEX_INDEX) {
|
|
|
$out = 'KEY ';
|
|
$out = 'KEY ';
|
|
|
}
|
|
}
|
|
|
- if ($data['type'] === Table::INDEX_FULLTEXT) {
|
|
|
|
|
|
|
+ if ($data['type'] === TableSchema::INDEX_FULLTEXT) {
|
|
|
$out = 'FULLTEXT KEY ';
|
|
$out = 'FULLTEXT KEY ';
|
|
|
}
|
|
}
|
|
|
$out .= $this->_driver->quoteIdentifier($name);
|
|
$out .= $this->_driver->quoteIdentifier($name);
|
|
@@ -548,7 +548,7 @@ class MysqlSchema extends BaseSchema
|
|
|
$columns[$i] .= sprintf('(%d)', $data['length'][$column]);
|
|
$columns[$i] .= sprintf('(%d)', $data['length'][$column]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if ($data['type'] === Table::CONSTRAINT_FOREIGN) {
|
|
|
|
|
|
|
+ if ($data['type'] === TableSchema::CONSTRAINT_FOREIGN) {
|
|
|
return $prefix . sprintf(
|
|
return $prefix . sprintf(
|
|
|
' FOREIGN KEY (%s) REFERENCES %s (%s) ON UPDATE %s ON DELETE %s',
|
|
' FOREIGN KEY (%s) REFERENCES %s (%s) ON UPDATE %s ON DELETE %s',
|
|
|
implode(', ', $columns),
|
|
implode(', ', $columns),
|