From 8bc714a2b1ad6c3477d3245eca8875bef1d7098b Mon Sep 17 00:00:00 2001 From: Alexei Sorokin Date: Mon, 10 Aug 2020 10:55:59 +0300 Subject: [PATCH] [DATABASE][MariaDB] Always use LONGBLOB for "blob" "blob" is practically used with the expectation of unlimited length, which is true with PostgreSQL's bytea, but not with MariaDB's BLOB, which is limited to 64KiB. So instead use LONGBLOB, which has a maximum of 4GiB, effectively unlimited. --- lib/database/mysqlschema.php | 31 +++++++++++++++++++------------ lib/database/pgsqlschema.php | 25 ++++++++++++++----------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/lib/database/mysqlschema.php b/lib/database/mysqlschema.php index a35f474f6f..ae1a1ce57a 100644 --- a/lib/database/mysqlschema.php +++ b/lib/database/mysqlschema.php @@ -517,24 +517,31 @@ class MysqlSchema extends Schema $map = [ 'integer' => 'int', 'numeric' => 'decimal', + 'blob' => 'longblob', ]; $type = $column['type']; - if (isset($map[$type])) { + if (array_key_exists($type, $map)) { $type = $map[$type]; } - if (!empty($column['size'])) { - $size = $column['size']; - if ($type == 'int' && - in_array($size, ['tiny', 'small', 'medium', 'big'])) { - $type = $size . $type; - } elseif ($type == 'float' && $size == 'big') { - $type = 'double'; - } elseif (in_array($type, ['blob', 'text']) && - in_array($size, ['tiny', 'medium', 'long'])) { - $type = $size . $type; - } + $size = $column['size'] ?? null; + switch ($type) { + case 'int': + if (in_array($size, ['tiny', 'small', 'medium', 'big'])) { + $type = $size . $type; + } + break; + case 'float': + if ($size === 'big') { + $type = 'double'; + } + break; + case 'text': + if (in_array($size, ['tiny', 'medium', 'long'])) { + $type = $size . $type; + } + break; } return $type; diff --git a/lib/database/pgsqlschema.php b/lib/database/pgsqlschema.php index 56d4cfc4e8..ceb966b381 100644 --- a/lib/database/pgsqlschema.php +++ b/lib/database/pgsqlschema.php @@ -419,21 +419,24 @@ class PgsqlSchema extends Schema ]; $type = $column['type']; - if (isset($map[$type])) { + if (array_key_exists($type, $map)) { $type = $map[$type]; } $size = $column['size'] ?? null; - if ($type === 'int') { - if (in_array($size, ['tiny', 'small'])) { - $type = 'int2'; - } elseif ($size === 'big') { - $type = 'int8'; - } else { - $type = 'int4'; - } - } elseif ($type === 'float') { - $type = ($size !== 'big') ? 'float4' : 'float8'; + switch ($type) { + case 'int': + if (in_array($size, ['tiny', 'small'])) { + $type = 'int2'; + } elseif ($size === 'big') { + $type = 'int8'; + } else { + $type = 'int4'; + } + break; + case 'float': + $type = ($size !== 'big') ? 'float4' : 'float8'; + break; } return $type;