Skip to content

Commit a7144ff

Browse files
authored
Merge pull request #885 from Icinga/icingadb-migrate-sql-explicit-as-i884
icingadb-migrate: Explicit AS in SELECT
2 parents 15d4ac4 + f94a65f commit a7144ff

File tree

5 files changed

+72
-23
lines changed

5 files changed

+72
-23
lines changed

cmd/icingadb-migrate/embed/comment_query.sql

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
SELECT ch.commenthistory_id, UNIX_TIMESTAMP(ch.entry_time) entry_time,
2-
ch.entry_time_usec, ch.entry_type, ch.author_name, ch.comment_data, ch.is_persistent,
3-
COALESCE(UNIX_TIMESTAMP(ch.expiration_time), 0) expiration_time,
4-
COALESCE(UNIX_TIMESTAMP(ch.deletion_time), 0) deletion_time,
1+
SELECT
2+
ch.commenthistory_id,
3+
UNIX_TIMESTAMP(ch.entry_time) AS entry_time,
4+
ch.entry_time_usec,
5+
ch.entry_type,
6+
ch.author_name,
7+
ch.comment_data,
8+
ch.is_persistent,
9+
COALESCE(UNIX_TIMESTAMP(ch.expiration_time), 0) AS expiration_time,
10+
COALESCE(UNIX_TIMESTAMP(ch.deletion_time), 0) AS deletion_time,
511
ch.deletion_time_usec,
6-
COALESCE(ch.name, CONCAT(o.name1, '!', COALESCE(o.name2, ''), '!', ch.commenthistory_id, '-', ch.object_id)) name,
7-
o.objecttype_id, o.name1, COALESCE(o.name2, '') name2
12+
COALESCE(ch.name, CONCAT(o.name1, '!', COALESCE(o.name2, ''), '!', ch.commenthistory_id, '-', ch.object_id)) AS name,
13+
o.objecttype_id, o.name1, COALESCE(o.name2, '') AS name2
814
FROM icinga_commenthistory ch USE INDEX (PRIMARY)
915
INNER JOIN icinga_objects o ON o.object_id=ch.object_id
1016
WHERE ch.commenthistory_id BETWEEN :fromid AND :toid

cmd/icingadb-migrate/embed/downtime_query.sql

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1-
SELECT dh.downtimehistory_id, UNIX_TIMESTAMP(dh.entry_time) entry_time, dh.author_name, dh.comment_data,
2-
dh.is_fixed, dh.duration, UNIX_TIMESTAMP(dh.scheduled_start_time) scheduled_start_time,
3-
COALESCE(UNIX_TIMESTAMP(dh.scheduled_end_time), 0) scheduled_end_time, dh.was_started,
4-
COALESCE(UNIX_TIMESTAMP(dh.actual_start_time), 0) actual_start_time, dh.actual_start_time_usec,
5-
COALESCE(UNIX_TIMESTAMP(dh.actual_end_time), 0) actual_end_time, dh.actual_end_time_usec, dh.was_cancelled,
6-
COALESCE(UNIX_TIMESTAMP(dh.trigger_time), 0) trigger_time,
7-
COALESCE(dh.name, CONCAT(o.name1, '!', COALESCE(o.name2, ''), '!', dh.downtimehistory_id, '-', dh.object_id)) name,
8-
o.objecttype_id, o.name1, COALESCE(o.name2, '') name2, COALESCE(sd.name, '') triggered_by
1+
SELECT
2+
dh.downtimehistory_id,
3+
UNIX_TIMESTAMP(dh.entry_time) AS entry_time,
4+
dh.author_name,
5+
dh.comment_data,
6+
dh.is_fixed,
7+
dh.duration,
8+
UNIX_TIMESTAMP(dh.scheduled_start_time) AS scheduled_start_time,
9+
COALESCE(UNIX_TIMESTAMP(dh.scheduled_end_time), 0) AS scheduled_end_time,
10+
dh.was_started,
11+
COALESCE(UNIX_TIMESTAMP(dh.actual_start_time), 0) AS actual_start_time,
12+
dh.actual_start_time_usec,
13+
COALESCE(UNIX_TIMESTAMP(dh.actual_end_time), 0) AS actual_end_time,
14+
dh.actual_end_time_usec,
15+
dh.was_cancelled,
16+
COALESCE(UNIX_TIMESTAMP(dh.trigger_time), 0) AS trigger_time,
17+
COALESCE(dh.name, CONCAT(o.name1, '!', COALESCE(o.name2, ''), '!', dh.downtimehistory_id, '-', dh.object_id)) AS name,
18+
o.objecttype_id,
19+
o.name1,
20+
COALESCE(o.name2, '') AS name2,
21+
COALESCE(sd.name, '') AS triggered_by
922
FROM icinga_downtimehistory dh USE INDEX (PRIMARY)
1023
INNER JOIN icinga_objects o ON o.object_id=dh.object_id
1124
LEFT JOIN icinga_scheduleddowntime sd ON sd.scheduleddowntime_id=dh.triggered_by_id

cmd/icingadb-migrate/embed/flapping_query.sql

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
SELECT fh.flappinghistory_id, UNIX_TIMESTAMP(fh.event_time) event_time,
2-
fh.event_time_usec, fh.event_type, fh.percent_state_change, fh.low_threshold,
3-
fh.high_threshold, o.objecttype_id, o.name1, COALESCE(o.name2, '') name2
1+
SELECT
2+
fh.flappinghistory_id,
3+
UNIX_TIMESTAMP(fh.event_time) AS event_time,
4+
fh.event_time_usec,
5+
fh.event_type,
6+
fh.percent_state_change,
7+
fh.low_threshold,
8+
fh.high_threshold,
9+
o.objecttype_id,
10+
o.name1,
11+
COALESCE(o.name2, '') AS name2
412
FROM icinga_flappinghistory fh USE INDEX (PRIMARY)
513
INNER JOIN icinga_objects o ON o.object_id=fh.object_id
614
WHERE fh.flappinghistory_id BETWEEN :fromid AND :toid

cmd/icingadb-migrate/embed/notification_query.sql

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
SELECT n.notification_id, n.notification_reason, UNIX_TIMESTAMP(n.end_time) end_time,
2-
n.end_time_usec, n.state, COALESCE(n.output, '') output, n.long_output,
3-
n.contacts_notified, o.objecttype_id, o.name1, COALESCE(o.name2, '') name2
1+
SELECT
2+
n.notification_id,
3+
n.notification_reason,
4+
UNIX_TIMESTAMP(n.end_time) AS end_time,
5+
n.end_time_usec,
6+
n.state,
7+
COALESCE(n.output, '') AS output,
8+
n.long_output,
9+
n.contacts_notified,
10+
o.objecttype_id,
11+
o.name1,
12+
COALESCE(o.name2, '') AS name2
413
FROM icinga_notifications n USE INDEX (PRIMARY)
514
INNER JOIN icinga_objects o ON o.object_id=n.object_id
615
WHERE n.notification_id BETWEEN :fromid AND :toid

cmd/icingadb-migrate/embed/state_query.sql

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
SELECT sh.statehistory_id, UNIX_TIMESTAMP(sh.state_time) state_time, sh.state_time_usec, sh.state,
2-
sh.state_type, sh.current_check_attempt, sh.max_check_attempts, sh.last_state, sh.last_hard_state,
3-
sh.output, sh.long_output, sh.check_source, o.objecttype_id, o.name1, COALESCE(o.name2, '') name2
1+
SELECT
2+
sh.statehistory_id,
3+
UNIX_TIMESTAMP(sh.state_time) AS state_time,
4+
sh.state_time_usec,
5+
sh.state,
6+
sh.state_type,
7+
sh.current_check_attempt,
8+
sh.max_check_attempts,
9+
sh.last_state,
10+
sh.last_hard_state,
11+
sh.output,
12+
sh.long_output,
13+
sh.check_source,
14+
o.objecttype_id,
15+
o.name1,
16+
COALESCE(o.name2, '') AS name2
417
FROM icinga_statehistory sh USE INDEX (PRIMARY)
518
INNER JOIN icinga_objects o ON o.object_id=sh.object_id
619
WHERE sh.statehistory_id BETWEEN :fromid AND :toid

0 commit comments

Comments
 (0)