From a56cfc2f50e1cf6bd39dc9b4fd96d317451fb1cd Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 28 Mar 2020 23:00:41 +0100 Subject: [PATCH 1/3] Ignore display width of integer columns in mysql schema change item --- .../src/Schema/ChangeItem/MysqlChangeItem.php | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/libraries/src/Schema/ChangeItem/MysqlChangeItem.php b/libraries/src/Schema/ChangeItem/MysqlChangeItem.php index 2b171c1340cb0..7f77635d2356e 100644 --- a/libraries/src/Schema/ChangeItem/MysqlChangeItem.php +++ b/libraries/src/Schema/ChangeItem/MysqlChangeItem.php @@ -232,8 +232,9 @@ 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. * * @param string $type1 the column type * @param string $type2 the column attributes @@ -246,13 +247,20 @@ 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, 3)) === 'int') + { + $result = 'int unsigned'; + } + else + { + $result = $type1 . ' unsigned'; + } } - elseif (strtolower(substr($type2, 0, 8)) === 'unsigned') + elseif (strtolower(substr($type1, 0, 3)) === 'int') { - $result = $type1 . ' unsigned'; + $result = 'int'; } return $result; @@ -281,7 +289,8 @@ 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 columns without display length for MySQL 8. * * @param string $type The column type found in the update query * @@ -293,7 +302,16 @@ private function fixUtf8mb4TypeChecks($type) { $uType = strtoupper(str_replace(';', '', $type)); - if ($this->db->hasUTF8mb4Support()) + if ($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') { From a647117f0c788736957a7de47cf12ae99fa664f8 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 28 Mar 2020 23:20:21 +0100 Subject: [PATCH 2/3] Fix tinyint, too. --- .../src/Schema/ChangeItem/MysqlChangeItem.php | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/libraries/src/Schema/ChangeItem/MysqlChangeItem.php b/libraries/src/Schema/ChangeItem/MysqlChangeItem.php index 7f77635d2356e..ad841f7fec635 100644 --- a/libraries/src/Schema/ChangeItem/MysqlChangeItem.php +++ b/libraries/src/Schema/ChangeItem/MysqlChangeItem.php @@ -235,6 +235,7 @@ protected function buildCheckQuery() * 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 @@ -249,7 +250,11 @@ private function fixInteger($type1, $type2) if (strtolower(substr($type2, 0, 8)) === 'unsigned') { - if (strtolower(substr($type1, 0, 3)) === 'int') + if (strtolower(substr($type1, 0, 7)) === 'tinyint') + { + $result = 'tinyint unsigned'; + } + elseif (strtolower(substr($type1, 0, 3)) === 'int') { $result = 'int unsigned'; } @@ -258,6 +263,9 @@ private function fixInteger($type1, $type2) $result = $type1 . ' unsigned'; } } + elseif (strtolower(substr($type1, 0, 7)) === 'tinyint') + { + $result = 'tinyint'; elseif (strtolower(substr($type1, 0, 3)) === 'int') { $result = 'int'; @@ -290,7 +298,8 @@ 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, and - * fix integer columns without display length for MySQL 8. + * fix integer (int or tinyint) columns without display length + * for MySQL 8. * * @param string $type The column type found in the update query * @@ -302,7 +311,16 @@ private function fixUtf8mb4TypeChecks($type) { $uType = strtoupper(str_replace(';', '', $type)); - if ($uType === 'INT UNSIGNED') + 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'); From 19f3009bbfa3c1ce435718652093a64cec69cbe3 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 28 Mar 2020 23:23:20 +0100 Subject: [PATCH 3/3] Fix typo --- libraries/src/Schema/ChangeItem/MysqlChangeItem.php | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/src/Schema/ChangeItem/MysqlChangeItem.php b/libraries/src/Schema/ChangeItem/MysqlChangeItem.php index ad841f7fec635..fa6a6deb52ebd 100644 --- a/libraries/src/Schema/ChangeItem/MysqlChangeItem.php +++ b/libraries/src/Schema/ChangeItem/MysqlChangeItem.php @@ -266,6 +266,7 @@ private function fixInteger($type1, $type2) elseif (strtolower(substr($type1, 0, 7)) === 'tinyint') { $result = 'tinyint'; + } elseif (strtolower(substr($type1, 0, 3)) === 'int') { $result = 'int';