diff --git a/libraries/src/Schema/ChangeItem/MysqlChangeItem.php b/libraries/src/Schema/ChangeItem/MysqlChangeItem.php index 2b171c1340cb0..fa6a6deb52ebd 100644 --- a/libraries/src/Schema/ChangeItem/MysqlChangeItem.php +++ b/libraries/src/Schema/ChangeItem/MysqlChangeItem.php @@ -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 @@ -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; @@ -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 * @@ -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') {