Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions libraries/src/Schema/ChangeItem/MysqlChangeItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ protected function buildCheckQuery()

/**
* Fix up integer. Fixes problem with MySQL integer descriptions.
* If you change a column to "integer unsigned" it shows
* as "int(10) unsigned" in the check query.
* On MySQL 8 display length is not shown anymore.
* This means we have to match e.g. both "int(10) unsigned" and
* "int unsigned", or both "int(11)" and "int" and so on.
* The same applies to tinyint.
*
* @param string $type1 the column type
* @param string $type2 the column attributes
Expand All @@ -246,13 +248,28 @@ private function fixInteger($type1, $type2)
{
$result = $type1;

if (strtolower($type1) === 'integer' && strtolower(substr($type2, 0, 8)) === 'unsigned')
if (strtolower(substr($type2, 0, 8)) === 'unsigned')
{
$result = 'int(10) unsigned';
if (strtolower(substr($type1, 0, 7)) === 'tinyint')
{
$result = 'tinyint unsigned';
}
elseif (strtolower(substr($type1, 0, 3)) === 'int')
{
$result = 'int unsigned';
}
else
{
$result = $type1 . ' unsigned';
}
}
elseif (strtolower(substr($type1, 0, 7)) === 'tinyint')
{
$result = 'tinyint';
}
elseif (strtolower(substr($type2, 0, 8)) === 'unsigned')
elseif (strtolower(substr($type1, 0, 3)) === 'int')
{
$result = $type1 . ' unsigned';
$result = 'int';
}

return $result;
Expand Down Expand Up @@ -281,7 +298,9 @@ private function fixQuote($string)
/**
* Make check query for column changes/modifications tolerant
* for automatic type changes of text columns, e.g. from TEXT
* to MEDIUMTEXT, after comnversion from utf8 to utf8mb4
* to MEDIUMTEXT, after comnversion from utf8 to utf8mb4, and
* fix integer (int or tinyint) columns without display length
* for MySQL 8.
*
* @param string $type The column type found in the update query
*
Expand All @@ -293,7 +312,25 @@ private function fixUtf8mb4TypeChecks($type)
{
$uType = strtoupper(str_replace(';', '', $type));

if ($this->db->hasUTF8mb4Support())
if ($uType === 'TINYINT UNSIGNED')
{
$typeCheck = 'UPPER(LEFT(type, 7)) = ' . $this->db->quote('TINYINT')
. ' AND UPPER(RIGHT(type, 9)) = ' . $this->db->quote(' UNSIGNED');
}
elseif ($uType === 'TINYINT')
{
$typeCheck = 'UPPER(LEFT(type, 7)) = ' . $this->db->quote('TINYINT');
}
elseif ($uType === 'INT UNSIGNED')
{
$typeCheck = 'UPPER(LEFT(type, 3)) = ' . $this->db->quote('INT')
. ' AND UPPER(RIGHT(type, 9)) = ' . $this->db->quote(' UNSIGNED');
}
elseif ($uType === 'INT')
{
$typeCheck = 'UPPER(LEFT(type, 3)) = ' . $this->db->quote('INT');
}
elseif ($this->db->hasUTF8mb4Support())
{
if ($uType === 'TINYTEXT')
{
Expand Down