Commit d629ab52 authored by Johan Cwiklinski's avatar Johan Cwiklinski Committed by Johan Cwiklinski

Fix usage of INFORMATION_SCHEMA db on MySQL 8

parent e3568eab
......@@ -57,14 +57,17 @@ class BuildMissingTimestampsCommand extends AbstractCommand {
$tables_iterator = $this->db->request(
[
'SELECT' => ['TABLE_NAME', 'COLUMN_NAME'],
'FROM' => 'INFORMATION_SCHEMA.COLUMNS',
'SELECT' => [
'table_name AS TABLE_NAME',
'column_name AS COLUMN_NAME',
],
'FROM' => 'information_schema.columns',
'WHERE' => [
'TABLE_SCHEMA' => $this->db->dbdefault,
'TABLE_NAME' => ['LIKE', 'glpi_%'],
'COLUMN_NAME' => ['date_creation', 'date_mod'],
'table_schema' => $this->db->dbdefault,
'table_name' => ['LIKE', 'glpi_%'],
'column_name' => ['date_creation', 'date_mod'],
],
'ORDER' => ['TABLE_NAME', 'COLUMN_NAME'],
'ORDER' => ['table_name', 'column_name'],
]
);
......
......@@ -48,7 +48,7 @@ class TimestampsCommand extends AbstractCommand {
parent::configure();
$this->setName('glpi:migration:timestamps');
$this->setDescription(__('Convert DATETIME to timestamps to use timezones.'));
$this->setDescription(__('Convert "datetime" fields to "timestamp" to use timezones.'));
}
protected function execute(InputInterface $input, OutputInterface $output) {
......@@ -56,31 +56,31 @@ class TimestampsCommand extends AbstractCommand {
// we are going to update datetime, date and time (?) types to timestamp type
$tbl_iterator = $this->db->request([
'SELECT' => ['INFORMATION_SCHEMA.COLUMNS.TABLE_NAME'],
'SELECT' => ['information_schema.columns.table_name as TABLE_NAME'],
'DISTINCT' => true,
'FROM' => 'INFORMATION_SCHEMA.COLUMNS',
'FROM' => 'information_schema.columns',
'INNER JOIN' => [
'INFORMATION_SCHEMA.TABLES' => [
'information_schema.tables' => [
'ON' => [
'INFORMATION_SCHEMA.TABLES.TABLE_NAME',
'INFORMATION_SCHEMA.COLUMNS.TABLE_NAME', [
'AND' => ['INFORMATION_SCHEMA.TABLES.TABLE_TYPE' => 'BASE TABLE']
'information_schema.tables.table_name',
'information_schema.columns.table_name', [
'AND' => ['information_schema.tables.table_type' => 'BASE TABLE']
]
]
]
],
'WHERE' => [
'INFORMATION_SCHEMA.COLUMNS.TABLE_SCHEMA' => $this->db->dbdefault,
'INFORMATION_SCHEMA.COLUMNS.COLUMN_TYPE' => 'DATETIME'
'information_schema.columns.table_schema' => $this->db->dbdefault,
'information_schema.columns.data_type' => 'datetime'
],
'ORDER' => [
'INFORMATION_SCHEMA.COLUMNS.TABLE_NAME'
'information_schema.columns.table_name'
]
]);
$output->writeln(
sprintf(
'<info>' . __('Found %s table(s) using requiring migration.') . '</info>',
'<info>' . __('Found %s table(s) requiring migration.') . '</info>',
$tbl_iterator->count()
)
);
......@@ -118,11 +118,18 @@ class TimestampsCommand extends AbstractCommand {
// get accurate info from information_schema to perform correct alter
$col_iterator = $this->db->request([
'FROM' => 'INFORMATION_SCHEMA.COLUMNS',
'SELECT' => [
'table_name AS TABLE_NAME',
'column_name AS COLUMN_NAME',
'column_default AS COLUMN_DEFAULT',
'column_comment AS COLUMN_COMMENT',
'is_nullable AS IS_NULLABLE',
],
'FROM' => 'information_schema.columns',
'WHERE' => [
'TABLE_SCHEMA' => $this->db->dbdefault,
'TABLE_NAME' => $table['TABLE_NAME'],
'COLUMN_TYPE' => 'DATETIME'
'table_schema' => $this->db->dbdefault,
'table_name' => $table['TABLE_NAME'],
'data_type' => 'datetime'
]
]);
......
......@@ -537,12 +537,12 @@ class DBmysql {
*/
function listTables($table = 'glpi_%', array $where = []) {
$iterator = $this->request([
'SELECT' => 'TABLE_NAME',
'FROM' => 'information_schema.TABLES',
'SELECT' => 'table_name as TABLE_NAME',
'FROM' => 'information_schema.tables',
'WHERE' => [
'TABLE_SCHEMA' => $this->dbdefault,
'TABLE_TYPE' => 'BASE TABLE',
'TABLE_NAME' => ['LIKE', $table]
'table_schema' => $this->dbdefault,
'table_type' => 'BASE TABLE',
'table_name' => ['LIKE', $table]
] + $where
]);
return $iterator;
......@@ -1510,10 +1510,10 @@ class DBmysql {
$result = $DB->request([
'COUNT' => 'cpt',
'FROM' => 'INFORMATION_SCHEMA.COLUMNS',
'FROM' => 'information_schema.columns',
'WHERE' => [
'INFORMATION_SCHEMA.COLUMNS.TABLE_SCHEMA' => $DB->dbdefault,
'INFORMATION_SCHEMA.COLUMNS.COLUMN_TYPE' => ['DATETIME']
'information_schema.columns.table_schema' => $DB->dbdefault,
'information_schema.columns.column_type' => ['datetime']
]
])->next();
return (int)$result['cpt'];
......
......@@ -188,12 +188,12 @@ class Migration extends \GLPITestCase {
)->isIdenticalTo("Task completed.");
$this->array($this->queries)->isIdenticalTo([
0 => 'SELECT `TABLE_NAME` FROM `information_schema`.`TABLES`' .
' WHERE `TABLE_SCHEMA` = \'' . $DB->dbdefault .
'\' AND `TABLE_TYPE` = \'BASE TABLE\' AND `TABLE_NAME` LIKE \'%table1%\'',
1 => 'SELECT `TABLE_NAME` FROM `information_schema`.`TABLES`' .
' WHERE `TABLE_SCHEMA` = \'' . $DB->dbdefault .
'\' AND `TABLE_TYPE` = \'BASE TABLE\' AND `TABLE_NAME` LIKE \'%table2%\''
0 => 'SELECT `table_name` AS `TABLE_NAME` FROM `information_schema`.`tables`' .
' WHERE `table_schema` = \'' . $DB->dbdefault .
'\' AND `table_type` = \'BASE TABLE\' AND `table_name` LIKE \'%table1%\'',
1 => 'SELECT `table_name` AS `TABLE_NAME` FROM `information_schema`.`tables`' .
' WHERE `table_schema` = \'' . $DB->dbdefault .
'\' AND `table_type` = \'BASE TABLE\' AND `table_name` LIKE \'%table2%\''
]);
//try to backup existant tables
......
Markdown is supported
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