summaryrefslogtreecommitdiffstats
path: root/schema/mysql-migrations/upgrade_174.sql
blob: 653cb423755290e7bce34f58515c51d850369242 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
ALTER TABLE icinga_zone ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND()   * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_zone SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_zone MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


ALTER TABLE icinga_timeperiod ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND()   * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_timeperiod SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_timeperiod MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


ALTER TABLE icinga_command ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND()   * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_command SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_command MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


ALTER TABLE icinga_apiuser ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND()   * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_apiuser SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_apiuser MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


ALTER TABLE icinga_endpoint ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND()   * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_endpoint SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_endpoint MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


ALTER TABLE icinga_host ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_host SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_host MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


ALTER TABLE icinga_service ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND()   * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_service SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_service MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


ALTER TABLE icinga_hostgroup ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND()   * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_hostgroup SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_hostgroup MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


ALTER TABLE icinga_servicegroup ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND()   * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_servicegroup SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_servicegroup MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


ALTER TABLE icinga_user ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND()   * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_user SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_user MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


ALTER TABLE icinga_usergroup ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND()   * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_usergroup SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_usergroup MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


ALTER TABLE icinga_notification ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND()   * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_notification SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_notification MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


ALTER TABLE icinga_dependency ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND()   * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_dependency SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_dependency MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


ALTER TABLE icinga_scheduled_downtime ADD COLUMN uuid VARBINARY(16) DEFAULT NULL AFTER id;
SET @tmp_uuid = LOWER(CONCAT(
     LPAD(HEX(FLOOR(RAND()   * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'), '-',
     '4',
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     HEX(FLOOR(RAND() * 4 + 8)),
     LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'), '-',
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0'),
     LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0')
));
UPDATE icinga_scheduled_downtime SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL;
ALTER TABLE icinga_scheduled_downtime MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid);


INSERT INTO director_schema_migration
  (schema_version, migration_time)
  VALUES (174, NOW());