Unverified Commit 1222b43b authored by Curtis Conard's avatar Curtis Conard Committed by GitHub
Browse files

Support larger impact graphs (#9154)



* Support larger impact graphs

* Handle mediumtext alteration during utf8mb4 migration

* Put back previous case to fix tests
Co-authored-by: default avatarCédric Anne <cedric.anne@gmail.com>
parent 35889fa3
...@@ -24,6 +24,7 @@ The present file will list all changes made to the project; according to the ...@@ -24,6 +24,7 @@ The present file will list all changes made to the project; according to the
#### Changes #### Changes
- Format of `Message-Id` header sent in Tickets notifications changed to match format used by other items. - Format of `Message-Id` header sent in Tickets notifications changed to match format used by other items.
- Added `DB::truncate()` to replace raw SQL queries - Added `DB::truncate()` to replace raw SQL queries
- Impact context `positions` field type changed from `TEXT` to `MEDIUMTEXT`
#### Deprecated #### Deprecated
- Usage of `GLPI_FORCE_EMPTY_SQL_MODE` constant - Usage of `GLPI_FORCE_EMPTY_SQL_MODE` constant
......
...@@ -315,25 +315,20 @@ class Migration { ...@@ -315,25 +315,20 @@ class Migration {
break; break;
case 'text' : case 'text' :
$format = "TEXT COLLATE $collate"; case 'mediumtext' :
if (!$nodefault) {
if (is_null($default_value)) {
$format.= " DEFAULT NULL";
} else {
$format.= " NOT NULL DEFAULT '$default_value'";
}
}
break;
case 'longtext' : case 'longtext' :
$format = "LONGTEXT COLLATE $collate"; $format = sprintf('%s COLLATE %s', strtoupper($type), $collate);
if (!$nodefault) { if (!$nodefault) {
if (is_null($default_value)) { if (is_null($default_value)) {
$format .= " DEFAULT NULL"; $format .= " DEFAULT NULL";
} else {
if (empty($default_value)) {
$format .= " NOT NULL";
} else { } else {
$format .= " NOT NULL DEFAULT '$default_value'"; $format .= " NOT NULL DEFAULT '$default_value'";
} }
} }
}
break; break;
// for plugins // for plugins
...@@ -429,7 +424,7 @@ class Migration { ...@@ -429,7 +424,7 @@ class Migration {
* @param string $newfield New name of the field * @param string $newfield New name of the field
* @param string $type Field type, @see Migration::fieldFormat() * @param string $type Field type, @see Migration::fieldFormat()
* @param array $options Options: * @param array $options Options:
* - default_value new field's default value, if a specific default value needs to be used * - value : new field's default value, if a specific default value needs to be used
* - first : add the new field at first column * - first : add the new field at first column
* - after : where adding the new field * - after : where adding the new field
* - null : value could be NULL (default false) * - null : value could be NULL (default false)
......
...@@ -154,8 +154,8 @@ class DatabaseSchemaChecker { ...@@ -154,8 +154,8 @@ class DatabaseSchemaChecker {
$differ = new Differ(); $differ = new Differ();
return $differ->diff( return $differ->diff(
$this->getNomalizedSql($proper_create_table_sql), $proper_create_table_sql,
$this->getNomalizedSql($effective_create_table_sql) $effective_create_table_sql
); );
} }
...@@ -245,8 +245,10 @@ class DatabaseSchemaChecker { ...@@ -245,8 +245,10 @@ class DatabaseSchemaChecker {
if ($this->db->use_utf8mb4) { if ($this->db->use_utf8mb4) {
// Remove default charset / collate // Remove default charset / collate
$column_replacements['/( CHARACTER SET utf8mb4)? COLLATE utf8mb4_unicode_ci/i'] = ''; $column_replacements['/( CHARACTER SET utf8mb4)? COLLATE utf8mb4_unicode_ci/i'] = '';
// text were replaced by mediumtext during utf8mb4 migration // "text" fields were replaced by larger type during utf8mb4 migration.
$column_replacements['/mediumtext/i'] = 'text'; // As is it not really possible to know if checked database has been modified by utf8mb4 migration
// or not, we normalize "mediumtext" and "longtext" fields to "text".
$column_replacements['/(medium|long)text/i'] = 'text';
} else { } else {
// Remove default charset / collate // Remove default charset / collate
$column_replacements['/( CHARACTER SET utf8)? COLLATE utf8_unicode_ci/i'] = ''; $column_replacements['/( CHARACTER SET utf8)? COLLATE utf8_unicode_ci/i'] = '';
......
<?php
/**
* ---------------------------------------------------------------------
* GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2015-2021 Teclib' and contributors.
*
* http://glpi-project.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* GLPI is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GLPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GLPI. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
/**
* @var DB $DB
* @var Migration $migration
*/
/** Impact Relations improvements */
$migration->changeField('glpi_impactcontexts', 'positions', 'positions', 'mediumtext', [
'after' => 'id',
'value' => '',
]);
...@@ -1255,7 +1255,7 @@ CREATE TABLE `glpi_impactitems` ( ...@@ -1255,7 +1255,7 @@ CREATE TABLE `glpi_impactitems` (
DROP TABLE IF EXISTS `glpi_impactcontexts`; DROP TABLE IF EXISTS `glpi_impactcontexts`;
CREATE TABLE `glpi_impactcontexts` ( CREATE TABLE `glpi_impactcontexts` (
`id` int NOT NULL AUTO_INCREMENT, `id` int NOT NULL AUTO_INCREMENT,
`positions` text NOT NULL, `positions` mediumtext NOT NULL,
`zoom` float NOT NULL DEFAULT '0', `zoom` float NOT NULL DEFAULT '0',
`pan_x` float NOT NULL DEFAULT '0', `pan_x` float NOT NULL DEFAULT '0',
`pan_y` float NOT NULL DEFAULT '0', `pan_y` float NOT NULL DEFAULT '0',
......
...@@ -239,12 +239,14 @@ SQL ...@@ -239,12 +239,14 @@ SQL
// - should accept missing default charset/collate on columns if matching utf8mb4; // - should accept missing default charset/collate on columns if matching utf8mb4;
// - should not accept non utf8mb4 charset; // - should not accept non utf8mb4 charset;
// - should accept 'mediumtext' instead of 'text'. // - should accept 'mediumtext' instead of 'text'.
// - should accept 'longtext' instead of 'mediumtext'.
[ [
'proper_sql' => <<<SQL 'proper_sql' => <<<SQL
CREATE TABLE `table` ( CREATE TABLE `table` (
`id` int NOT NULL AUTO_INCREMENT, `id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL, `name` varchar(255) NOT NULL,
`content` text, `content` text,
`description` mediumtext,
`bis` varchar(100), `bis` varchar(100),
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
...@@ -255,6 +257,7 @@ CREATE TABLE `table` ( ...@@ -255,6 +257,7 @@ CREATE TABLE `table` (
`id` int NOT NULL AUTO_INCREMENT, `id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL CHARACTER SET utf8 COLLATE utf8_unicode_ci, `name` varchar(255) NOT NULL CHARACTER SET utf8 COLLATE utf8_unicode_ci,
`content` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci, `content` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`description` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`bis` varchar(100) CHARSET latin1, `bis` varchar(100) CHARSET latin1,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
...@@ -274,6 +277,7 @@ SQL ...@@ -274,6 +277,7 @@ SQL
- `name` varchar(255) NOT NULL, - `name` varchar(255) NOT NULL,
+ `name` varchar(255) NOT NULL CHARACTER SET utf8 COLLATE utf8_unicode_ci, + `name` varchar(255) NOT NULL CHARACTER SET utf8 COLLATE utf8_unicode_ci,
`content` text, `content` text,
`description` text,
- `bis` varchar(100), - `bis` varchar(100),
+ `bis` varchar(100) CHARSET latin1, + `bis` varchar(100) CHARSET latin1,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
...@@ -287,12 +291,14 @@ DIFF ...@@ -287,12 +291,14 @@ DIFF
// - should accept missing default charset/collate on columns if matching utf8; // - should accept missing default charset/collate on columns if matching utf8;
// - should not accept non utf8 charset; // - should not accept non utf8 charset;
// - should not accept 'mediumtext' instead of 'text'. // - should not accept 'mediumtext' instead of 'text'.
// - should not accept 'longtext' instead of 'mediumtext'.
[ [
'proper_sql' => <<<SQL 'proper_sql' => <<<SQL
CREATE TABLE `table` ( CREATE TABLE `table` (
`id` int NOT NULL AUTO_INCREMENT, `id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL, `name` varchar(255) NOT NULL,
`content` text, `content` text,
`description` mediumtext,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
SQL SQL
...@@ -302,6 +308,7 @@ CREATE TABLE `table` ( ...@@ -302,6 +308,7 @@ CREATE TABLE `table` (
`id` int NOT NULL AUTO_INCREMENT, `id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci, `name` varchar(255) NOT NULL CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`content` mediumtext CHARACTER SET utf8 COLLATE utf8_unicode_ci, `content` mediumtext CHARACTER SET utf8 COLLATE utf8_unicode_ci,
`description` longtext CHARACTER SET utf8 COLLATE utf8_unicode_ci,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
SQL SQL
...@@ -319,8 +326,10 @@ SQL ...@@ -319,8 +326,10 @@ SQL
`id` int NOT NULL AUTO_INCREMENT, `id` int NOT NULL AUTO_INCREMENT,
- `name` varchar(255) NOT NULL, - `name` varchar(255) NOT NULL,
- `content` text, - `content` text,
- `description` mediumtext,
+ `name` varchar(255) NOT NULL CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci, + `name` varchar(255) NOT NULL CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
+ `content` mediumtext, + `content` mediumtext,
+ `description` longtext,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) COLLATE=utf8_unicode_ci DEFAULT CHARSET=utf8 ENGINE=InnoDB ) COLLATE=utf8_unicode_ci DEFAULT CHARSET=utf8 ENGINE=InnoDB
......
...@@ -414,6 +414,32 @@ class Migration extends \GLPITestCase { ...@@ -414,6 +414,32 @@ class Migration extends \GLPITestCase {
'format' => 'text', 'format' => 'text',
'options' => ['value' => 'A text'], 'options' => ['value' => 'A text'],
'sql' => "ALTER TABLE `my_table` ADD `my_field` TEXT COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'A text' ", 'sql' => "ALTER TABLE `my_table` ADD `my_field` TEXT COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'A text' ",
], [
'table' => 'my_table',
'field' => 'my_field',
'format' => 'mediumtext',
'options' => [],
'sql' => "ALTER TABLE `my_table` ADD `my_field` MEDIUMTEXT COLLATE utf8_unicode_ci DEFAULT NULL ",
'utf8mb4' => false,
], [
'table' => 'my_table',
'field' => 'my_field',
'format' => 'mediumtext',
'options' => [],
'sql' => "ALTER TABLE `my_table` ADD `my_field` MEDIUMTEXT COLLATE utf8mb4_unicode_ci DEFAULT NULL ",
], [
'table' => 'my_table',
'field' => 'my_field',
'format' => 'mediumtext',
'options' => ['value' => 'A medium text'],
'sql' => "ALTER TABLE `my_table` ADD `my_field` MEDIUMTEXT COLLATE utf8_unicode_ci NOT NULL DEFAULT 'A medium text' ",
'utf8mb4' => false,
], [
'table' => 'my_table',
'field' => 'my_field',
'format' => 'mediumtext',
'options' => ['value' => 'A medium text'],
'sql' => "ALTER TABLE `my_table` ADD `my_field` MEDIUMTEXT COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'A medium text' ",
], [ ], [
'table' => 'my_table', 'table' => 'my_table',
'field' => 'my_field', 'field' => 'my_field',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment