schema: add UUIDs for main Icinga objects

This commit is contained in:
Thomas Gelf 2021-10-06 02:01:58 +02:00
parent 20bb6dfc7f
commit fc97d0d4e1
4 changed files with 374 additions and 3 deletions

View File

@ -0,0 +1,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());

View File

@ -231,12 +231,14 @@ CREATE TABLE director_setting (
CREATE TABLE icinga_zone (
id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
uuid VARBINARY(16) NOT NULL,
parent_id INT(10) UNSIGNED DEFAULT NULL,
object_name VARCHAR(255) NOT NULL,
object_type ENUM('object', 'template', 'external_object') NOT NULL,
disabled ENUM('y', 'n') NOT NULL DEFAULT 'n',
is_global ENUM('y', 'n') NOT NULL DEFAULT 'n',
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid),
UNIQUE INDEX object_name (object_name),
CONSTRAINT icinga_zone_parent
FOREIGN KEY parent_zone (parent_id)
@ -265,6 +267,7 @@ CREATE TABLE icinga_zone_inheritance (
CREATE TABLE icinga_timeperiod (
id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
uuid VARBINARY(16) NOT NULL,
object_name VARCHAR(255) NOT NULL,
display_name VARCHAR(255) DEFAULT NULL,
update_method VARCHAR(64) DEFAULT NULL COMMENT 'Usually LegacyTimePeriod',
@ -273,6 +276,7 @@ CREATE TABLE icinga_timeperiod (
disabled ENUM('y', 'n') NOT NULL DEFAULT 'n',
prefer_includes ENUM('y', 'n') DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid),
UNIQUE INDEX object_name (object_name, zone_id),
CONSTRAINT icinga_timeperiod_zone
FOREIGN KEY zone (zone_id)
@ -349,6 +353,7 @@ CREATE TABLE director_job_setting (
CREATE TABLE icinga_command (
id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
uuid VARBINARY(16) NOT NULL,
object_name VARCHAR(255) NOT NULL,
object_type ENUM('object', 'template', 'external_object') NOT NULL
COMMENT 'external_object is an attempt to work with existing commands',
@ -361,6 +366,7 @@ CREATE TABLE icinga_command (
timeout SMALLINT UNSIGNED DEFAULT NULL,
zone_id INT(10) UNSIGNED DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid),
UNIQUE INDEX object_name (object_name),
CONSTRAINT icinga_command_zone
FOREIGN KEY zone (zone_id)
@ -447,17 +453,20 @@ CREATE TABLE icinga_command_var (
CREATE TABLE icinga_apiuser (
id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
uuid VARBINARY(16) NOT NULL,
object_name VARCHAR(255) NOT NULL,
object_type ENUM('object', 'template', 'external_object') NOT NULL,
disabled ENUM('y', 'n') NOT NULL DEFAULT 'n',
password VARCHAR(255) DEFAULT NULL,
client_dn VARCHAR(64) DEFAULT NULL,
permissions TEXT DEFAULT NULL COMMENT 'JSON-encoded permissions',
PRIMARY KEY (id)
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE icinga_endpoint (
id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
uuid VARBINARY(16) NOT NULL,
zone_id INT(10) UNSIGNED DEFAULT NULL,
object_name VARCHAR(255) NOT NULL,
object_type ENUM('object', 'template', 'external_object') NOT NULL,
@ -467,6 +476,7 @@ CREATE TABLE icinga_endpoint (
log_duration VARCHAR(32) DEFAULT NULL COMMENT '1d if not set',
apiuser_id INT(10) UNSIGNED DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid),
UNIQUE INDEX object_name (object_name),
CONSTRAINT icinga_endpoint_zone
FOREIGN KEY zone (zone_id)
@ -512,6 +522,7 @@ CREATE TABLE icinga_host_template_choice (
CREATE TABLE icinga_host (
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
uuid VARBINARY(16) NOT NULL,
object_name VARCHAR(255) NOT NULL,
object_type ENUM('object', 'template') NOT NULL,
disabled ENUM('y', 'n') NOT NULL DEFAULT 'n',
@ -547,6 +558,7 @@ CREATE TABLE icinga_host (
api_key VARCHAR(40) DEFAULT NULL,
template_choice_id INT(10) UNSIGNED DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid),
UNIQUE INDEX object_name (object_name),
UNIQUE INDEX api_key (api_key),
KEY search_idx (display_name),
@ -671,6 +683,7 @@ CREATE TABLE icinga_service_template_choice (
CREATE TABLE icinga_service (
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
uuid VARBINARY(16) NOT NULL,
object_name VARCHAR(255) NOT NULL,
object_type ENUM('object', 'template', 'apply') NOT NULL,
disabled ENUM('y', 'n') NOT NULL DEFAULT 'n',
@ -706,6 +719,7 @@ CREATE TABLE icinga_service (
assign_filter TEXT DEFAULT NULL,
template_choice_id INT(10) UNSIGNED DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid),
UNIQUE KEY object_key (object_name, host_id),
CONSTRAINT icinga_service_host
FOREIGN KEY host (host_id)
@ -876,12 +890,14 @@ CREATE TABLE icinga_service_set_var (
CREATE TABLE icinga_hostgroup (
id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
uuid VARBINARY(16) NOT NULL,
object_name VARCHAR(255) NOT NULL,
object_type ENUM('object', 'template', 'external_object') NOT NULL,
disabled ENUM('y', 'n') NOT NULL DEFAULT 'n',
display_name VARCHAR(255) DEFAULT NULL,
assign_filter TEXT DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid),
UNIQUE INDEX object_name (object_name),
KEY search_idx (display_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -907,12 +923,14 @@ CREATE TABLE icinga_hostgroup_inheritance (
CREATE TABLE icinga_servicegroup (
id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
uuid VARBINARY(16) NOT NULL,
object_name VARCHAR(255) DEFAULT NULL,
object_type ENUM('object', 'template') NOT NULL,
disabled ENUM('y', 'n') NOT NULL DEFAULT 'n',
display_name VARCHAR(255) DEFAULT NULL,
assign_filter TEXT DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid),
UNIQUE INDEX object_name (object_name),
KEY search_idx (display_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -1017,6 +1035,7 @@ CREATE TABLE icinga_hostgroup_parent (
CREATE TABLE icinga_user (
id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
uuid VARBINARY(16) NOT NULL,
object_name VARCHAR(255) DEFAULT NULL,
object_type ENUM('object', 'template') NOT NULL,
disabled ENUM('y', 'n') NOT NULL DEFAULT 'n',
@ -1027,6 +1046,7 @@ CREATE TABLE icinga_user (
period_id INT(10) UNSIGNED DEFAULT NULL,
zone_id INT(10) UNSIGNED DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid),
UNIQUE INDEX object_name (object_name, zone_id),
CONSTRAINT icinga_user_zone
FOREIGN KEY zone (zone_id)
@ -1137,12 +1157,14 @@ CREATE TABLE icinga_user_field (
CREATE TABLE icinga_usergroup (
id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
uuid VARBINARY(16) NOT NULL,
object_name VARCHAR(255) NOT NULL,
object_type ENUM('object', 'template') NOT NULL,
disabled ENUM('y', 'n') NOT NULL DEFAULT 'n',
display_name VARCHAR(255) DEFAULT NULL,
zone_id INT(10) UNSIGNED DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid),
UNIQUE INDEX object_name (object_name),
KEY search_idx (display_name),
CONSTRAINT icinga_usergroup_zone
@ -1204,6 +1226,7 @@ CREATE TABLE icinga_usergroup_parent (
CREATE TABLE icinga_notification (
id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
uuid VARBINARY(16) NOT NULL,
object_name VARCHAR(255) DEFAULT NULL,
object_type ENUM('object', 'template', 'apply') NOT NULL,
disabled ENUM('y', 'n') NOT NULL DEFAULT 'n',
@ -1218,6 +1241,7 @@ CREATE TABLE icinga_notification (
zone_id INT(10) UNSIGNED DEFAULT NULL,
assign_filter TEXT DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid),
CONSTRAINT icinga_notification_host
FOREIGN KEY host (host_id)
REFERENCES icinga_host (id)
@ -1707,6 +1731,7 @@ CREATE TABLE icinga_user_resolved_var (
CREATE TABLE icinga_dependency (
id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
uuid VARBINARY(16) NOT NULL,
object_name VARCHAR(255) DEFAULT NULL,
object_type ENUM('object', 'template', 'apply') NOT NULL,
disabled ENUM('y', 'n') NOT NULL DEFAULT 'n',
@ -1724,6 +1749,7 @@ CREATE TABLE icinga_dependency (
assign_filter TEXT DEFAULT NULL,
parent_service_by_name VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid),
CONSTRAINT icinga_dependency_parent_host
FOREIGN KEY parent_host (parent_host_id)
REFERENCES icinga_host (id)
@ -1828,6 +1854,7 @@ CREATE TABLE icinga_timeperiod_exclude (
CREATE TABLE icinga_scheduled_downtime (
id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
uuid VARBINARY(16) NOT NULL,
object_name VARCHAR(255) NOT NULL,
zone_id INT(10) UNSIGNED DEFAULT NULL,
object_type ENUM('object', 'template', 'apply') NOT NULL,
@ -1840,6 +1867,7 @@ CREATE TABLE icinga_scheduled_downtime (
duration INT(10) UNSIGNED DEFAULT NULL,
with_services ENUM('y', 'n') NULL DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE INDEX uuid (uuid),
UNIQUE INDEX object_name (object_name),
CONSTRAINT icinga_scheduled_downtime_zone
FOREIGN KEY zone (zone_id)
@ -1884,4 +1912,4 @@ CREATE TABLE icinga_scheduled_downtime_range (
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (173, NOW());
VALUES (174, NOW());

View File

@ -0,0 +1,73 @@
ALTER TABLE icinga_zone ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_zone SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_zone ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX zone_uuid ON icinga_zone (uuid);
ALTER TABLE icinga_timeperiod ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_timeperiod SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_timeperiod ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX timeperiod_uuid ON icinga_timeperiod (uuid);
ALTER TABLE icinga_command ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_command SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_command ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX command_uuid ON icinga_command (uuid);
ALTER TABLE icinga_apiuser ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_apiuser SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_apiuser ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX apiuser_uuid ON icinga_apiuser (uuid);
ALTER TABLE icinga_endpoint ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_endpoint SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_endpoint ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX endpoint_uuid ON icinga_endpoint (uuid);
ALTER TABLE icinga_host ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_host SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_host ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX host_uuid ON icinga_host (uuid);
ALTER TABLE icinga_service ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_service SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_service ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX service_uuid ON icinga_service (uuid);
ALTER TABLE icinga_hostgroup ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_hostgroup SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_hostgroup ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX hostgroup_uuid ON icinga_hostgroup (uuid);
ALTER TABLE icinga_servicegroup ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_servicegroup SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_servicegroup ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX servicegroup_uuid ON icinga_servicegroup (uuid);
ALTER TABLE icinga_user ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_user SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_user ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX user_uuid ON icinga_user (uuid);
ALTER TABLE icinga_usergroup ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_usergroup SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_usergroup ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX usergroup_uuid ON icinga_usergroup (uuid);
ALTER TABLE icinga_notification ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_notification SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_notification ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX notification_uuid ON icinga_notification (uuid);
ALTER TABLE icinga_dependency ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_dependency SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_dependency ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX dependency_uuid ON icinga_dependency (uuid);
ALTER TABLE icinga_scheduled_downtime ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16);
UPDATE icinga_scheduled_downtime SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL;
ALTER TABLE icinga_scheduled_downtime ALTER COLUMN uuid SET NOT NULL;
CREATE UNIQUE INDEX scheduled_downtime_uuid ON icinga_scheduled_downtime (uuid);
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (174, NOW());

View File

@ -311,6 +311,7 @@ CREATE TABLE director_setting (
CREATE TABLE icinga_zone (
id serial,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
parent_id integer DEFAULT NULL,
object_name character varying(255) NOT NULL UNIQUE,
object_type enum_object_type_all NOT NULL,
@ -325,6 +326,7 @@ CREATE TABLE icinga_zone (
);
CREATE INDEX zone_parent ON icinga_zone (parent_id);
CREATE UNIQUE INDEX zone_uuid ON icinga_zone (uuid);
CREATE TABLE icinga_zone_inheritance (
@ -351,6 +353,7 @@ CREATE INDEX zone_inheritance_zone_parent ON icinga_zone_inheritance (parent_zon
CREATE TABLE icinga_timeperiod (
id serial,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
object_name character varying(255) NOT NULL,
display_name character varying(255) DEFAULT NULL,
update_method character varying(64) DEFAULT NULL,
@ -366,6 +369,7 @@ CREATE TABLE icinga_timeperiod (
ON UPDATE CASCADE
);
CREATE UNIQUE INDEX timeperiod_uuid ON icinga_timeperiod (uuid);
CREATE UNIQUE INDEX timeperiod_object_name ON icinga_timeperiod (object_name, zone_id);
CREATE INDEX timeperiod_zone ON icinga_timeperiod (zone_id);
COMMENT ON COLUMN icinga_timeperiod.update_method IS 'Usually LegacyTimePeriod';
@ -453,6 +457,7 @@ CREATE INDEX director_job_setting_job ON director_job_setting (job_id);
CREATE TABLE icinga_command (
id serial,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
object_name character varying(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
@ -470,6 +475,7 @@ CREATE TABLE icinga_command (
ON UPDATE CASCADE
);
CREATE UNIQUE INDEX command_uuid ON icinga_command (uuid);
CREATE UNIQUE INDEX command_object_name ON icinga_command (object_name);
CREATE INDEX command_zone ON icinga_command (zone_id);
COMMENT ON COLUMN icinga_command.object_type IS 'external_object is an attempt to work with existing commands';
@ -567,6 +573,7 @@ CREATE INDEX command_var_checksum ON icinga_command_var (checksum);
CREATE TABLE icinga_apiuser (
id BIGSERIAL,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
object_name CHARACTER VARYING(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
@ -576,11 +583,13 @@ CREATE TABLE icinga_apiuser (
PRIMARY KEY (id)
);
CREATE UNIQUE INDEX apiuser_uuid ON icinga_apiuser (uuid);
COMMENT ON COLUMN icinga_apiuser.permissions IS 'JSON-encoded permissions';
CREATE TABLE icinga_endpoint (
id serial,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
zone_id integer DEFAULT NULL,
object_name character varying(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
@ -602,6 +611,7 @@ CREATE TABLE icinga_endpoint (
ON UPDATE CASCADE
);
CREATE UNIQUE INDEX endpoint_uuid ON icinga_endpoint (uuid);
CREATE UNIQUE INDEX endpoint_object_name ON icinga_endpoint (object_name);
CREATE INDEX endpoint_zone ON icinga_endpoint (zone_id);
COMMENT ON COLUMN icinga_endpoint.host IS 'IP address / hostname of remote node';
@ -647,6 +657,7 @@ CREATE INDEX host_template_choice_required_template ON icinga_host_template_choi
CREATE TABLE icinga_host (
id serial,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
object_name character varying(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
@ -715,6 +726,7 @@ CREATE TABLE icinga_host (
);
CREATE UNIQUE INDEX host_uuid ON icinga_host (uuid);
CREATE UNIQUE INDEX object_name_host ON icinga_host (object_name, zone_id);
CREATE UNIQUE INDEX host_api_key ON icinga_host (api_key);
CREATE INDEX host_zone ON icinga_host (zone_id);
@ -834,6 +846,7 @@ CREATE INDEX service_template_choice_required_template ON icinga_service_templat
CREATE TABLE icinga_service (
id serial,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
object_name character varying(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean DEFAULT 'n',
@ -912,6 +925,7 @@ CREATE TABLE icinga_service (
ON UPDATE CASCADE
);
CREATE UNIQUE INDEX service_uuid ON icinga_service (uuid);
CREATE INDEX service_zone ON icinga_service (zone_id);
CREATE INDEX service_timeperiod ON icinga_service (check_period_id);
CREATE INDEX service_check_command ON icinga_service (check_command_id);
@ -1076,6 +1090,7 @@ CREATE INDEX service_set_var_checksum ON icinga_service_set_var (checksum);
CREATE TABLE icinga_hostgroup (
id serial,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
object_name character varying(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
@ -1084,6 +1099,7 @@ CREATE TABLE icinga_hostgroup (
PRIMARY KEY (id)
);
CREATE UNIQUE INDEX hostgroup_uuid ON icinga_hostgroup (uuid);
CREATE UNIQUE INDEX hostgroup_object_name ON icinga_hostgroup (object_name);
CREATE INDEX hostgroup_search_idx ON icinga_hostgroup (display_name);
@ -1113,6 +1129,7 @@ CREATE INDEX hostgroup_inheritance_hostgroup_parent ON icinga_hostgroup_inherita
CREATE TABLE icinga_servicegroup (
id serial,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
object_name character varying(255) DEFAULT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
@ -1121,6 +1138,7 @@ CREATE TABLE icinga_servicegroup (
PRIMARY KEY (id)
);
CREATE UNIQUE INDEX servicegroup_uuid ON icinga_servicegroup (uuid);
CREATE UNIQUE INDEX servicegroup_object_name ON icinga_servicegroup (object_name);
CREATE INDEX servicegroup_search_idx ON icinga_servicegroup (display_name);
@ -1248,6 +1266,7 @@ CREATE INDEX hostgroup_parent_parent ON icinga_hostgroup_parent (parent_hostgrou
CREATE TABLE icinga_user (
id serial,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
object_name character varying(255) DEFAULT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
@ -1270,6 +1289,7 @@ CREATE TABLE icinga_user (
ON UPDATE CASCADE
);
CREATE UNIQUE INDEX user_uuid ON icinga_user (uuid);
CREATE UNIQUE INDEX user_object_name ON icinga_user (object_name, zone_id);
CREATE INDEX user_zone ON icinga_user (zone_id);
@ -1373,6 +1393,7 @@ COMMENT ON COLUMN icinga_user_field.user_id IS 'Makes only sense for templates';
CREATE TABLE icinga_usergroup (
id serial,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
object_name character varying(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
@ -1386,6 +1407,7 @@ CREATE TABLE icinga_usergroup (
ON UPDATE CASCADE
);
CREATE UNIQUE INDEX usergroup_uuid ON icinga_usergroup (uuid);
CREATE UNIQUE INDEX usergroup_search_idx ON icinga_usergroup (display_name);
CREATE INDEX usergroup_object_name ON icinga_usergroup (object_name);
CREATE INDEX usergroup_zone ON icinga_usergroup (zone_id);
@ -1455,6 +1477,7 @@ CREATE INDEX usergroup_parent_parent ON icinga_usergroup_parent (parent_usergrou
CREATE TABLE icinga_notification (
id serial,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
object_name CHARACTER VARYING(255) DEFAULT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
@ -1496,6 +1519,8 @@ CREATE TABLE icinga_notification (
ON UPDATE CASCADE
);
CREATE UNIQUE INDEX notification_uuid ON icinga_notification (uuid);
CREATE TABLE icinga_notification_user (
notification_id integer NOT NULL,
@ -2004,6 +2029,7 @@ CREATE INDEX user_resolved_var_schecksum ON icinga_user_resolved_var (checksum);
CREATE TABLE icinga_dependency (
id serial,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
object_name character varying(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean DEFAULT 'n',
@ -2053,6 +2079,7 @@ CREATE TABLE icinga_dependency (
ON UPDATE CASCADE
);
CREATE UNIQUE INDEX dependency_uuid ON icinga_dependency (uuid);
CREATE INDEX dependency_parent_host ON icinga_dependency (parent_host_id);
CREATE INDEX dependency_parent_service ON icinga_dependency (parent_service_id);
CREATE INDEX dependency_child_host ON icinga_dependency (child_host_id);
@ -2133,6 +2160,7 @@ CREATE TABLE icinga_timeperiod_exclude (
CREATE TABLE icinga_scheduled_downtime (
id serial,
uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16),
object_name character varying(255) NOT NULL,
zone_id integer DEFAULT NULL,
object_type enum_object_type_all NOT NULL,
@ -2152,6 +2180,7 @@ CREATE TABLE icinga_scheduled_downtime (
ON UPDATE CASCADE
);
CREATE UNIQUE INDEX scheduled_downtime_uuid ON icinga_scheduled_downtime (uuid);
CREATE UNIQUE INDEX scheduled_downtime_object_name ON icinga_scheduled_downtime (object_name);
CREATE INDEX scheduled_downtime_zone ON icinga_scheduled_downtime (zone_id);
@ -2201,4 +2230,4 @@ COMMENT ON COLUMN icinga_scheduled_downtime_range.merge_behaviour IS 'set -> = {
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (173, NOW());
VALUES (174, NOW());