-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmytap-timezone.sql
89 lines (67 loc) · 1.95 KB
/
mytap-timezone.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
-- TIMEZONE
-- ========
USE tap;
DELIMITER //
/****************************************************************************/
-- _has_timezones()
DROP FUNCTION IF EXISTS _has_timezones //
CREATE FUNCTION _has_timezones()
RETURNS BOOLEAN
DETERMINISTIC
BEGIN
DECLARE ret INT;
SELECT count(*) INTO ret
FROM `mysql`.`time_zone_name`;
RETURN IF(ret > 0, 1, 0);
END //
-- has_timezones()
DROP FUNCTION IF EXISTS has_timezones //
CREATE FUNCTION has_timezones(description TEXT)
RETURNS TEXT
DETERMINISTIC
BEGIN
IF description = '' THEN
SET description = concat('Table `mysql`.`time_zone_data` should be populated');
END IF;
RETURN ok(_has_timezones(), description);
END //
-- hasnt_timezones()
DROP FUNCTION IF EXISTS hasnt_timezones //
CREATE FUNCTION hasnt_timezones(description TEXT)
RETURNS TEXT
DETERMINISTIC
BEGIN
IF description = '' THEN
SET description = concat('Table `mysql`.`time_zone_data` should be empty');
END IF;
RETURN ok(NOT _has_timezones(), description);
END //
-- _timezones_updated()
DROP FUNCTION IF EXISTS _timezones_updated //
CREATE FUNCTION _timezones_updated()
RETURNS BOOLEAN
DETERMINISTIC
BEGIN
DECLARE pre DATETIME;
DECLARE post DATETIME;
-- use example from https://dev.mysql.com/doc/refman/5.7/en/time-zone-upgrades.html
SET pre = (SELECT CONVERT_TZ('2007-03-11 2:00:00','US/Eastern','US/Central'));
SET post = (SELECT CONVERT_TZ('2007-03-11 3:00:00','US/Eastern','US/Central'));
RETURN IF(pre = post, 1, 0);
END //
-- timezones_updated()
DROP FUNCTION IF EXISTS timezones_updated //
CREATE FUNCTION timezones_updated(description TEXT)
RETURNS TEXT
DETERMINISTIC
BEGIN
IF description = '' THEN
SET description = concat('Timezones data should be updated for changes');
END IF;
IF NOT _has_timezones() THEN
RETURN CONCAT(ok(FALSE, description), '\n',
diag(CONCAT('Table `mysql`.`time_zone_data` is empty')));
END IF;
RETURN ok(_timezones_updated(), description);
END //
DELIMITER ;