Skip to content

Commit 54a3a41

Browse files
Marek Młynarskirennox
authored andcommitted
BUG#36029331 mysqlsh checkForServerUpgrade doesn't identify old temporal types correctly
This commit fixes old_temporal check to include all affected temporal types in scanning. Temporal types (TIMESTAMP, DATETIME, TIME) after version 5.6.4 ware updated to include fractional parts, but required update of column types using them to new binary format. Version 5.6.24 introduced system variable "show_old_temporals", that enabled to detect types in old old "5.5" format. This option, when enabled, added a string "/* 5.5 binary format */" after a columnt_type in listing from infromation_schema. Old check "old_temporal" was set to only detect the timestamp temporal type, ignoring the rest. This commit fixes it by expanding the select query to search for all instances of old format column type. Change-Id: I7aff6c3767e7b1b111be754f9525d28352d2b333
1 parent 727ef00 commit 54a3a41

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed

modules/util/upgrade_check.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ std::unique_ptr<Sql_upgrade_check> Sql_upgrade_check::get_old_temporal_check() {
323323
std::vector<std::string>{
324324
"SELECT table_schema, table_name,column_name,column_type "
325325
"FROM information_schema.columns WHERE column_type LIKE "
326-
"'timestamp /* 5.5 binary format */';"},
326+
"'%5.5 binary format%';"},
327327
Upgrade_issue::ERROR,
328328
"Following table columns use a deprecated and no longer supported "
329-
"timestamp disk storage format. They must be converted to the new format "
329+
"temporal disk storage format. They must be converted to the new format "
330330
"before upgrading. It can by done by rebuilding the table using 'ALTER "
331331
"TABLE <table_name> FORCE' command",
332332
nullptr, std::forward_list<std::string>{"SET show_old_temporals = ON;"},

res/upgrade_checker/upgrade_checker.msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# Usage of old temporal type
3838

3939
* oldTemporalCheck.description
40-
# Error: Following table columns use a deprecated and no longer supported timestamp disk storage
40+
# Error: Following table columns use a deprecated and no longer supported temporal disk storage
4141
# format. They must be converted to the new format before upgrading. It can by done by rebuilding
4242
# the table using 'ALTER TABLE <table_name> FORCE' command
4343

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Tests handling for upgrade checker detecting old temporal types.
2+
// This test requires to create data on server with version before 5.6.4
3+
// and then upgrade to at least 5.7 to prepare the test data.
4+
5+
// Run with mysqlshrec -f <thisfile>, from the build dir.
6+
7+
var db_user = 'root'
8+
var db_host = 'localhost'
9+
var db_port = 3306
10+
11+
function fix_version(ver) {
12+
var idx = ver.indexOf('-');
13+
return idx < 0 ? ver : ver.substr(0, idx);
14+
}
15+
16+
function compare_version_lt(left_version, right_version) {
17+
var l_ver = left_version.split('.');
18+
var r_ver = right_version.split('.');
19+
20+
l_ver[2] = fix_version(l_ver[2]);
21+
22+
if (Number(l_ver[0]) != Number(r_ver[0]))
23+
return Number(l_ver[0]) < Number(r_ver[0]);
24+
if (Number(l_ver[1]) != Number(r_ver[1]))
25+
return Number(l_ver[1]) < Number(r_ver[1]);
26+
if (Number(l_ver[2]) != Number(r_ver[2]))
27+
return Number(l_ver[2]) < Number(r_ver[2]);
28+
return false;
29+
}
30+
31+
function check_sql_contains(result, column_name, column_type) {
32+
for (var i = 0; result.length; i++) {
33+
if (result[i].getField('column_name') == column_name &&
34+
result[i].getField('column_type') == column_type) {
35+
return true;
36+
}
37+
}
38+
return false;
39+
}
40+
41+
println('Connecting to database');
42+
shell.connect(`${db_user}@${db_host}:${db_port}`);
43+
44+
println('Checking database version...');
45+
var db_ver_result = session.runSql('select version();').fetchOne()
46+
var db_version = db_ver_result[0]
47+
48+
if (compare_version_lt(db_version, "5.6.4")) {
49+
println('Database version below 5.6.4 - correct for upgrade.');
50+
51+
println('Creating test data...');
52+
53+
session.runSql('drop schema if exists old_temporal_test;');
54+
session.runSql('create schema old_temporal_test;');
55+
56+
session.runSql('use old_temporal_test;');
57+
58+
session.runSql('create table old_temporal_table (ts_col TIMESTAMP, dt_col DATETIME, tm_col TIME);');
59+
session.runSql('insert into old_temporal_table VALUES(NOW(), NOW(), NOW());');
60+
61+
println('Test data created.');
62+
63+
println('Database can now be upgraded - preferably to version 5.7.');
64+
println('After upgrade, please run "upgrade_checker_old_temporal.js" again to continue testing.');
65+
}
66+
else {
67+
println('Database version above 5.6.4 - correct for testing.');
68+
69+
println('Runing test, please verify output.');
70+
71+
// EXPECTED OUTPUT:
72+
// Warning (code 1287): '@@show_old_temporals' is deprecated and will be removed in a future release.
73+
session.runSql('set session show_old_temporals=ON');
74+
75+
var db_result = session.runSql('select column_name, column_type from information_schema.columns where table_name=\'old_temporal_table\';');
76+
var results = db_result.fetchAll();
77+
78+
if (check_sql_contains(results, 'ts_col', 'timestamp /* 5.5 binary format */') &&
79+
check_sql_contains(results, 'dt_col', 'datetime /* 5.5 binary format */') &&
80+
check_sql_contains(results, 'tm_col', 'time /* 5.5 binary format */')) {
81+
println('Database verified to contain proper test data.');
82+
}
83+
else {
84+
testutil.fail('Database does not contain test data. Test will fail.');
85+
}
86+
87+
println('Running util.checkForServerUpgrade...');
88+
89+
util.checkForServerUpgrade();
90+
91+
println('Output should contain:');
92+
println('old_temporal_test.old_temporal_table.ts_col - timestamp /* 5.5 binary format */');
93+
println('old_temporal_test.old_temporal_table.dt_col - datetime /* 5.5 binary format */');
94+
println('old_temporal_test.old_temporal_table.tm_col - time /* 5.5 binary format */');
95+
96+
println('Test ended, please verify results.');
97+
}
98+

0 commit comments

Comments
 (0)