diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
commit | cd989f9c3aff968e19a3aeabc4eb9085787a6673 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /schema | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.tar.xz icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.zip |
Adding upstream version 1.10.2.upstream/1.10.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
280 files changed, 12118 insertions, 0 deletions
diff --git a/schema/mysql-legacy-changes/upgrade_1.sql b/schema/mysql-legacy-changes/upgrade_1.sql new file mode 100644 index 0000000..e9b1008 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_1.sql @@ -0,0 +1,2 @@ +ALTER TABLE icinga_user ADD COLUMN object_type ENUM('object', 'template') NOT NULL AFTER zone_id; + diff --git a/schema/mysql-legacy-changes/upgrade_10.sql b/schema/mysql-legacy-changes/upgrade_10.sql new file mode 100644 index 0000000..2709186 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_10.sql @@ -0,0 +1,14 @@ +ALTER TABLE icinga_hostgroup_parent DROP FOREIGN KEY icinga_hostgroup_parent_parent; +ALTER TABLE icinga_hostgroup_parent ADD CONSTRAINT icinga_hostgroup_parent_parent + FOREIGN KEY parent (parent_hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE icinga_usergroup_parent DROP FOREIGN KEY icinga_usergroup_parent_parent; +ALTER TABLE icinga_usergroup_parent ADD CONSTRAINT icinga_usergroup_parent_parent + FOREIGN KEY parent (parent_usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + diff --git a/schema/mysql-legacy-changes/upgrade_11.sql b/schema/mysql-legacy-changes/upgrade_11.sql new file mode 100644 index 0000000..8aaf71a --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_11.sql @@ -0,0 +1 @@ +ALTER TABLE icinga_zone ADD is_global ENUM('y', 'n') NOT NULL DEFAULT 'n' AFTER object_type; diff --git a/schema/mysql-legacy-changes/upgrade_12.sql b/schema/mysql-legacy-changes/upgrade_12.sql new file mode 100644 index 0000000..5ee2525 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_12.sql @@ -0,0 +1,17 @@ +CREATE TABLE icinga_service_inheritance ( + service_id INT(10) UNSIGNED NOT NULL, + parent_service_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (service_id, parent_service_id), + UNIQUE KEY unique_order (service_id, weight), + CONSTRAINT icinga_service_inheritance_service + FOREIGN KEY host (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_inheritance_parent_service + FOREIGN KEY host (parent_service_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/mysql-legacy-changes/upgrade_13.sql b/schema/mysql-legacy-changes/upgrade_13.sql new file mode 100644 index 0000000..96b0aad --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_13.sql @@ -0,0 +1,18 @@ +CREATE TABLE icinga_user_inheritance ( + user_id INT(10) UNSIGNED NOT NULL, + parent_user_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (user_id, parent_user_id), + UNIQUE KEY unique_order (user_id, weight), + CONSTRAINT icinga_user_inheritance_user + FOREIGN KEY host (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_user_inheritance_parent_user + FOREIGN KEY host (parent_user_id) + REFERENCES icinga_user (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + diff --git a/schema/mysql-legacy-changes/upgrade_14.sql b/schema/mysql-legacy-changes/upgrade_14.sql new file mode 100644 index 0000000..506f779 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_14.sql @@ -0,0 +1,18 @@ +CREATE TABLE icinga_timeperiod_inheritance ( + timeperiod_id INT(10) UNSIGNED NOT NULL, + parent_timeperiod_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (timeperiod_id, parent_timeperiod_id), + UNIQUE KEY unique_order (timeperiod_id, weight), + CONSTRAINT icinga_timeperiod_inheritance_timeperiod + FOREIGN KEY host (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_timeperiod_inheritance_parent_timeperiod + FOREIGN KEY host (parent_timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + diff --git a/schema/mysql-legacy-changes/upgrade_15.sql b/schema/mysql-legacy-changes/upgrade_15.sql new file mode 100644 index 0000000..c5f7dd7 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_15.sql @@ -0,0 +1,17 @@ +CREATE TABLE icinga_hostgroup_inheritance ( + hostgroup_id INT(10) UNSIGNED NOT NULL, + parent_hostgroup_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (hostgroup_id, parent_hostgroup_id), + UNIQUE KEY unique_order (hostgroup_id, weight), + CONSTRAINT icinga_hostgroup_inheritance_hostgroup + FOREIGN KEY host (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_hostgroup_inheritance_parent_hostgroup + FOREIGN KEY host (parent_hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/mysql-legacy-changes/upgrade_16.sql b/schema/mysql-legacy-changes/upgrade_16.sql new file mode 100644 index 0000000..0a41a68 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_16.sql @@ -0,0 +1,17 @@ +CREATE TABLE icinga_servicegroup_inheritance ( + servicegroup_id INT(10) UNSIGNED NOT NULL, + parent_servicegroup_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (servicegroup_id, parent_servicegroup_id), + UNIQUE KEY unique_order (servicegroup_id, weight), + CONSTRAINT icinga_servicegroup_inheritance_servicegroup + FOREIGN KEY host (servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_servicegroup_inheritance_parent_servicegroup + FOREIGN KEY host (parent_servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/mysql-legacy-changes/upgrade_17.sql b/schema/mysql-legacy-changes/upgrade_17.sql new file mode 100644 index 0000000..58f7e88 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_17.sql @@ -0,0 +1,17 @@ +CREATE TABLE icinga_command_inheritance ( + command_id INT(10) UNSIGNED NOT NULL, + parent_command_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (command_id, parent_command_id), + UNIQUE KEY unique_order (command_id, weight), + CONSTRAINT icinga_command_inheritance_command + FOREIGN KEY command (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_command_inheritance_parent_command + FOREIGN KEY command (parent_command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/mysql-legacy-changes/upgrade_18.sql b/schema/mysql-legacy-changes/upgrade_18.sql new file mode 100644 index 0000000..5d3eb85 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_18.sql @@ -0,0 +1,17 @@ +CREATE TABLE icinga_zone_inheritance ( + zone_id INT(10) UNSIGNED NOT NULL, + parent_zone_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (zone_id, parent_zone_id), + UNIQUE KEY unique_order (zone_id, weight), + CONSTRAINT icinga_zone_inheritance_zone + FOREIGN KEY zone (zone_id) + REFERENCES icinga_zone (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_zone_inheritance_parent_zone + FOREIGN KEY zone (parent_zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/mysql-legacy-changes/upgrade_19.sql b/schema/mysql-legacy-changes/upgrade_19.sql new file mode 100644 index 0000000..2980ccc --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_19.sql @@ -0,0 +1,17 @@ +CREATE TABLE icinga_usergroup_inheritance ( + usergroup_id INT(10) UNSIGNED NOT NULL, + parent_usergroup_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (usergroup_id, parent_usergroup_id), + UNIQUE KEY unique_order (usergroup_id, weight), + CONSTRAINT icinga_usergroup_inheritance_usergroup + FOREIGN KEY usergroup (usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_usergroup_inheritance_parent_usergroup + FOREIGN KEY usergroup (parent_usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/mysql-legacy-changes/upgrade_2.sql b/schema/mysql-legacy-changes/upgrade_2.sql new file mode 100644 index 0000000..04f3733 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_2.sql @@ -0,0 +1 @@ +ALTER TABLE icinga_command_argument ADD UNIQUE KEY unique_idx (command_id, argument_name); diff --git a/schema/mysql-legacy-changes/upgrade_20.sql b/schema/mysql-legacy-changes/upgrade_20.sql new file mode 100644 index 0000000..91a86a2 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_20.sql @@ -0,0 +1,17 @@ +CREATE TABLE icinga_endpoint_inheritance ( + endpoint_id INT(10) UNSIGNED NOT NULL, + parent_endpoint_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (endpoint_id, parent_endpoint_id), + UNIQUE KEY unique_order (endpoint_id, weight), + CONSTRAINT icinga_endpoint_inheritance_endpoint + FOREIGN KEY endpoint (endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_endpoint_inheritance_parent_endpoint + FOREIGN KEY endpoint (parent_endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/mysql-legacy-changes/upgrade_21.sql b/schema/mysql-legacy-changes/upgrade_21.sql new file mode 100644 index 0000000..7c72b86 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_21.sql @@ -0,0 +1,15 @@ +DROP TABLE director_datalist_value; + +CREATE TABLE director_datalist_entry ( + list_id INT(10) UNSIGNED NOT NULL, + entry_name VARCHAR(255) DEFAULT NULL, + entry_value TEXT DEFAULT NULL, + format enum ('string', 'expression', 'json'), + PRIMARY KEY (list_id, entry_name), + CONSTRAINT director_datalist_value_datalist + FOREIGN KEY datalist (list_id) + REFERENCES director_datalist (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + diff --git a/schema/mysql-legacy-changes/upgrade_22.sql b/schema/mysql-legacy-changes/upgrade_22.sql new file mode 100644 index 0000000..418145c --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_22.sql @@ -0,0 +1,43 @@ +CREATE TABLE icinga_host_field ( + host_id INT(10) UNSIGNED NOT NULL COMMENT 'Makes only sense for templates', + fieldname VARCHAR(64) NOT NULL, + caption VARCHAR(255) NOT NULL, + datatype_id INT(10) UNSIGNED NOT NULL, +-- datatype_param? multiple ones? + default_value TEXT DEFAULT NULL, + format enum ('string', 'json', 'expression'), + PRIMARY KEY (host_id, fieldname), + KEY search_idx (fieldname), + CONSTRAINT icinga_host_field_host + FOREIGN KEY host(host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_field_datatype + FOREIGN KEY datatype (datatype_id) + REFERENCES director_datatype (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_service_field ( + service_id INT(10) UNSIGNED NOT NULL COMMENT 'Makes only sense for templates', + fieldname VARCHAR(64) NOT NULL, + caption VARCHAR(255) NOT NULL, + datatype_id INT(10) UNSIGNED NOT NULL, + -- datatype_param? multiple ones? + default_value TEXT DEFAULT NULL, + format enum ('string', 'json', 'expression'), + PRIMARY KEY (service_id, fieldname), + KEY search_idx (fieldname), + CONSTRAINT icinga_service_field_service + FOREIGN KEY service (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_field_datatype + FOREIGN KEY datatype (datatype_id) + REFERENCES director_datatype (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/mysql-legacy-changes/upgrade_23.sql b/schema/mysql-legacy-changes/upgrade_23.sql new file mode 100644 index 0000000..2368a17 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_23.sql @@ -0,0 +1,51 @@ +DROP TABLE director_datatype; + +CREATE TABLE director_datafield ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + varname VARCHAR(64) NOT NULL, + caption VARCHAR(255) NOT NULL, + description TEXT DEFAULT NULL, + datatype varchar(255) NOT NULL, +-- datatype_param? multiple ones? + format enum ('string', 'json', 'expression'), + PRIMARY KEY (id), + KEY search_idx (varname) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +DROP TABLE icinga_host_field; + +CREATE TABLE icinga_host_field ( + host_id INT(10) UNSIGNED NOT NULL COMMENT 'Makes only sense for templates', + datafield_id INT(10) UNSIGNED NOT NULL, + is_required ENUM('y', 'n') DEFAULT NULL, + PRIMARY KEY (host_id, datafield_id), + CONSTRAINT icinga_host_field_host + FOREIGN KEY host(host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_field_datafield + FOREIGN KEY datafield(datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +DROP TABLE icinga_service_field; + +CREATE TABLE icinga_service_field ( + service_id INT(10) UNSIGNED NOT NULL COMMENT 'Makes only sense for templates', + datafield_id INT(10) UNSIGNED NOT NULL, + is_required ENUM('y', 'n') DEFAULT NULL, + PRIMARY KEY (service_id, datafield_id), + CONSTRAINT icinga_service_field_service + FOREIGN KEY service(service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_field_datafield + FOREIGN KEY datafield(datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8;
\ No newline at end of file diff --git a/schema/mysql-legacy-changes/upgrade_24.sql b/schema/mysql-legacy-changes/upgrade_24.sql new file mode 100644 index 0000000..4c380b1 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_24.sql @@ -0,0 +1,91 @@ +CREATE TABLE import_source ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + source_name VARCHAR(64) NOT NULL, + provider_class VARCHAR(72) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE import_source_setting ( + source_id INT(10) UNSIGNED NOT NULL, + setting_name VARCHAR(64) NOT NULL, + setting_value VARCHAR(255) NOT NULL, + PRIMARY KEY (source_id, setting_name), + CONSTRAINT import_source_settings_source + FOREIGN KEY source (source_id) + REFERENCES import_source (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE imported_rowset ( + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (checksum) +) ENGINE=InnoDB; + +CREATE TABLE import_run ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + source_id INT(10) UNSIGNED NOT NULL, + imported_rowset_checksum VARBINARY(20) DEFAULT NULL, + start_time DATETIME NOT NULL, + end_time DATETIME DEFAULT NULL, + succeeded ENUM('y', 'n') DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT import_run_source + FOREIGN KEY import_source (source_id) + REFERENCES import_source (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT import_run_rowset + FOREIGN KEY rowset (imported_rowset_checksum) + REFERENCES imported_rowset (checksum) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE imported_row ( + checksum VARBINARY(20) NOT NULL COMMENT 'sha1(object_name;property_checksum;...)', + object_name VARCHAR(255) NOT NULL, + PRIMARY KEY (checksum) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE imported_rowset_row ( + rowset_checksum VARBINARY(20) NOT NULL, + row_checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (rowset_checksum, row_checksum), + CONSTRAINT imported_rowset_row_rowset + FOREIGN KEY rowset_row_rowset (rowset_checksum) + REFERENCES imported_rowset (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT imported_rowset_row_row + FOREIGN KEY rowset_row_rowset (row_checksum) + REFERENCES imported_row (checksum) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE imported_property ( + checksum VARBINARY(20) NOT NULL, + property_name VARCHAR(64) NOT NULL, + property_value TEXT NOT NULL, + format enum ('string', 'expression', 'json'), + PRIMARY KEY (checksum), + KEY search_idx (property_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE imported_row_property ( + row_checksum VARBINARY(20) NOT NULL, + property_checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (row_checksum, property_checksum), + CONSTRAINT imported_row_property_row + FOREIGN KEY row_checksum (row_checksum) + REFERENCES imported_row (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT imported_row_property_property + FOREIGN KEY property_checksum (property_checksum) + REFERENCES imported_property (checksum) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB; + diff --git a/schema/mysql-legacy-changes/upgrade_25.sql b/schema/mysql-legacy-changes/upgrade_25.sql new file mode 100644 index 0000000..f4d2d90 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_25.sql @@ -0,0 +1,2 @@ +ALTER TABLE import_source ADD COLUMN key_column VARCHAR(64) NOT NULL AFTER source_name; +ALTER TABLE import_source ADD INDEX search_idx (key_column); diff --git a/schema/mysql-legacy-changes/upgrade_26.sql b/schema/mysql-legacy-changes/upgrade_26.sql new file mode 100644 index 0000000..d7f0c46 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_26.sql @@ -0,0 +1,4 @@ +ALTER TABLE import_run DROP FOREIGN KEY import_run_rowset; +ALTER TABLE import_run CHANGE imported_rowset_checksum rowset_checksum varbinary(20) DEFAULT NULL; +ALTER TABLE import_run ADD CONSTRAINT import_run_rowset FOREIGN KEY rowset (rowset_checksum) REFERENCES imported_rowset (checksum) ON DELETE RESTRICT ON UPDATE CASCADE; + diff --git a/schema/mysql-legacy-changes/upgrade_27.sql b/schema/mysql-legacy-changes/upgrade_27.sql new file mode 100644 index 0000000..684e45c --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_27.sql @@ -0,0 +1,58 @@ + +CREATE TABLE sync_rule ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + rule_name VARCHAR(255) NOT NULL, + object_type ENUM('host', 'user') NOT NULL, + update_policy ENUM('merge', 'override', 'ignore') NOT NULL, + purge_existing ENUM('y', 'n') NOT NULL DEFAULT 'n', + filter_expression TEXT NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE sync_property ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + rule_id INT(10) UNSIGNED NOT NULL, + source_id INT(10) UNSIGNED NOT NULL, + source_expression VARCHAR(255) NOT NULL, + destination_field VARCHAR(64), + priority SMALLINT UNSIGNED NOT NULL, + filter_expression TEXT DEFAULT NULL, + merge_policy ENUM('override', 'merge') NOT NULL, + PRIMARY KEY (id), + CONSTRAINT sync_property_rule + FOREIGN KEY sync_rule (rule_id) + REFERENCES sync_rule (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT sync_property_source + FOREIGN KEY import_source (source_id) + REFERENCES import_source (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE sync_modifier ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + property_id INT(10) UNSIGNED NOT NULL, + provider_class VARCHAR(72) NOT NULL, + PRIMARY KEY (id), + CONSTRAINT sync_modifier_property + FOREIGN KEY sync_property (property_id) + REFERENCES sync_property (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE sync_modifier_param ( + modifier_id INT UNSIGNED NOT NULL, + param_name VARCHAR(64) NOT NULL, + param_value TEXT DEFAULT NULL, + PRIMARY KEY (modifier_id, param_name), + CONSTRAINT sync_modifier_param_modifier + FOREIGN KEY modifier (modifier_id) + REFERENCES sync_modifier (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + diff --git a/schema/mysql-legacy-changes/upgrade_28.sql b/schema/mysql-legacy-changes/upgrade_28.sql new file mode 100644 index 0000000..2451311 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_28.sql @@ -0,0 +1 @@ +ALTER TABLE sync_rule MODIFY filter_expression TEXT DEFAULT NULL; diff --git a/schema/mysql-legacy-changes/upgrade_29.sql b/schema/mysql-legacy-changes/upgrade_29.sql new file mode 100644 index 0000000..e841a7f --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_29.sql @@ -0,0 +1,16 @@ +DROP TABLE sync_modifier_param; +DROP TABLE sync_modifier; + +CREATE TABLE import_row_modifier ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + property_id INT(10) UNSIGNED NOT NULL, + provider_class VARCHAR(72) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE import_row_modifier_settings ( + modifier_id INT UNSIGNED NOT NULL, + settings_name VARCHAR(64) NOT NULL, + settings_value TEXT DEFAULT NULL, + PRIMARY KEY (modifier_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/mysql-legacy-changes/upgrade_3.sql b/schema/mysql-legacy-changes/upgrade_3.sql new file mode 100644 index 0000000..1a093d6 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_3.sql @@ -0,0 +1 @@ +ALTER TABLE icinga_hostgroup ADD COLUMN object_type ENUM('object', 'template') NOT NULL AFTER display_name;
\ No newline at end of file diff --git a/schema/mysql-legacy-changes/upgrade_30.sql b/schema/mysql-legacy-changes/upgrade_30.sql new file mode 100644 index 0000000..1cd60b8 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_30.sql @@ -0,0 +1,8 @@ +DROP TABLE import_row_modifier_settings; + +CREATE TABLE import_row_modifier_setting ( + modifier_id INT UNSIGNED NOT NULL, + setting_name VARCHAR(64) NOT NULL, + setting_value TEXT DEFAULT NULL, + PRIMARY KEY (modifier_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/mysql-legacy-changes/upgrade_31.sql b/schema/mysql-legacy-changes/upgrade_31.sql new file mode 100644 index 0000000..d8031ed --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_31.sql @@ -0,0 +1,2 @@ +ALTER TABLE director_generated_file MODIFY content MEDIUMTEXT DEFAULT NULL; + diff --git a/schema/mysql-legacy-changes/upgrade_32.sql b/schema/mysql-legacy-changes/upgrade_32.sql new file mode 100644 index 0000000..4d584de --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_32.sql @@ -0,0 +1 @@ +ALTER TABLE import_source_setting MODIFY setting_value TEXT DEFAULT NULL; diff --git a/schema/mysql-legacy-changes/upgrade_33.sql b/schema/mysql-legacy-changes/upgrade_33.sql new file mode 100644 index 0000000..19f7e45 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_33.sql @@ -0,0 +1,11 @@ +CREATE TABLE director_datafield_setting ( + datafield_id INT(10) UNSIGNED NOT NULL, + setting_name VARCHAR(64) NOT NULL, + setting_value TEXT NOT NULL, + PRIMARY KEY (datafield_id, setting_name), + CONSTRAINT datafield_id_settings + FOREIGN KEY datafield (datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/mysql-legacy-changes/upgrade_34.sql b/schema/mysql-legacy-changes/upgrade_34.sql new file mode 100644 index 0000000..21af3d0 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_34.sql @@ -0,0 +1,2 @@ +ALTER TABLE icinga_host_field MODIFY is_required ENUM('y', 'n') NOT NULL; +ALTER TABLE icinga_service_field MODIFY is_required ENUM('y', 'n') NOT NULL; diff --git a/schema/mysql-legacy-changes/upgrade_35.sql b/schema/mysql-legacy-changes/upgrade_35.sql new file mode 100644 index 0000000..166a06f --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_35.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_command_argument DROP COLUMN value_format, ADD COLUMN argument_format ENUM('string', 'expression', 'json') NOT NULL DEFAULT 'string' AFTER argument_value; +ALTER TABLE icinga_command_argument DEFAULT COLLATE utf8_bin; +ALTER TABLE icinga_command_argument MODIFY COLUMN argument_name VARCHAR(64) DEFAULT NULL COLLATE utf8_bin; + + + diff --git a/schema/mysql-legacy-changes/upgrade_36.sql b/schema/mysql-legacy-changes/upgrade_36.sql new file mode 100644 index 0000000..8905f10 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_36.sql @@ -0,0 +1 @@ +ALTER TABLE sync_rule MODIFY COLUMN object_type enum('host', 'host_template', 'service', 'service_template', 'command', 'command_template', 'user', 'user_template', 'hostgroup', 'servicegroup', 'usergroup', 'datalistEntry') NOT NULL; diff --git a/schema/mysql-legacy-changes/upgrade_37.sql b/schema/mysql-legacy-changes/upgrade_37.sql new file mode 100644 index 0000000..2533370 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_37.sql @@ -0,0 +1,17 @@ +CREATE TABLE icinga_command_field ( + command_id INT(10) UNSIGNED NOT NULL, + datafield_id INT(10) UNSIGNED NOT NULL, + is_required ENUM('y', 'n') NOT NULL, + PRIMARY KEY (command_id, datafield_id), + CONSTRAINT icinga_command_field_command_argument + FOREIGN KEY host(command_id) + REFERENCES icinga_command_argument (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_command_field_datafield + FOREIGN KEY datafield(datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + diff --git a/schema/mysql-legacy-changes/upgrade_38.sql b/schema/mysql-legacy-changes/upgrade_38.sql new file mode 100644 index 0000000..8760334 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_38.sql @@ -0,0 +1,4 @@ +ALTER TABLE icinga_host + ADD COLUMN display_name VARCHAR(255) DEFAULT NULL, + ADD INDEX search_idx (display_name); + diff --git a/schema/mysql-legacy-changes/upgrade_39.sql b/schema/mysql-legacy-changes/upgrade_39.sql new file mode 100644 index 0000000..81ee33d --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_39.sql @@ -0,0 +1,5 @@ +ALTER TABLE director_deployment_log + MODIFY COLUMN startup_log TEXT DEFAULT NULL, + ADD COLUMN stage_name VARCHAR(64) DEFAULT NULL AFTER duration_dump, + ADD COLUMN stage_collected ENUM('y', 'n') DEFAULT NULL AFTER stage_name; + diff --git a/schema/mysql-legacy-changes/upgrade_4.sql b/schema/mysql-legacy-changes/upgrade_4.sql new file mode 100644 index 0000000..4f005f2 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_4.sql @@ -0,0 +1 @@ +ALTER TABLE icinga_servicegroup ADD COLUMN object_type ENUM('object', 'template') NOT NULL AFTER display_name;
\ No newline at end of file diff --git a/schema/mysql-legacy-changes/upgrade_40.sql b/schema/mysql-legacy-changes/upgrade_40.sql new file mode 100644 index 0000000..55bcbed --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_40.sql @@ -0,0 +1,9 @@ + +ALTER TABLE director_deployment_log ADD COLUMN config_checksum VARBINARY(20) DEFAULT NULL AFTER config_id; +ALTER TABLE director_deployment_log DROP COLUMN config_id; +ALTER TABLE director_deployment_log ADD CONSTRAINT config_checksum + FOREIGN KEY config_checksum (config_checksum) + REFERENCES director_generated_config (checksum) + ON DELETE SET NULL + ON UPDATE RESTRICT; + diff --git a/schema/mysql-legacy-changes/upgrade_41.sql b/schema/mysql-legacy-changes/upgrade_41.sql new file mode 100644 index 0000000..0ddb9b6 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_41.sql @@ -0,0 +1,19 @@ +DROP TABLE icinga_command_field; + +CREATE TABLE icinga_command_field ( + command_id INT(10) UNSIGNED NOT NULL, + datafield_id INT(10) UNSIGNED NOT NULL, + is_required ENUM('y', 'n') NOT NULL, + PRIMARY KEY (command_id, datafield_id), + CONSTRAINT icinga_command_field_command + FOREIGN KEY command_id (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_command_field_datafield + FOREIGN KEY datafield(datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + diff --git a/schema/mysql-legacy-changes/upgrade_42.sql b/schema/mysql-legacy-changes/upgrade_42.sql new file mode 100644 index 0000000..849ffda --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_42.sql @@ -0,0 +1,7 @@ +ALTER TABLE import_run DROP FOREIGN KEY import_run_source; +ALTER TABLE import_run ADD CONSTRAINT import_run_source + FOREIGN KEY import_source (source_id) + REFERENCES import_source (id) + ON DELETE CASCADE + ON UPDATE RESTRICT; + diff --git a/schema/mysql-legacy-changes/upgrade_43.sql b/schema/mysql-legacy-changes/upgrade_43.sql new file mode 100644 index 0000000..4e6a810 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_43.sql @@ -0,0 +1,13 @@ +CREATE TABLE icinga_service_assignment ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + service_id INT(10) UNSIGNED NOT NULL, + filter_string TEXT NOT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_service_assignment + FOREIGN KEY service (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + + diff --git a/schema/mysql-legacy-changes/upgrade_44.sql b/schema/mysql-legacy-changes/upgrade_44.sql new file mode 100644 index 0000000..a874f67 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_44.sql @@ -0,0 +1,2 @@ +ALTER TABLE imported_property MODIFY property_value MEDIUMTEXT NULL DEFAULT NULL; + diff --git a/schema/mysql-legacy-changes/upgrade_45.sql b/schema/mysql-legacy-changes/upgrade_45.sql new file mode 100644 index 0000000..c819424 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_45.sql @@ -0,0 +1 @@ +ALTER TABLE icinga_command_argument MODIFY argument_format ENUM('string','expression','json') NULL DEFAULT NULL; diff --git a/schema/mysql-legacy-changes/upgrade_46.sql b/schema/mysql-legacy-changes/upgrade_46.sql new file mode 100644 index 0000000..cc7c5fc --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_46.sql @@ -0,0 +1,2 @@ +ALTER TABLE icinga_command_argument MODIFY argument_name VARCHAR(64) COLLATE utf8_bin DEFAULT NULL COMMENT '-x, --host'; + diff --git a/schema/mysql-legacy-changes/upgrade_47.sql b/schema/mysql-legacy-changes/upgrade_47.sql new file mode 100644 index 0000000..cdaedad --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_47.sql @@ -0,0 +1 @@ +ALTER TABLE icinga_command_argument DROP INDEX sort_idx, ADD INDEX sort_idx (command_id, sort_order); diff --git a/schema/mysql-legacy-changes/upgrade_48.sql b/schema/mysql-legacy-changes/upgrade_48.sql new file mode 100644 index 0000000..de72ece --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_48.sql @@ -0,0 +1 @@ +ALTER TABLE icinga_zone MODIFY object_type ENUM('object', 'template', 'external_object') NOT NULL; diff --git a/schema/mysql-legacy-changes/upgrade_49.sql b/schema/mysql-legacy-changes/upgrade_49.sql new file mode 100644 index 0000000..35a9dc9 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_49.sql @@ -0,0 +1 @@ +ALTER TABLE director_deployment_log MODIFY stage_name VARCHAR(96) DEFAULT NULL; diff --git a/schema/mysql-legacy-changes/upgrade_5.sql b/schema/mysql-legacy-changes/upgrade_5.sql new file mode 100644 index 0000000..4c17ce3 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_5.sql @@ -0,0 +1 @@ +ALTER TABLE icinga_usergroup ADD COLUMN object_type ENUM('object', 'template') NOT NULL AFTER zone_id;
\ No newline at end of file diff --git a/schema/mysql-legacy-changes/upgrade_50.sql b/schema/mysql-legacy-changes/upgrade_50.sql new file mode 100644 index 0000000..6d6a7a3 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_50.sql @@ -0,0 +1 @@ +ALTER TABLE director_deployment_log MODIFY startup_log MEDIUMTEXT DEFAULT NULL; diff --git a/schema/mysql-legacy-changes/upgrade_51.sql b/schema/mysql-legacy-changes/upgrade_51.sql new file mode 100644 index 0000000..13df6d5 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_51.sql @@ -0,0 +1,2 @@ +ALTER TABLE sync_rule MODIFY object_type enum('host', 'host_template', 'service', 'service_template', 'command', 'command_template', 'user', 'user_template', 'hostgroup', 'servicegroup', 'usergroup', 'datalistEntry', 'endpoint', 'zone') NOT NULL; + diff --git a/schema/mysql-legacy-changes/upgrade_52.sql b/schema/mysql-legacy-changes/upgrade_52.sql new file mode 100644 index 0000000..fad0d56 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_52.sql @@ -0,0 +1,5 @@ +ALTER TABLE icinga_endpoint + MODIFY object_type ENUM('object', 'template', 'external_object') NOT NULL, + ADD COLUMN host VARCHAR(255) DEFAULT NULL COMMENT 'IP address / hostname of remote node' AFTER object_name, + DROP column address; + diff --git a/schema/mysql-legacy-changes/upgrade_53.sql b/schema/mysql-legacy-changes/upgrade_53.sql new file mode 100644 index 0000000..d6a54cb --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_53.sql @@ -0,0 +1,9 @@ +ALTER TABLE icinga_service + ADD COLUMN host_id INT(10) UNSIGNED DEFAULT NULL AFTER display_name, + ADD UNIQUE KEY object_key (object_name, host_id), + ADD CONSTRAINT icinga_host + FOREIGN KEY host (host_id) + REFERENCES icinga_host (id) + ON DELETE SET NULL + ON UPDATE CASCADE; + diff --git a/schema/mysql-legacy-changes/upgrade_54.sql b/schema/mysql-legacy-changes/upgrade_54.sql new file mode 100644 index 0000000..1b65963 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_54.sql @@ -0,0 +1,2 @@ +ALTER TABLE director_generated_config_file MODIFY file_path VARCHAR(128) NOT NULL COMMENT 'e.g. zones/nafta/hosts.conf'; + diff --git a/schema/mysql-legacy-changes/upgrade_55.sql b/schema/mysql-legacy-changes/upgrade_55.sql new file mode 100644 index 0000000..4ad6feb --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_55.sql @@ -0,0 +1,8 @@ +ALTER TABLE icinga_zone + DROP FOREIGN KEY icinga_zone_parent_zone, + CHANGE parent_zone_id parent_id INT(10) UNSIGNED DEFAULT NULL, + ADD CONSTRAINT icinga_zone_parent + FOREIGN KEY parent_zone (parent_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; diff --git a/schema/mysql-legacy-changes/upgrade_56.sql b/schema/mysql-legacy-changes/upgrade_56.sql new file mode 100644 index 0000000..75683de --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_56.sql @@ -0,0 +1,13 @@ +ALTER TABLE director_generated_file + ADD COLUMN cnt_object INT(10) UNSIGNED NOT NULL DEFAULT 0, + ADD COLUMN cnt_template INT(10) UNSIGNED NOT NULL DEFAULT 0; + +UPDATE director_generated_file +SET cnt_object = ROUND( + (LENGTH(content) - LENGTH( REPLACE(content, 'object ', '') ) ) + / LENGTH('object ') +), cnt_template = ROUND( + (LENGTH(content) - LENGTH( REPLACE(content, 'template ', '') ) ) + / LENGTH('template ') +); + diff --git a/schema/mysql-legacy-changes/upgrade_57.sql b/schema/mysql-legacy-changes/upgrade_57.sql new file mode 100644 index 0000000..3b2f756 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_57.sql @@ -0,0 +1,20 @@ + +CREATE TABLE icinga_apiuser ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + object_name VARCHAR(255) NOT NULL, + object_type ENUM('object', 'template', 'external_object') NOT NULL, + password VARCHAR(255) DEFAULT NULL, + client_dn VARCHAR(64) DEFAULT NULL, + permissions TEXT DEFAULT NULL COMMENT 'JSON-encoded permissions', + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE icinga_endpoint + ADD COLUMN apiuser_id INT(10) UNSIGNED DEFAULT NULL, + ADD CONSTRAINT icinga_apiuser + FOREIGN KEY apiuser (apiuser_id) + REFERENCES icinga_apiuser (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + + diff --git a/schema/mysql-legacy-changes/upgrade_58.sql b/schema/mysql-legacy-changes/upgrade_58.sql new file mode 100644 index 0000000..5771f6a --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_58.sql @@ -0,0 +1,5 @@ +ALTER TABLE icinga_host + ADD COLUMN has_agent ENUM('y', 'n') DEFAULT NULL, + ADD COLUMN master_should_connect ENUM('y', 'n') DEFAULT NULL, + ADD COLUMN accept_config ENUM('y', 'n') DEFAULT NULL; + diff --git a/schema/mysql-legacy-changes/upgrade_59.sql b/schema/mysql-legacy-changes/upgrade_59.sql new file mode 100644 index 0000000..8c760e2 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_59.sql @@ -0,0 +1,3 @@ +ALTER TABLE icinga_service + ADD COLUMN use_agent ENUM('y', 'n') NOT NULL DEFAULT 'n'; + diff --git a/schema/mysql-legacy-changes/upgrade_6.sql b/schema/mysql-legacy-changes/upgrade_6.sql new file mode 100644 index 0000000..0834b10 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_6.sql @@ -0,0 +1,5 @@ +ALTER TABLE icinga_endpoint + MODIFY zone_id INT(10) UNSIGNED DEFAULT NULL, + MODIFY port SMALLINT UNSIGNED DEFAULT NULL COMMENT '5665 if not set', + MODIFY log_duration VARCHAR(32) DEFAULT NULL COMMENT '1d if not set'; + diff --git a/schema/mysql-legacy-changes/upgrade_60.sql b/schema/mysql-legacy-changes/upgrade_60.sql new file mode 100644 index 0000000..5b0da8f --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_60.sql @@ -0,0 +1,2 @@ +ALTER TABLE icinga_service MODIFY COLUMN use_agent ENUM('y', 'n') DEFAULT NULL; + diff --git a/schema/mysql-legacy-changes/upgrade_61.sql b/schema/mysql-legacy-changes/upgrade_61.sql new file mode 100644 index 0000000..50d62fd --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_61.sql @@ -0,0 +1,2 @@ +ALTER TABLE icinga_host DROP KEY object_name, ADD UNIQUE KEY object_name (object_name); + diff --git a/schema/mysql-legacy-changes/upgrade_62.sql b/schema/mysql-legacy-changes/upgrade_62.sql new file mode 100644 index 0000000..a3aba5f --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_62.sql @@ -0,0 +1 @@ +ALTER TABLE icinga_command MODIFY command TEXT DEFAULT NULL; diff --git a/schema/mysql-legacy-changes/upgrade_7.sql b/schema/mysql-legacy-changes/upgrade_7.sql new file mode 100644 index 0000000..38780b2 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_7.sql @@ -0,0 +1 @@ +ALTER TABLE icinga_service DROP INDEX object_name;
\ No newline at end of file diff --git a/schema/mysql-legacy-changes/upgrade_8.sql b/schema/mysql-legacy-changes/upgrade_8.sql new file mode 100644 index 0000000..a1c9d46 --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_8.sql @@ -0,0 +1,36 @@ +DROP TABLE director_generated_config_file; + +DROP TABLE director_generated_config; + +CREATE TABLE director_generated_config ( + checksum VARBINARY(20) NOT NULL COMMENT 'SHA1(last_activity_checksum;file_path=checksum;file_path=checksum;...)', + director_version VARCHAR(64) DEFAULT NULL, + director_db_version INT(10) DEFAULT NULL, + duration INT(10) UNSIGNED DEFAULT NULL COMMENT 'Config generation duration (ms)', + last_activity_checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (checksum), + CONSTRAINT director_generated_config_activity + FOREIGN KEY activity_checksum (last_activity_checksum) + REFERENCES director_activity_log (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_generated_config_file ( + config_checksum VARBINARY(20) NOT NULL, + file_checksum VARBINARY(20) NOT NULL, + file_path VARCHAR(64) NOT NULL COMMENT 'e.g. zones/nafta/hosts.conf', + CONSTRAINT director_generated_config_file_config + FOREIGN KEY config (config_checksum) + REFERENCES director_generated_config (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT director_generated_config_file_file + FOREIGN KEY checksum (file_checksum) + REFERENCES director_generated_file (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT, + PRIMARY KEY (config_checksum, file_path), + INDEX search_idx (file_checksum) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + diff --git a/schema/mysql-legacy-changes/upgrade_9.sql b/schema/mysql-legacy-changes/upgrade_9.sql new file mode 100644 index 0000000..4a7b93a --- /dev/null +++ b/schema/mysql-legacy-changes/upgrade_9.sql @@ -0,0 +1 @@ +ALTER TABLE icinga_command MODIFY timeout SMALLINT UNSIGNED DEFAULT NULL;
\ No newline at end of file diff --git a/schema/mysql-migrations/upgrade_100.sql b/schema/mysql-migrations/upgrade_100.sql new file mode 100644 index 0000000..56f8b54 --- /dev/null +++ b/schema/mysql-migrations/upgrade_100.sql @@ -0,0 +1,6 @@ +ALTER TABLE import_row_modifier + ADD COLUMN target_property VARCHAR(255) DEFAULT NULL AFTER property_name; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (100, NOW()); diff --git a/schema/mysql-migrations/upgrade_101.sql b/schema/mysql-migrations/upgrade_101.sql new file mode 100644 index 0000000..bbe1817 --- /dev/null +++ b/schema/mysql-migrations/upgrade_101.sql @@ -0,0 +1,7 @@ +ALTER TABLE icinga_host + ADD COLUMN api_key VARCHAR(40) DEFAULT NULL AFTER accept_config, + ADD UNIQUE KEY api_key (api_key); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (101, NOW()); diff --git a/schema/mysql-migrations/upgrade_102.sql b/schema/mysql-migrations/upgrade_102.sql new file mode 100644 index 0000000..5607f1e --- /dev/null +++ b/schema/mysql-migrations/upgrade_102.sql @@ -0,0 +1,13 @@ +UPDATE director_deployment_log SET startup_log = LEFT(startup_log, 20480) || ' + +[..] shortened ' +|| (LENGTH(startup_log) - 40960) +|| ' bytes by Director on schema upgrade [..] + +' || RIGHT(startup_log, 20480) WHERE LENGTH(startup_log) > 61440; + +OPTIMIZE TABLE director_deployment_log; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (102, NOW()); diff --git a/schema/mysql-migrations/upgrade_103.sql b/schema/mysql-migrations/upgrade_103.sql new file mode 100644 index 0000000..64d222b --- /dev/null +++ b/schema/mysql-migrations/upgrade_103.sql @@ -0,0 +1,12 @@ +UPDATE icinga_command_argument + SET + argument_name = '(no key)', + skip_key = 'y' + WHERE argument_name IS NULL; + +ALTER TABLE icinga_command_argument + MODIFY argument_name VARCHAR(64) COLLATE utf8_bin NOT NULL COMMENT '-x, --host'; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (103, NOW()); diff --git a/schema/mysql-migrations/upgrade_104.sql b/schema/mysql-migrations/upgrade_104.sql new file mode 100644 index 0000000..673360a --- /dev/null +++ b/schema/mysql-migrations/upgrade_104.sql @@ -0,0 +1,19 @@ +ALTER TABLE icinga_timeperiod_range + ADD COLUMN range_key VARCHAR(255) NOT NULL COMMENT 'monday, ...', + ADD COLUMN range_value VARCHAR(255) NOT NULL COMMENT '00:00-24:00, ...'; + +UPDATE icinga_timeperiod_range + SET range_key = timeperiod_key, + range_value = timeperiod_value; + +ALTER TABLE icinga_timeperiod_range + DROP PRIMARY KEY, + ADD PRIMARY KEY (timeperiod_id, range_type, range_key); + +ALTER TABLE icinga_timeperiod_range + DROP COLUMN timeperiod_key, + DROP COLUMN timeperiod_value; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (104, NOW()); diff --git a/schema/mysql-migrations/upgrade_105.sql b/schema/mysql-migrations/upgrade_105.sql new file mode 100644 index 0000000..da4efa8 --- /dev/null +++ b/schema/mysql-migrations/upgrade_105.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_service + ADD COLUMN use_var_overrides ENUM('y', 'n') DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (105, NOW()); diff --git a/schema/mysql-migrations/upgrade_107.sql b/schema/mysql-migrations/upgrade_107.sql new file mode 100644 index 0000000..fb35f07 --- /dev/null +++ b/schema/mysql-migrations/upgrade_107.sql @@ -0,0 +1,9 @@ +ALTER TABLE director_job + MODIFY last_error_message TEXT DEFAULT NULL; + +ALTER TABLE sync_rule + MODIFY last_error_message TEXT DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (107, NOW()); diff --git a/schema/mysql-migrations/upgrade_108.sql b/schema/mysql-migrations/upgrade_108.sql new file mode 100644 index 0000000..8a6ef39 --- /dev/null +++ b/schema/mysql-migrations/upgrade_108.sql @@ -0,0 +1,18 @@ +ALTER TABLE icinga_command_var + MODIFY COLUMN varname VARCHAR(255) NOT NULL COLLATE utf8_bin; + +ALTER TABLE icinga_host_var + MODIFY COLUMN varname VARCHAR(255) NOT NULL COLLATE utf8_bin; + +ALTER TABLE icinga_service_var + MODIFY COLUMN varname VARCHAR(255) NOT NULL COLLATE utf8_bin; + +ALTER TABLE icinga_user_var + MODIFY COLUMN varname VARCHAR(255) NOT NULL COLLATE utf8_bin; + +ALTER TABLE icinga_notification_var + MODIFY COLUMN varname VARCHAR(255) NOT NULL COLLATE utf8_bin; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (108, NOW()); diff --git a/schema/mysql-migrations/upgrade_109.sql b/schema/mysql-migrations/upgrade_109.sql new file mode 100644 index 0000000..1989fa7 --- /dev/null +++ b/schema/mysql-migrations/upgrade_109.sql @@ -0,0 +1,16 @@ +CREATE TABLE icinga_hostgroup_assignment ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + hostgroup_id INT(10) UNSIGNED NOT NULL, + filter_string TEXT NOT NULL, + assign_type ENUM('assign', 'ignore') NOT NULL DEFAULT 'assign', + PRIMARY KEY (id), + CONSTRAINT icinga_hostgroup_assignment + FOREIGN KEY hostgroup (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (109, NOW()); diff --git a/schema/mysql-migrations/upgrade_110.sql b/schema/mysql-migrations/upgrade_110.sql new file mode 100644 index 0000000..800f7ab --- /dev/null +++ b/schema/mysql-migrations/upgrade_110.sql @@ -0,0 +1,104 @@ +UPDATE icinga_host_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_host_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_service_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_service_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + + +UPDATE icinga_command_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_command_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_user_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_user_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_notification_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_notification_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (110, NOW()); diff --git a/schema/mysql-migrations/upgrade_112.sql b/schema/mysql-migrations/upgrade_112.sql new file mode 100644 index 0000000..5336d35 --- /dev/null +++ b/schema/mysql-migrations/upgrade_112.sql @@ -0,0 +1,6 @@ +ALTER TABLE director_datalist_entry + MODIFY COLUMN entry_name VARCHAR(255) COLLATE utf8_bin NOT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (112, NOW()); diff --git a/schema/mysql-migrations/upgrade_114.sql b/schema/mysql-migrations/upgrade_114.sql new file mode 100644 index 0000000..24d3430 --- /dev/null +++ b/schema/mysql-migrations/upgrade_114.sql @@ -0,0 +1,55 @@ +CREATE TABLE icinga_service_set ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + object_name VARCHAR(128) NOT NULL, + object_type ENUM('object', 'template', 'external_object') NOT NULL, + host_id INT(10) UNSIGNED DEFAULT NULL, + description TEXT NOT NULL, + PRIMARY KEY (id), + UNIQUE KEY object_key (object_name, host_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_service_set_service ( + service_set_id INT(10) UNSIGNED NOT NULL, + service_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (service_set_id, service_id), + CONSTRAINT service_set_set + FOREIGN KEY service_set (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT service_set_service + FOREIGN KEY service (service_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_service_set_assignment ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + service_set_id INT(10) UNSIGNED NOT NULL, + filter_string TEXT NOT NULL, + assign_type ENUM('assign', 'ignore') NOT NULL DEFAULT 'assign', + PRIMARY KEY (id), + CONSTRAINT icinga_service_set_assignment + FOREIGN KEY service_set (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE icinga_service_set_var ( + service_set_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + varvalue TEXT DEFAULT NULL, + format ENUM('string', 'expression', 'json') NOT NULL DEFAULT 'string', + PRIMARY KEY (service_set_id, varname), + CONSTRAINT icinga_service_set_var_service + FOREIGN KEY command (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (114, NOW()); diff --git a/schema/mysql-migrations/upgrade_115.sql b/schema/mysql-migrations/upgrade_115.sql new file mode 100644 index 0000000..45f6236 --- /dev/null +++ b/schema/mysql-migrations/upgrade_115.sql @@ -0,0 +1,23 @@ +CREATE TABLE icinga_service_set_inheritance ( + service_set_id INT(10) UNSIGNED NOT NULL, + parent_service_set_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (service_set_id, parent_service_set_id), + UNIQUE KEY unique_order (service_set_id, weight), + CONSTRAINT icinga_service_set_inheritance_set + FOREIGN KEY host (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_set_inheritance_parent + FOREIGN KEY host (parent_service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE icinga_service_set MODIFY description TEXT DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (115, NOW()); diff --git a/schema/mysql-migrations/upgrade_116.sql b/schema/mysql-migrations/upgrade_116.sql new file mode 100644 index 0000000..a252d42 --- /dev/null +++ b/schema/mysql-migrations/upgrade_116.sql @@ -0,0 +1,18 @@ +ALTER TABLE sync_rule MODIFY object_type enum( + 'host', + 'service', + 'command', + 'user', + 'hostgroup', + 'servicegroup', + 'usergroup', + 'datalistEntry', + 'endpoint', + 'zone', + 'timePeriod', + 'serviceSet' +) NOT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (116, NOW()); diff --git a/schema/mysql-migrations/upgrade_117.sql b/schema/mysql-migrations/upgrade_117.sql new file mode 100644 index 0000000..e0ab4f3 --- /dev/null +++ b/schema/mysql-migrations/upgrade_117.sql @@ -0,0 +1,20 @@ +CREATE TABLE icinga_notification_field ( + notification_id INT(10) UNSIGNED NOT NULL COMMENT 'Makes only sense for templates', + datafield_id INT(10) UNSIGNED NOT NULL, + is_required ENUM('y', 'n') NOT NULL, + PRIMARY KEY (notification_id, datafield_id), + CONSTRAINT icinga_notification_field_notification + FOREIGN KEY notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_field_datafield + FOREIGN KEY datafield(datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (117, NOW()); diff --git a/schema/mysql-migrations/upgrade_119.sql b/schema/mysql-migrations/upgrade_119.sql new file mode 100644 index 0000000..c5fcf54 --- /dev/null +++ b/schema/mysql-migrations/upgrade_119.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_service + ADD COLUMN apply_for VARCHAR(255) DEFAULT NULL AFTER use_agent; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (119, NOW()); diff --git a/schema/mysql-migrations/upgrade_120.sql b/schema/mysql-migrations/upgrade_120.sql new file mode 100644 index 0000000..4020dea --- /dev/null +++ b/schema/mysql-migrations/upgrade_120.sql @@ -0,0 +1,184 @@ +ALTER TABLE icinga_service ADD COLUMN assign_filter TEXT DEFAULT NULL; + +UPDATE icinga_service s JOIN ( + + SELECT + service_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN sa.filter_string + ELSE GROUP_CONCAT(sa.filter_string SEPARATOR '&') END AS filter_string + FROM ( + SELECT + sa_not.service_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN sa_not.filter_string + ELSE '(' || GROUP_CONCAT(sa_not.filter_string SEPARATOR '&') || ')' END AS filter_string + FROM ( SELECT + sa.service_id, + '!' || sa.filter_string AS filter_string + FROM icinga_service_assignment sa + WHERE assign_type = 'ignore' + ) sa_not + GROUP BY service_id + + UNION ALL + + SELECT + sa_yes.service_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN sa_yes.filter_string + ELSE '(' || GROUP_CONCAT(sa_yes.filter_string SEPARATOR '|') || ')' END AS filter_string + FROM ( SELECT + sa.service_id, + sa.filter_string AS filter_string + FROM icinga_service_assignment sa + WHERE assign_type = 'assign' + ) sa_yes + GROUP BY service_id + + ) sa GROUP BY service_id + +) flat_assign ON s.id = flat_assign.service_id SET s.assign_filter = flat_assign.filter_string; + +DROP TABLE icinga_service_assignment; + +ALTER TABLE icinga_service_set ADD COLUMN assign_filter TEXT DEFAULT NULL; + +UPDATE icinga_service_set s JOIN ( + + SELECT + service_set_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN sa.filter_string + ELSE GROUP_CONCAT(sa.filter_string SEPARATOR '&') END AS filter_string + FROM ( + SELECT + sa_not.service_set_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN sa_not.filter_string + ELSE '(' || GROUP_CONCAT(sa_not.filter_string SEPARATOR '&') || ')' END AS filter_string + FROM ( SELECT + sa.service_set_id, + '!' || sa.filter_string AS filter_string + FROM icinga_service_set_assignment sa + WHERE assign_type = 'ignore' + ) sa_not + GROUP BY service_set_id + + UNION ALL + + SELECT + sa_yes.service_set_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN sa_yes.filter_string + ELSE '(' || GROUP_CONCAT(sa_yes.filter_string SEPARATOR '|') || ')' END AS filter_string + FROM ( SELECT + sa.service_set_id, + sa.filter_string AS filter_string + FROM icinga_service_set_assignment sa + WHERE assign_type = 'assign' + ) sa_yes + GROUP BY service_set_id + + ) sa GROUP BY service_set_id + +) flat_assign ON s.id = flat_assign.service_set_id SET s.assign_filter = flat_assign.filter_string; + +DROP TABLE icinga_service_set_assignment; + + +ALTER TABLE icinga_notification ADD COLUMN assign_filter TEXT DEFAULT NULL; + +UPDATE icinga_notification s JOIN ( + + SELECT + notification_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN sa.filter_string + ELSE GROUP_CONCAT(sa.filter_string SEPARATOR '&') END AS filter_string + FROM ( + SELECT + sa_not.notification_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN sa_not.filter_string + ELSE '(' || GROUP_CONCAT(sa_not.filter_string SEPARATOR '&') || ')' END AS filter_string + FROM ( SELECT + sa.notification_id, + '!' || sa.filter_string AS filter_string + FROM icinga_notification_assignment sa + WHERE assign_type = 'ignore' + ) sa_not + GROUP BY notification_id + + UNION ALL + + SELECT + sa_yes.notification_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN sa_yes.filter_string + ELSE '(' || GROUP_CONCAT(sa_yes.filter_string SEPARATOR '|') || ')' END AS filter_string + FROM ( SELECT + sa.notification_id, + sa.filter_string AS filter_string + FROM icinga_notification_assignment sa + WHERE assign_type = 'assign' + ) sa_yes + GROUP BY notification_id + + ) sa GROUP BY notification_id + +) flat_assign ON s.id = flat_assign.notification_id SET s.assign_filter = flat_assign.filter_string; + +DROP TABLE icinga_notification_assignment; + +ALTER TABLE icinga_hostgroup ADD COLUMN assign_filter TEXT DEFAULT NULL; + +UPDATE icinga_hostgroup s JOIN ( + + SELECT + hostgroup_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN sa.filter_string + ELSE GROUP_CONCAT(sa.filter_string SEPARATOR '&') END AS filter_string + FROM ( + SELECT + sa_not.hostgroup_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN sa_not.filter_string + ELSE '(' || GROUP_CONCAT(sa_not.filter_string SEPARATOR '&') || ')' END AS filter_string + FROM ( SELECT + sa.hostgroup_id, + '!' || sa.filter_string AS filter_string + FROM icinga_hostgroup_assignment sa + WHERE assign_type = 'ignore' + ) sa_not + GROUP BY hostgroup_id + + UNION ALL + + SELECT + sa_yes.hostgroup_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN sa_yes.filter_string + ELSE '(' || GROUP_CONCAT(sa_yes.filter_string SEPARATOR '|') || ')' END AS filter_string + FROM ( SELECT + sa.hostgroup_id, + sa.filter_string AS filter_string + FROM icinga_hostgroup_assignment sa + WHERE assign_type = 'assign' + ) sa_yes + GROUP BY hostgroup_id + + ) sa GROUP BY hostgroup_id + +) flat_assign ON s.id = flat_assign.hostgroup_id SET s.assign_filter = flat_assign.filter_string; + +DROP TABLE icinga_hostgroup_assignment; + + +ALTER TABLE icinga_servicegroup ADD COLUMN assign_filter TEXT DEFAULT NULL; + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (120, NOW()); diff --git a/schema/mysql-migrations/upgrade_121.sql b/schema/mysql-migrations/upgrade_121.sql new file mode 100644 index 0000000..24c307a --- /dev/null +++ b/schema/mysql-migrations/upgrade_121.sql @@ -0,0 +1,8 @@ +ALTER TABLE icinga_service + ADD COLUMN service_set_id INT(10) UNSIGNED DEFAULT NULL AFTER host_id; + +DROP TABLE icinga_service_set_service; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (121, NOW()); diff --git a/schema/mysql-migrations/upgrade_122.sql b/schema/mysql-migrations/upgrade_122.sql new file mode 100644 index 0000000..6a94e05 --- /dev/null +++ b/schema/mysql-migrations/upgrade_122.sql @@ -0,0 +1,12 @@ +ALTER TABLE director_generated_file + ADD COLUMN cnt_apply INT(10) UNSIGNED NOT NULL DEFAULT 0; + +UPDATE director_generated_file +SET cnt_apply = ROUND( + (LENGTH(content) - LENGTH( REPLACE(content, 'apply ', '') ) ) + / LENGTH('apply ') +); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (122, NOW()); diff --git a/schema/mysql-migrations/upgrade_123.sql b/schema/mysql-migrations/upgrade_123.sql new file mode 100644 index 0000000..024ed72 --- /dev/null +++ b/schema/mysql-migrations/upgrade_123.sql @@ -0,0 +1,30 @@ +-- cleanup dangling service_set before we add foreign key +DELETE ss FROM icinga_service_set AS ss + LEFT JOIN icinga_host AS h ON h.id = ss.host_id + WHERE ss.object_type = 'object' + AND ss.host_id IS NOT NULL + AND h.id IS NULL; + +-- cleanup dangling services to service_set +DELETE s FROM icinga_service AS s + LEFT JOIN icinga_service_set AS ss ON ss.id = s.service_set_id + WHERE s.object_type IN ('object', 'apply') + AND s.service_set_id IS NOT NULL + AND ss.id IS NULL; + + +ALTER TABLE icinga_service_set + ADD FOREIGN KEY icinga_service_set_host (host_id) + REFERENCES icinga_host (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE icinga_service + ADD FOREIGN KEY icinga_service_service_set (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration +(schema_version, migration_time) +VALUES (123, NOW()); diff --git a/schema/mysql-migrations/upgrade_124.sql b/schema/mysql-migrations/upgrade_124.sql new file mode 100644 index 0000000..c7e218f --- /dev/null +++ b/schema/mysql-migrations/upgrade_124.sql @@ -0,0 +1,3 @@ +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (124, NOW()); diff --git a/schema/mysql-migrations/upgrade_125.sql b/schema/mysql-migrations/upgrade_125.sql new file mode 100644 index 0000000..b1ffea1 --- /dev/null +++ b/schema/mysql-migrations/upgrade_125.sql @@ -0,0 +1,18 @@ +ALTER TABLE icinga_command_field + ADD COLUMN var_filter TEXT DEFAULT NULL; + +ALTER TABLE icinga_host_field + ADD COLUMN var_filter TEXT DEFAULT NULL; + +ALTER TABLE icinga_notification_field + ADD COLUMN var_filter TEXT DEFAULT NULL; + +ALTER TABLE icinga_service_field + ADD COLUMN var_filter TEXT DEFAULT NULL; + +ALTER TABLE icinga_user_field + ADD COLUMN var_filter TEXT DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (125, NOW()); diff --git a/schema/mysql-migrations/upgrade_126.sql b/schema/mysql-migrations/upgrade_126.sql new file mode 100644 index 0000000..d655eaa --- /dev/null +++ b/schema/mysql-migrations/upgrade_126.sql @@ -0,0 +1,217 @@ +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT * FROM information_schema.table_constraints + WHERE + table_schema = DATABASE() + AND table_name = 'icinga_service_set' + AND constraint_name = 'icinga_service_set_host' + )), + 'ALTER TABLE icinga_service_set DROP FOREIGN KEY icinga_service_set_host', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT * FROM information_schema.table_constraints + WHERE + table_schema = DATABASE() + AND table_name = 'icinga_service_set' + AND constraint_name = 'icinga_service_set_ibfk_1' + )), + 'ALTER TABLE icinga_service_set DROP FOREIGN KEY icinga_service_set_ibfk_1', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT * FROM information_schema.table_constraints + WHERE + table_schema = DATABASE() + AND table_name = 'icinga_service_set' + AND constraint_name = 'icinga_service_set_ibfk_2' + )), + 'ALTER TABLE icinga_service_set DROP FOREIGN KEY icinga_service_set_ibfk_2', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + + +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT * FROM information_schema.table_constraints + WHERE + table_schema = DATABASE() + AND table_name = 'icinga_service_set' + AND constraint_name = 'icinga_service_set_ibfk_3' + )), + 'ALTER TABLE icinga_service_set DROP FOREIGN KEY icinga_service_set_ibfk_3', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + + +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT * FROM information_schema.table_constraints + WHERE + table_schema = DATABASE() + AND table_name = 'icinga_service' + AND constraint_name = 'icinga_service_service_set' + )), + 'ALTER TABLE icinga_service DROP FOREIGN KEY icinga_service_service_set', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT * FROM information_schema.table_constraints + WHERE + table_schema = DATABASE() + AND table_name = 'icinga_service' + AND constraint_name = 'icinga_service_ibfk_1' + )), + 'ALTER TABLE icinga_service DROP FOREIGN KEY icinga_service_ibfk_1', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT 1 + FROM information_schema.statistics + WHERE table_schema = SCHEMA() + AND table_name = 'icinga_service' + AND index_name = 'icinga_service_service_set' + )), + 'ALTER TABLE icinga_service DROP INDEX icinga_service_service_set', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT 1 + FROM information_schema.statistics + WHERE table_schema = SCHEMA() + AND table_name = 'icinga_service_set' + AND index_name = 'icinga_service_set_ibfk_1' + )), + 'ALTER TABLE icinga_service_set DROP INDEX icinga_service_set_ibfk_1', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT 1 + FROM information_schema.statistics + WHERE table_schema = SCHEMA() + AND table_name = 'icinga_service_set' + AND index_name = 'icinga_service_set_host' + )), + 'ALTER TABLE icinga_service_set DROP INDEX icinga_service_set_host', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT 1 + FROM information_schema.statistics + WHERE table_schema = SCHEMA() + AND table_name = 'icinga_service' + AND index_name = 'icinga_service_ibfk_1' + )), + 'ALTER TABLE icinga_service_set DROP INDEX icinga_service_ibfk_1', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT 1 + FROM information_schema.statistics + WHERE table_schema = SCHEMA() + AND table_name = 'icinga_service_set' + AND index_name = 'icinga_service_set_ibfk_2' + )), + 'ALTER TABLE icinga_service_set DROP INDEX icinga_service_set_ibfk_2', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + +ALTER TABLE icinga_service_set + ADD CONSTRAINT icinga_service_set_host + FOREIGN KEY host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE; + +ALTER TABLE icinga_service + ADD CONSTRAINT icinga_service_service_set + FOREIGN KEY service_set (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (126, NOW()); diff --git a/schema/mysql-migrations/upgrade_127.sql b/schema/mysql-migrations/upgrade_127.sql new file mode 100644 index 0000000..575675e --- /dev/null +++ b/schema/mysql-migrations/upgrade_127.sql @@ -0,0 +1,152 @@ +ALTER TABLE icinga_command_var + ADD COLUMN checksum VARBINARY(20) DEFAULT NULL AFTER command_id, + ADD INDEX search_idx (varname), + ADD INDEX checksum (checksum); + +ALTER TABLE icinga_host_var + ADD COLUMN checksum VARBINARY(20) DEFAULT NULL AFTER host_id, + ADD INDEX checksum (checksum); + +ALTER TABLE icinga_notification_var + ADD COLUMN checksum VARBINARY(20) DEFAULT NULL AFTER notification_id, + ADD INDEX checksum (checksum); + +ALTER TABLE icinga_service_set_var + ADD COLUMN checksum VARBINARY(20) DEFAULT NULL AFTER service_set_id, + ADD INDEX search_idx (varname), + ADD INDEX checksum (checksum); + +ALTER TABLE icinga_service_var + ADD COLUMN checksum VARBINARY(20) DEFAULT NULL AFTER service_id, + ADD INDEX checksum (checksum); + +ALTER TABLE icinga_user_var + ADD COLUMN checksum VARBINARY(20) DEFAULT NULL AFTER user_id, + ADD INDEX checksum (checksum); + +CREATE TABLE icinga_var ( + checksum VARBINARY(20) NOT NULL, + rendered_checksum VARBINARY(20) NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + varvalue TEXT NOT NULL, + rendered TEXT NOT NULL, + PRIMARY KEY (checksum), + INDEX search_idx (varname) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_flat_var ( + var_checksum VARBINARY(20) NOT NULL, + flatname_checksum VARBINARY(20) NOT NULL, + flatname VARCHAR(512) NOT NULL COLLATE utf8_bin, + flatvalue TEXT NOT NULL, + PRIMARY KEY (var_checksum, flatname_checksum), + INDEX search_varname (flatname (191)), + INDEX search_varvalue (flatvalue (128)), + CONSTRAINT flat_var_var + FOREIGN KEY checksum (var_checksum) + REFERENCES icinga_var (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_command_resolved_var ( + command_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (command_id, checksum), + INDEX search_varname (varname), + CONSTRAINT command_resolved_var_command + FOREIGN KEY command (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT command_resolved_var_checksum + FOREIGN KEY checksum (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_host_resolved_var ( + host_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (host_id, checksum), + INDEX search_varname (varname), + FOREIGN KEY host_resolved_var_host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + FOREIGN KEY host_resolved_var_checksum (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_notification_resolved_var ( + notification_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (notification_id, checksum), + INDEX search_varname (varname), + FOREIGN KEY notification_resolved_var_notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + FOREIGN KEY notification_resolved_var_checksum (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_service_set_resolved_var ( + service_set_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (service_set_id, checksum), + INDEX search_varname (varname), + FOREIGN KEY service_set_resolved_var_service_set (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + FOREIGN KEY service_set_resolved_var_checksum(checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_service_resolved_var ( + service_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (service_id, checksum), + INDEX search_varname (varname), + FOREIGN KEY service_resolve_var_service (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + FOREIGN KEY service_resolve_var_checksum(checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_user_resolved_var ( + user_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (user_id, checksum), + INDEX search_varname (varname), + FOREIGN KEY user_resolve_var_user (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + FOREIGN KEY user_resolve_var_checksum(checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (127, NOW()); diff --git a/schema/mysql-migrations/upgrade_128.sql b/schema/mysql-migrations/upgrade_128.sql new file mode 100644 index 0000000..30e809c --- /dev/null +++ b/schema/mysql-migrations/upgrade_128.sql @@ -0,0 +1,6 @@ +ALTER TABLE director_activity_log + ADD INDEX search_author (author); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (128, NOW()); diff --git a/schema/mysql-migrations/upgrade_129.sql b/schema/mysql-migrations/upgrade_129.sql new file mode 100644 index 0000000..b47601c --- /dev/null +++ b/schema/mysql-migrations/upgrade_129.sql @@ -0,0 +1,6 @@ +ALTER TABLE director_datafield + MODIFY COLUMN varname VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (129, NOW()); diff --git a/schema/mysql-migrations/upgrade_130.sql b/schema/mysql-migrations/upgrade_130.sql new file mode 100644 index 0000000..c862d0d --- /dev/null +++ b/schema/mysql-migrations/upgrade_130.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_hostgroup + MODIFY object_type enum('object', 'template', 'external_object') NOT NULL; + +INSERT INTO director_schema_migration +(schema_version, migration_time) +VALUES (130, NOW()); diff --git a/schema/mysql-migrations/upgrade_131.sql b/schema/mysql-migrations/upgrade_131.sql new file mode 100644 index 0000000..282e060 --- /dev/null +++ b/schema/mysql-migrations/upgrade_131.sql @@ -0,0 +1,19 @@ +CREATE TABLE icinga_hostgroup_host_resolved ( + hostgroup_id INT(10) UNSIGNED NOT NULL, + host_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (hostgroup_id, host_id), + CONSTRAINT icinga_hostgroup_host_resolved_host + FOREIGN KEY host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_hostgroup_host_resolved_hostgroup + FOREIGN KEY hostgroup (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration +(schema_version, migration_time) +VALUES (131, NOW()); diff --git a/schema/mysql-migrations/upgrade_132.sql b/schema/mysql-migrations/upgrade_132.sql new file mode 100644 index 0000000..76be96f --- /dev/null +++ b/schema/mysql-migrations/upgrade_132.sql @@ -0,0 +1,21 @@ +CREATE TABLE icinga_host_template_choice ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + object_name VARCHAR(64) NOT NULL, + description TEXT DEFAULT NULL, + min_required SMALLINT UNSIGNED NOT NULL DEFAULT 0, + max_allowed SMALLINT UNSIGNED NOT NULL DEFAULT 1, + PRIMARY KEY (id), + UNIQUE KEY (object_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE icinga_host + ADD COLUMN template_choice_id INT(10) UNSIGNED DEFAULT NULL, + ADD CONSTRAINT icinga_host_template_choice + FOREIGN KEY choice (template_choice_id) + REFERENCES icinga_host_template_choice (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration +(schema_version, migration_time) +VALUES (132, NOW()); diff --git a/schema/mysql-migrations/upgrade_133.sql b/schema/mysql-migrations/upgrade_133.sql new file mode 100644 index 0000000..9f1a474 --- /dev/null +++ b/schema/mysql-migrations/upgrade_133.sql @@ -0,0 +1,21 @@ +CREATE TABLE icinga_service_template_choice ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + object_name VARCHAR(64) NOT NULL, + description TEXT DEFAULT NULL, + min_required SMALLINT UNSIGNED NOT NULL DEFAULT 0, + max_allowed SMALLINT UNSIGNED NOT NULL DEFAULT 1, + PRIMARY KEY (id), + UNIQUE KEY (object_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE icinga_service + ADD COLUMN template_choice_id INT(10) UNSIGNED DEFAULT NULL, + ADD CONSTRAINT icinga_service_template_choice + FOREIGN KEY choice (template_choice_id) + REFERENCES icinga_service_template_choice (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration +(schema_version, migration_time) +VALUES (133, NOW()); diff --git a/schema/mysql-migrations/upgrade_134.sql b/schema/mysql-migrations/upgrade_134.sql new file mode 100644 index 0000000..b652e5b --- /dev/null +++ b/schema/mysql-migrations/upgrade_134.sql @@ -0,0 +1,19 @@ +ALTER TABLE icinga_host + DROP FOREIGN KEY icinga_host_template_choice, + ADD CONSTRAINT icinga_host_template_choice_v2 + FOREIGN KEY template_choice (template_choice_id) + REFERENCES icinga_host_template_choice (id) + ON DELETE SET NULL + ON UPDATE CASCADE; + +ALTER TABLE icinga_service + DROP FOREIGN KEY icinga_service_template_choice, + ADD CONSTRAINT icinga_service_template_choice_v2 + FOREIGN KEY template_choice (template_choice_id) + REFERENCES icinga_service_template_choice (id) + ON DELETE SET NULL + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (134, NOW()); diff --git a/schema/mysql-migrations/upgrade_135.sql b/schema/mysql-migrations/upgrade_135.sql new file mode 100644 index 0000000..6a1d687 --- /dev/null +++ b/schema/mysql-migrations/upgrade_135.sql @@ -0,0 +1,9 @@ +ALTER TABLE icinga_host + ADD COLUMN check_timeout SMALLINT UNSIGNED DEFAULT NULL AFTER retry_interval; + +ALTER TABLE icinga_service + ADD COLUMN check_timeout SMALLINT UNSIGNED DEFAULT NULL AFTER retry_interval; + +INSERT INTO director_schema_migration +(schema_version, migration_time) +VALUES (135, NOW()); diff --git a/schema/mysql-migrations/upgrade_136.sql b/schema/mysql-migrations/upgrade_136.sql new file mode 100644 index 0000000..d308062 --- /dev/null +++ b/schema/mysql-migrations/upgrade_136.sql @@ -0,0 +1,6 @@ +ALTER TABLE director_datalist_entry + ADD COLUMN allowed_roles VARCHAR(255) DEFAULT NULL; + +INSERT INTO director_schema_migration +(schema_version, migration_time) +VALUES (136, NOW()); diff --git a/schema/mysql-migrations/upgrade_137.sql b/schema/mysql-migrations/upgrade_137.sql new file mode 100644 index 0000000..535d2bc --- /dev/null +++ b/schema/mysql-migrations/upgrade_137.sql @@ -0,0 +1,9 @@ +ALTER TABLE import_source + ADD COLUMN description TEXT DEFAULT NULL; + +ALTER TABLE sync_rule + ADD COLUMN description TEXT DEFAULT NULL; + +INSERT INTO director_schema_migration +(schema_version, migration_time) +VALUES (137, NOW()); diff --git a/schema/mysql-migrations/upgrade_138.sql b/schema/mysql-migrations/upgrade_138.sql new file mode 100644 index 0000000..8561c00 --- /dev/null +++ b/schema/mysql-migrations/upgrade_138.sql @@ -0,0 +1,6 @@ +ALTER TABLE import_row_modifier + ADD COLUMN description TEXT DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (138, NOW()); diff --git a/schema/mysql-migrations/upgrade_139.sql b/schema/mysql-migrations/upgrade_139.sql new file mode 100644 index 0000000..817244b --- /dev/null +++ b/schema/mysql-migrations/upgrade_139.sql @@ -0,0 +1,7 @@ +UPDATE import_row_modifier SET priority = id; + +ALTER TABLE import_row_modifier ADD UNIQUE INDEX idx_prio (source_id, priority); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (139, NOW()); diff --git a/schema/mysql-migrations/upgrade_140.sql b/schema/mysql-migrations/upgrade_140.sql new file mode 100644 index 0000000..996e9ef --- /dev/null +++ b/schema/mysql-migrations/upgrade_140.sql @@ -0,0 +1,5 @@ +UPDATE sync_property SET priority = 10000 - priority; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (140, NOW()); diff --git a/schema/mysql-migrations/upgrade_141.sql b/schema/mysql-migrations/upgrade_141.sql new file mode 100644 index 0000000..a382208 --- /dev/null +++ b/schema/mysql-migrations/upgrade_141.sql @@ -0,0 +1,7 @@ +UPDATE icinga_service_set + SET object_type = 'template' + WHERE object_type = 'object' AND host_id IS NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (141, NOW()); diff --git a/schema/mysql-migrations/upgrade_143.sql b/schema/mysql-migrations/upgrade_143.sql new file mode 100644 index 0000000..7d07385 --- /dev/null +++ b/schema/mysql-migrations/upgrade_143.sql @@ -0,0 +1,21 @@ +ALTER TABLE icinga_host_template_choice + ADD COLUMN required_template_id INT(10) UNSIGNED DEFAULT NULL, + ADD COLUMN allowed_roles VARCHAR(255) DEFAULT NULL, + ADD CONSTRAINT host_template_choice_required_template + FOREIGN KEY required_template (required_template_id) + REFERENCES icinga_host (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE icinga_service_template_choice + ADD COLUMN required_template_id INT(10) UNSIGNED DEFAULT NULL, + ADD COLUMN allowed_roles VARCHAR(255) DEFAULT NULL, + ADD CONSTRAINT service_template_choice_required_template + FOREIGN KEY required_template (required_template_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (143, NOW()); diff --git a/schema/mysql-migrations/upgrade_144.sql b/schema/mysql-migrations/upgrade_144.sql new file mode 100644 index 0000000..fff6f8f --- /dev/null +++ b/schema/mysql-migrations/upgrade_144.sql @@ -0,0 +1,91 @@ +CREATE TABLE icinga_dependency ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'apply') NOT NULL, + disabled ENUM('y', 'n') NOT NULL DEFAULT 'n', + apply_to ENUM('host', 'service') DEFAULT NULL, + parent_host_id INT(10) UNSIGNED DEFAULT NULL, + parent_service_id INT(10) UNSIGNED DEFAULT NULL, + child_host_id INT(10) UNSIGNED DEFAULT NULL, + child_service_id INT(10) UNSIGNED DEFAULT NULL, + disable_checks ENUM('y', 'n') DEFAULT NULL, + disable_notifications ENUM('y', 'n') DEFAULT NULL, + ignore_soft_states ENUM('y', 'n') DEFAULT NULL, + period_id INT(10) UNSIGNED DEFAULT NULL, + zone_id INT(10) UNSIGNED DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + parent_service_by_name VARCHAR(255) DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_dependency_parent_host + FOREIGN KEY parent_host (parent_host_id) + REFERENCES icinga_host (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_parent_service + FOREIGN KEY parent_service (parent_service_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_child_host + FOREIGN KEY child_host (child_host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_child_service + FOREIGN KEY child_service (child_service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_period + FOREIGN KEY period (period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_zone + FOREIGN KEY zone (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_dependency_inheritance ( + dependency_id INT(10) UNSIGNED NOT NULL, + parent_dependency_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (dependency_id, parent_dependency_id), + UNIQUE KEY unique_order (dependency_id, weight), + CONSTRAINT icinga_dependency_inheritance_dependency + FOREIGN KEY dependency (dependency_id) + REFERENCES icinga_dependency (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_inheritance_parent_dependency + FOREIGN KEY parent_dependency (parent_dependency_id) + REFERENCES icinga_dependency (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_dependency_states_set ( + dependency_id INT(10) UNSIGNED NOT NULL, + property ENUM( + 'OK', + 'Warning', + 'Critical', + 'Unknown', + 'Up', + 'Down' + ) NOT NULL, + merge_behaviour ENUM('override', 'extend', 'blacklist') NOT NULL DEFAULT 'override' + COMMENT 'override: = [], extend: += [], blacklist: -= []', + PRIMARY KEY (dependency_id, property, merge_behaviour), + CONSTRAINT icinga_dependency_states_set_dependency + FOREIGN KEY icinga_dependency (dependency_id) + REFERENCES icinga_dependency (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (144, NOW()); diff --git a/schema/mysql-migrations/upgrade_145.sql b/schema/mysql-migrations/upgrade_145.sql new file mode 100644 index 0000000..a0e1853 --- /dev/null +++ b/schema/mysql-migrations/upgrade_145.sql @@ -0,0 +1,7 @@ +ALTER TABLE import_row_modifier + ADD INDEX source_id (source_id), + DROP INDEX idx_prio; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (145, NOW()); diff --git a/schema/mysql-migrations/upgrade_146.sql b/schema/mysql-migrations/upgrade_146.sql new file mode 100644 index 0000000..0520219 --- /dev/null +++ b/schema/mysql-migrations/upgrade_146.sql @@ -0,0 +1,14 @@ +ALTER TABLE icinga_host + DROP COLUMN flapping_threshold, + ADD COLUMN flapping_threshold_high SMALLINT UNSIGNED DEFAULT NULL, + ADD COLUMN flapping_threshold_low SMALLINT UNSIGNED DEFAULT NULL; + +ALTER TABLE icinga_service + DROP COLUMN flapping_threshold, + ADD COLUMN flapping_threshold_high SMALLINT UNSIGNED DEFAULT NULL, + ADD COLUMN flapping_threshold_low SMALLINT UNSIGNED DEFAULT NULL; + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (146, NOW()); diff --git a/schema/mysql-migrations/upgrade_147.sql b/schema/mysql-migrations/upgrade_147.sql new file mode 100644 index 0000000..d609cda --- /dev/null +++ b/schema/mysql-migrations/upgrade_147.sql @@ -0,0 +1,20 @@ +CREATE TABLE icinga_host_service_blacklist ( + host_id INT(10) UNSIGNED NOT NULL, + service_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (host_id, service_id), + CONSTRAINT icinga_host_service_bl_host + FOREIGN KEY host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_service_bl_service + FOREIGN KEY service (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (147, NOW()); diff --git a/schema/mysql-migrations/upgrade_148.sql b/schema/mysql-migrations/upgrade_148.sql new file mode 100644 index 0000000..2d15c82 --- /dev/null +++ b/schema/mysql-migrations/upgrade_148.sql @@ -0,0 +1,10 @@ +ALTER TABLE import_source + MODIFY provider_class VARCHAR(128) NOT NULL; + +ALTER TABLE import_row_modifier + MODIFY provider_class VARCHAR(128) NOT NULL; + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (148, NOW()); diff --git a/schema/mysql-migrations/upgrade_149.sql b/schema/mysql-migrations/upgrade_149.sql new file mode 100644 index 0000000..5940311 --- /dev/null +++ b/schema/mysql-migrations/upgrade_149.sql @@ -0,0 +1,11 @@ +ALTER TABLE icinga_usergroup + ADD COLUMN zone_id INT(10) UNSIGNED DEFAULT NULL, + ADD CONSTRAINT icinga_usergroup_zone + FOREIGN KEY zone (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (149, NOW()); diff --git a/schema/mysql-migrations/upgrade_150.sql b/schema/mysql-migrations/upgrade_150.sql new file mode 100644 index 0000000..92a7a6d --- /dev/null +++ b/schema/mysql-migrations/upgrade_150.sql @@ -0,0 +1,17 @@ +UPDATE icinga_user u +SET period_id = NULL +WHERE NOT EXISTS ( + SELECT id FROM icinga_timeperiod + WHERE id = u.period_id +) AND u.period_id IS NOT NULL; + +ALTER TABLE icinga_user + ADD CONSTRAINT icinga_user_period + FOREIGN KEY period (period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (150, NOW()); diff --git a/schema/mysql-migrations/upgrade_151.sql b/schema/mysql-migrations/upgrade_151.sql new file mode 100644 index 0000000..a811fd4 --- /dev/null +++ b/schema/mysql-migrations/upgrade_151.sql @@ -0,0 +1,38 @@ +ALTER TABLE icinga_timeperiod + ADD COLUMN prefer_includes ENUM('y', 'n') DEFAULT NULL; + +CREATE TABLE icinga_timeperiod_include ( + timeperiod_id INT(10) UNSIGNED NOT NULL, + include_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (timeperiod_id, include_id), + CONSTRAINT icinga_timeperiod_include + FOREIGN KEY timeperiod (include_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE RESTRICT, + CONSTRAINT icinga_timeperiod_include_timeperiod + FOREIGN KEY include (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE TABLE icinga_timeperiod_exclude ( + timeperiod_id INT(10) UNSIGNED NOT NULL, + exclude_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (timeperiod_id, exclude_id), + CONSTRAINT icinga_timeperiod_exclude + FOREIGN KEY timeperiod (exclude_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE RESTRICT, + CONSTRAINT icinga_timeperiod_exclude_timeperiod + FOREIGN KEY exclude (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (151, NOW()); diff --git a/schema/mysql-migrations/upgrade_152.sql b/schema/mysql-migrations/upgrade_152.sql new file mode 100644 index 0000000..91e8eea --- /dev/null +++ b/schema/mysql-migrations/upgrade_152.sql @@ -0,0 +1,9 @@ +ALTER TABLE import_source + ADD UNIQUE INDEX source_name (source_name); + +ALTER TABLE sync_rule + ADD UNIQUE INDEX rule_name (rule_name); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (152, NOW()); diff --git a/schema/mysql-migrations/upgrade_153.sql b/schema/mysql-migrations/upgrade_153.sql new file mode 100644 index 0000000..fa85130 --- /dev/null +++ b/schema/mysql-migrations/upgrade_153.sql @@ -0,0 +1,42 @@ +CREATE TABLE director_basket ( + uuid VARBINARY(16) NOT NULL, + basket_name VARCHAR(64) NOT NULL, + owner_type ENUM( + 'user', + 'usergroup', + 'role' + ) NOT NULL, + owner_value VARCHAR(255) NOT NULL, + objects MEDIUMTEXT NOT NULL, -- json-encoded + PRIMARY KEY (uuid), + UNIQUE INDEX basket_name (basket_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_bin; + +CREATE TABLE director_basket_content ( + checksum VARBINARY(20) NOT NULL, + summary VARCHAR(255) NOT NULL, -- json + content MEDIUMTEXT NOT NULL, -- json + PRIMARY KEY (checksum) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_bin; + +CREATE TABLE director_basket_snapshot ( + basket_uuid VARBINARY(16) NOT NULL, + ts_create BIGINT(20) NOT NULL, + content_checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (basket_uuid, ts_create), + INDEX sort_idx (ts_create), + CONSTRAINT basked_snapshot_basket + FOREIGN KEY director_basket_snapshot (basket_uuid) + REFERENCES director_basket (uuid) + ON DELETE CASCADE + ON UPDATE RESTRICT, + CONSTRAINT basked_snapshot_content + FOREIGN KEY content_checksum (content_checksum) + REFERENCES director_basket_content (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_bin; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (153, NOW()); diff --git a/schema/mysql-migrations/upgrade_154.sql b/schema/mysql-migrations/upgrade_154.sql new file mode 100644 index 0000000..08274b0 --- /dev/null +++ b/schema/mysql-migrations/upgrade_154.sql @@ -0,0 +1,12 @@ + +UPDATE icinga_command_argument +SET argument_format = NULL +WHERE argument_value IS NULL; + +UPDATE icinga_command_argument +SET set_if_format = NULL +WHERE set_if IS NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (154, NOW()); diff --git a/schema/mysql-migrations/upgrade_155.sql b/schema/mysql-migrations/upgrade_155.sql new file mode 100644 index 0000000..eab331f --- /dev/null +++ b/schema/mysql-migrations/upgrade_155.sql @@ -0,0 +1,19 @@ +CREATE TABLE icinga_servicegroup_service_resolved ( + servicegroup_id INT(10) UNSIGNED NOT NULL, + service_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (servicegroup_id, service_id), + CONSTRAINT icinga_servicegroup_service_resolved_service + FOREIGN KEY service (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_servicegroup_service_resolved_servicegroup + FOREIGN KEY servicegroup (servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (155, NOW()); diff --git a/schema/mysql-migrations/upgrade_156.sql b/schema/mysql-migrations/upgrade_156.sql new file mode 100644 index 0000000..cd13edf --- /dev/null +++ b/schema/mysql-migrations/upgrade_156.sql @@ -0,0 +1,7 @@ +ALTER TABLE icinga_command + DROP INDEX object_name, +ADD UNIQUE INDEX object_name (object_name); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (156, NOW()); diff --git a/schema/mysql-migrations/upgrade_157.sql b/schema/mysql-migrations/upgrade_157.sql new file mode 100644 index 0000000..f093a88 --- /dev/null +++ b/schema/mysql-migrations/upgrade_157.sql @@ -0,0 +1,6 @@ +ALTER TABLE director_basket_content + MODIFY COLUMN summary VARCHAR(500) NOT NULL; + + INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (157, NOW()); diff --git a/schema/mysql-migrations/upgrade_159.sql b/schema/mysql-migrations/upgrade_159.sql new file mode 100644 index 0000000..4de3cc6 --- /dev/null +++ b/schema/mysql-migrations/upgrade_159.sql @@ -0,0 +1,6 @@ +ALTER TABLE director_generated_file + MODIFY COLUMN content LONGTEXT NOT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (159, NOW()); diff --git a/schema/mysql-migrations/upgrade_160.sql b/schema/mysql-migrations/upgrade_160.sql new file mode 100644 index 0000000..3afbf47 --- /dev/null +++ b/schema/mysql-migrations/upgrade_160.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_command + ADD COLUMN is_string enum ('y', 'n') NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (160, NOW()); diff --git a/schema/mysql-migrations/upgrade_161.sql b/schema/mysql-migrations/upgrade_161.sql new file mode 100644 index 0000000..f8134a4 --- /dev/null +++ b/schema/mysql-migrations/upgrade_161.sql @@ -0,0 +1,58 @@ +CREATE TABLE icinga_scheduled_downtime ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + object_name VARCHAR(255) NOT NULL, + zone_id INT(10) UNSIGNED DEFAULT NULL, + object_type ENUM('object', 'template', 'apply') NOT NULL, + disabled ENUM('y', 'n') NOT NULL DEFAULT 'n', + apply_to ENUM('host', 'service') DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + author VARCHAR(255) DEFAULT NULL, + comment TEXT DEFAULT NULL, + fixed ENUM('y', 'n') DEFAULT NULL, + duration INT(10) UNSIGNED DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE INDEX object_name (object_name), + CONSTRAINT icinga_scheduled_downtime_zone + FOREIGN KEY zone (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_scheduled_downtime_inheritance ( + scheduled_downtime_id INT(10) UNSIGNED NOT NULL, + parent_scheduled_downtime_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (scheduled_downtime_id, parent_scheduled_downtime_id), + UNIQUE KEY unique_order (scheduled_downtime_id, weight), + CONSTRAINT icinga_scheduled_downtime_inheritance_downtime + FOREIGN KEY host (scheduled_downtime_id) + REFERENCES icinga_scheduled_downtime (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_scheduled_downtime_inheritance_parent_downtime + FOREIGN KEY host (parent_scheduled_downtime_id) + REFERENCES icinga_scheduled_downtime (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_scheduled_downtime_range ( + scheduled_downtime_id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + range_key VARCHAR(255) NOT NULL COMMENT 'monday, ...', + range_value VARCHAR(255) NOT NULL COMMENT '00:00-24:00, ...', + range_type ENUM('include', 'exclude') NOT NULL DEFAULT 'include' + COMMENT 'include -> ranges {}, exclude ranges_ignore {} - not yet', + merge_behaviour ENUM('set', 'add', 'substract') NOT NULL DEFAULT 'set' + COMMENT 'set -> = {}, add -> += {}, substract -> -= {}', + PRIMARY KEY (scheduled_downtime_id, range_type, range_key), + CONSTRAINT icinga_scheduled_downtime_range_downtime + FOREIGN KEY scheduled_downtime (scheduled_downtime_id) + REFERENCES icinga_scheduled_downtime (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (161, NOW()); diff --git a/schema/mysql-migrations/upgrade_162.sql b/schema/mysql-migrations/upgrade_162.sql new file mode 100644 index 0000000..7af104a --- /dev/null +++ b/schema/mysql-migrations/upgrade_162.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_scheduled_downtime + ADD COLUMN with_services ENUM('y', 'n') NULL DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (162, NOW()); diff --git a/schema/mysql-migrations/upgrade_163.sql b/schema/mysql-migrations/upgrade_163.sql new file mode 100644 index 0000000..610c0f6 --- /dev/null +++ b/schema/mysql-migrations/upgrade_163.sql @@ -0,0 +1,38 @@ +-- when applying manually make sure to set a sensible timezone for your users +-- otherwise the server / client timezone will be used! + +-- SET time_zone = '+02:00'; + +SET sql_mode = 'STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES,ERROR_FOR_DIVISION_BY_ZERO'; + +ALTER TABLE director_activity_log + MODIFY change_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; + +ALTER TABLE director_deployment_log + MODIFY start_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + MODIFY end_time TIMESTAMP NULL DEFAULT NULL, + MODIFY abort_time TIMESTAMP NULL DEFAULT NULL; + +ALTER TABLE director_schema_migration + MODIFY migration_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; + +ALTER TABLE director_job + MODIFY ts_last_attempt TIMESTAMP NULL DEFAULT NULL, + MODIFY ts_last_error TIMESTAMP NULL DEFAULT NULL; + +ALTER TABLE import_source + MODIFY last_attempt TIMESTAMP NULL DEFAULT NULL; + +ALTER TABLE import_run + MODIFY start_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + MODIFY end_time TIMESTAMP NULL DEFAULT NULL; + +ALTER TABLE sync_rule + MODIFY last_attempt TIMESTAMP NULL DEFAULT NULL; + +ALTER TABLE sync_run + MODIFY start_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (163, NOW()); diff --git a/schema/mysql-migrations/upgrade_164.sql b/schema/mysql-migrations/upgrade_164.sql new file mode 100644 index 0000000..19dec3d --- /dev/null +++ b/schema/mysql-migrations/upgrade_164.sql @@ -0,0 +1,8 @@ +SET sql_mode = 'STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES,ERROR_FOR_DIVISION_BY_ZERO'; + +ALTER TABLE icinga_dependency + ADD COLUMN parent_host_var VARCHAR(128) DEFAULT NULL AFTER parent_host_id; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (164, NOW()); diff --git a/schema/mysql-migrations/upgrade_165.sql b/schema/mysql-migrations/upgrade_165.sql new file mode 100644 index 0000000..dec47ce --- /dev/null +++ b/schema/mysql-migrations/upgrade_165.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_host + MODIFY COLUMN address VARCHAR(255) DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (165, NOW()); diff --git a/schema/mysql-migrations/upgrade_166.sql b/schema/mysql-migrations/upgrade_166.sql new file mode 100644 index 0000000..92b56f3 --- /dev/null +++ b/schema/mysql-migrations/upgrade_166.sql @@ -0,0 +1,21 @@ +ALTER TABLE sync_rule MODIFY object_type enum( + 'host', + 'service', + 'command', + 'user', + 'hostgroup', + 'servicegroup', + 'usergroup', + 'datalistEntry', + 'endpoint', + 'zone', + 'timePeriod', + 'serviceSet', + 'scheduledDowntime', + 'notification', + 'dependency' +) NOT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (166, NOW()); diff --git a/schema/mysql-migrations/upgrade_167.sql b/schema/mysql-migrations/upgrade_167.sql new file mode 100644 index 0000000..7a33bec --- /dev/null +++ b/schema/mysql-migrations/upgrade_167.sql @@ -0,0 +1,25 @@ +CREATE TABLE director_daemon_info ( + instance_uuid_hex VARCHAR(32) NOT NULL, -- random by daemon + schema_version SMALLINT UNSIGNED NOT NULL, + fqdn VARCHAR(255) NOT NULL, + username VARCHAR(64) NOT NULL, + pid INT UNSIGNED NOT NULL, + binary_path VARCHAR(128) NOT NULL, + binary_realpath VARCHAR(128) NOT NULL, + php_binary_path VARCHAR(128) NOT NULL, + php_binary_realpath VARCHAR(128) NOT NULL, + php_version VARCHAR(64) NOT NULL, + php_integer_size SMALLINT NOT NULL, + running_with_systemd ENUM('y', 'n') NOT NULL, + ts_started BIGINT(20) NOT NULL, + ts_stopped BIGINT(20) DEFAULT NULL, + ts_last_modification BIGINT(20) DEFAULT NULL, + ts_last_update BIGINT(20) DEFAULT NULL, + process_info MEDIUMTEXT NOT NULL, + PRIMARY KEY (instance_uuid_hex) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_bin; + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (167, NOW()); diff --git a/schema/mysql-migrations/upgrade_168.sql b/schema/mysql-migrations/upgrade_168.sql new file mode 100644 index 0000000..27934ae --- /dev/null +++ b/schema/mysql-migrations/upgrade_168.sql @@ -0,0 +1,21 @@ +CREATE TABLE director_datafield_category ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + category_name VARCHAR(255) NOT NULL, + description TEXT DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY category_name (category_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE director_datafield + ADD COLUMN category_id INT(10) UNSIGNED DEFAULT NULL AFTER id, + ADD CONSTRAINT director_datafield_category + FOREIGN KEY category (category_id) + REFERENCES director_datafield_category (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +; + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (168, NOW()); diff --git a/schema/mysql-migrations/upgrade_170.sql b/schema/mysql-migrations/upgrade_170.sql new file mode 100644 index 0000000..e259a79 --- /dev/null +++ b/schema/mysql-migrations/upgrade_170.sql @@ -0,0 +1,7 @@ + +ALTER TABLE sync_rule + MODIFY COLUMN update_policy ENUM('merge', 'override', 'ignore', 'update-only') NOT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (170, NOW()); diff --git a/schema/mysql-migrations/upgrade_171.sql b/schema/mysql-migrations/upgrade_171.sql new file mode 100644 index 0000000..76ab309 --- /dev/null +++ b/schema/mysql-migrations/upgrade_171.sql @@ -0,0 +1,3 @@ +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (171, NOW()); diff --git a/schema/mysql-migrations/upgrade_172.sql b/schema/mysql-migrations/upgrade_172.sql new file mode 100644 index 0000000..3af3571 --- /dev/null +++ b/schema/mysql-migrations/upgrade_172.sql @@ -0,0 +1,11 @@ +ALTER TABLE sync_rule + ADD COLUMN purge_action ENUM('delete', 'disable') NULL DEFAULT NULL AFTER purge_existing; + +UPDATE sync_rule SET purge_action = 'delete'; + +ALTER TABLE sync_rule + MODIFY COLUMN purge_action ENUM('delete', 'disable') DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (172, NOW()); diff --git a/schema/mysql-migrations/upgrade_173.sql b/schema/mysql-migrations/upgrade_173.sql new file mode 100644 index 0000000..609f783 --- /dev/null +++ b/schema/mysql-migrations/upgrade_173.sql @@ -0,0 +1,6 @@ +ALTER TABLE sync_rule + MODIFY COLUMN purge_action ENUM('delete', 'disable') NULL DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (173, NOW()); diff --git a/schema/mysql-migrations/upgrade_174.sql b/schema/mysql-migrations/upgrade_174.sql new file mode 100644 index 0000000..653cb42 --- /dev/null +++ b/schema/mysql-migrations/upgrade_174.sql @@ -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()); diff --git a/schema/mysql-migrations/upgrade_175.sql b/schema/mysql-migrations/upgrade_175.sql new file mode 100644 index 0000000..b8a010f --- /dev/null +++ b/schema/mysql-migrations/upgrade_175.sql @@ -0,0 +1,484 @@ +CREATE TABLE director_branch ( + uuid VARBINARY(16) NOT NULL, + owner VARCHAR(255) NOT NULL, + branch_name VARCHAR(255) NOT NULL, + description TEXT DEFAULT NULL, + ts_merge_request BIGINT DEFAULT NULL, + PRIMARY KEY(uuid), + UNIQUE KEY (branch_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_branch_activity ( + timestamp_ns BIGINT(20) NOT NULL, + object_uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + action ENUM ('create', 'modify', 'delete') NOT NULL, + object_table VARCHAR(64) NOT NULL, + author VARCHAR(255) NOT NULL, + former_properties LONGTEXT NOT NULL, -- json-encoded + modified_properties LONGTEXT NOT NULL, + PRIMARY KEY (timestamp_ns), + INDEX object_uuid (object_uuid), + INDEX branch_uuid (branch_uuid), + CONSTRAINT branch_activity_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_host ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + address VARCHAR(255) DEFAULT NULL, + address6 VARCHAR(45) DEFAULT NULL, + check_command VARCHAR(255) DEFAULT NULL, + max_check_attempts MEDIUMINT UNSIGNED DEFAULT NULL, + check_period VARCHAR(255) DEFAULT NULL, + check_interval VARCHAR(8) DEFAULT NULL, + retry_interval VARCHAR(8) DEFAULT NULL, + check_timeout SMALLINT UNSIGNED DEFAULT NULL, + enable_notifications ENUM('y', 'n') DEFAULT NULL, + enable_active_checks ENUM('y', 'n') DEFAULT NULL, + enable_passive_checks ENUM('y', 'n') DEFAULT NULL, + enable_event_handler ENUM('y', 'n') DEFAULT NULL, + enable_flapping ENUM('y', 'n') DEFAULT NULL, + enable_perfdata ENUM('y', 'n') DEFAULT NULL, + event_command VARCHAR(255) DEFAULT NULL, + flapping_threshold_high SMALLINT UNSIGNED DEFAULT NULL, + flapping_threshold_low SMALLINT UNSIGNED DEFAULT NULL, + volatile ENUM('y', 'n') DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + command_endpoint VARCHAR(255) DEFAULT NULL, + notes TEXT DEFAULT NULL, + notes_url VARCHAR(255) DEFAULT NULL, + action_url VARCHAR(255) DEFAULT NULL, + icon_image VARCHAR(255) DEFAULT NULL, + icon_image_alt VARCHAR(255) DEFAULT NULL, + has_agent ENUM('y', 'n') DEFAULT NULL, + master_should_connect ENUM('y', 'n') DEFAULT NULL, + accept_config ENUM('y', 'n') DEFAULT NULL, + api_key VARCHAR(40) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + `groups` TEXT DEFAULT NULL, + vars MEDIUMTEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_host_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_hostgroup ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_hostgroup_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_servicegroup ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_servicegroup_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_usergroup ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_usergroup_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_user ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + email VARCHAR(255) DEFAULT NULL, + pager VARCHAR(255) DEFAULT NULL, + enable_notifications ENUM('y', 'n') DEFAULT NULL, + period VARCHAR(255) DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + states TEXT DEFAULT NULL, + types TEXT DEFAULT NULL, + + imports TEXT DEFAULT NULL, + `groups` TEXT DEFAULT NULL, + vars MEDIUMTEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_user_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_zone ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + parent VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + is_global ENUM('y', 'n') DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_zone_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_timeperiod ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + update_method VARCHAR(64) DEFAULT NULL COMMENT 'Usually LegacyTimePeriod', + zone VARCHAR(255) DEFAULT NULL, + prefer_includes ENUM('y', 'n') DEFAULT NULL, + + imports TEXT DEFAULT NULL, + ranges TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_timeperiod_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_command ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + methods_execute VARCHAR(64) DEFAULT NULL, + command TEXT DEFAULT NULL, + is_string ENUM('y', 'n') NULL, + timeout SMALLINT UNSIGNED DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + arguments TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_command_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_apiuser ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + password VARCHAR(255) DEFAULT NULL, + client_dn VARCHAR(64) DEFAULT NULL, + permissions TEXT DEFAULT NULL COMMENT 'JSON-encoded permissions', + + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_apiuser_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_endpoint ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + host VARCHAR(255) DEFAULT NULL, + port SMALLINT UNSIGNED DEFAULT NULL, + log_duration VARCHAR(32) DEFAULT NULL, + apiuser VARCHAR(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_endpoint_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_service ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'apply') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + host VARCHAR(255) DEFAULT NULL, + service_set VARCHAR(255) DEFAULT NULL, + check_command VARCHAR(255) DEFAULT NULL, + max_check_attempts MEDIUMINT UNSIGNED DEFAULT NULL, + check_period VARCHAR(255) DEFAULT NULL, + check_interval VARCHAR(8) DEFAULT NULL, + retry_interval VARCHAR(8) DEFAULT NULL, + check_timeout SMALLINT UNSIGNED DEFAULT NULL, + enable_notifications ENUM('y', 'n') DEFAULT NULL, + enable_active_checks ENUM('y', 'n') DEFAULT NULL, + enable_passive_checks ENUM('y', 'n') DEFAULT NULL, + enable_event_handler ENUM('y', 'n') DEFAULT NULL, + enable_flapping ENUM('y', 'n') DEFAULT NULL, + enable_perfdata ENUM('y', 'n') DEFAULT NULL, + event_command VARCHAR(255) DEFAULT NULL, + flapping_threshold_high SMALLINT UNSIGNED DEFAULT NULL, + flapping_threshold_low SMALLINT UNSIGNED DEFAULT NULL, + volatile ENUM('y', 'n') DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + command_endpoint VARCHAR(255) DEFAULT NULL, + notes TEXT DEFAULT NULL, + notes_url VARCHAR(255) DEFAULT NULL, + action_url VARCHAR(255) DEFAULT NULL, + icon_image VARCHAR(255) DEFAULT NULL, + icon_image_alt VARCHAR(255) DEFAULT NULL, + use_agent ENUM('y', 'n') DEFAULT NULL, + apply_for VARCHAR(255) DEFAULT NULL, + use_var_overrides ENUM('y', 'n') DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + -- template_choice VARCHAR(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + `groups` TEXT DEFAULT NULL, + vars MEDIUMTEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_service_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_notification ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'apply') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + apply_to ENUM('host', 'service') DEFAULT NULL, + host VARCHAR(255) DEFAULT NULL, + service VARCHAR(255) DEFAULT NULL, + times_begin INT(10) UNSIGNED DEFAULT NULL, + times_end INT(10) UNSIGNED DEFAULT NULL, + notification_interval INT(10) UNSIGNED DEFAULT NULL, + command VARCHAR(255) DEFAULT NULL, + period VARCHAR(255) DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + + states TEXT DEFAULT NULL, + types TEXT DEFAULT NULL, + users TEXT DEFAULT NULL, + usergroups TEXT DEFAULT NULL, + + imports TEXT DEFAULT NULL, + vars MEDIUMTEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_notification_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_scheduled_downtime ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'apply') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + apply_to ENUM('host', 'service') DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + author VARCHAR(255) DEFAULT NULL, + comment TEXT DEFAULT NULL, + fixed ENUM('y', 'n') DEFAULT NULL, + duration INT(10) UNSIGNED DEFAULT NULL, + with_services ENUM('y', 'n') NULL DEFAULT NULL, + + imports TEXT DEFAULT NULL, + ranges TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_scheduled_downtime_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_dependency ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'apply') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + apply_to ENUM('host', 'service') DEFAULT NULL, + parent_host VARCHAR(255) DEFAULT NULL, + parent_host_var VARCHAR(128) DEFAULT NULL, + parent_service VARCHAR(255) DEFAULT NULL, + child_host VARCHAR(255) DEFAULT NULL, + child_service VARCHAR(255) DEFAULT NULL, + disable_checks ENUM('y', 'n') DEFAULT NULL, + disable_notifications ENUM('y', 'n') DEFAULT NULL, + ignore_soft_states ENUM('y', 'n') DEFAULT NULL, + period VARCHAR(255) DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + parent_service_by_name VARCHAR(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_dependency_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (175, NOW()); diff --git a/schema/mysql-migrations/upgrade_176.sql b/schema/mysql-migrations/upgrade_176.sql new file mode 100644 index 0000000..9913c11 --- /dev/null +++ b/schema/mysql-migrations/upgrade_176.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_host ADD COLUMN custom_endpoint_name VARCHAR(255) DEFAULT NULL AFTER accept_config; +ALTER TABLE branched_icinga_host ADD COLUMN custom_endpoint_name VARCHAR(255) DEFAULT NULL AFTER accept_config; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES ('176', NOW()); diff --git a/schema/mysql-migrations/upgrade_177.sql b/schema/mysql-migrations/upgrade_177.sql new file mode 100644 index 0000000..edceab0 --- /dev/null +++ b/schema/mysql-migrations/upgrade_177.sql @@ -0,0 +1,20 @@ +ALTER TABLE icinga_service_set 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 SET uuid = UNHEX(LPAD(LPAD(HEX(id), 8, '0'), 32, REPLACE(@tmp_uuid, '-', ''))) WHERE uuid IS NULL; +ALTER TABLE icinga_service_set MODIFY COLUMN uuid VARBINARY(16) NOT NULL, ADD UNIQUE INDEX uuid (uuid); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES ('177', NOW()); diff --git a/schema/mysql-migrations/upgrade_178.sql b/schema/mysql-migrations/upgrade_178.sql new file mode 100644 index 0000000..589e604 --- /dev/null +++ b/schema/mysql-migrations/upgrade_178.sql @@ -0,0 +1,20 @@ +CREATE TABLE director_activity_log_remark ( + first_related_activity BIGINT(20) UNSIGNED NOT NULL, + last_related_activity BIGINT(20) UNSIGNED NOT NULL, + remark TEXT NOT NULL, + PRIMARY KEY (first_related_activity, last_related_activity), + CONSTRAINT activity_log_remark_begin + FOREIGN KEY first_related_activity (first_related_activity) + REFERENCES director_activity_log (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT activity_log_remark_end + FOREIGN KEY last_related_activity (last_related_activity) + REFERENCES director_activity_log (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES ('178', NOW()); diff --git a/schema/mysql-migrations/upgrade_179.sql b/schema/mysql-migrations/upgrade_179.sql new file mode 100644 index 0000000..8368b18 --- /dev/null +++ b/schema/mysql-migrations/upgrade_179.sql @@ -0,0 +1,5 @@ +ALTER TABLE director_deployment_log ADD INDEX (start_time); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES ('179', NOW()); diff --git a/schema/mysql-migrations/upgrade_180.sql b/schema/mysql-migrations/upgrade_180.sql new file mode 100644 index 0000000..fb44365 --- /dev/null +++ b/schema/mysql-migrations/upgrade_180.sql @@ -0,0 +1,26 @@ +CREATE TABLE branched_icinga_service_set ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(128) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + host VARCHAR(255) DEFAULT NULL, + description TEXT DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + INDEX search_object_name (object_name), + CONSTRAINT icinga_service_set_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (180, NOW()); diff --git a/schema/mysql-migrations/upgrade_182.sql b/schema/mysql-migrations/upgrade_182.sql new file mode 100644 index 0000000..bb91fda --- /dev/null +++ b/schema/mysql-migrations/upgrade_182.sql @@ -0,0 +1,12 @@ +DELETE sr.* + FROM sync_run sr + JOIN sync_rule s ON s.id = sr.rule_id + WHERE sr.last_former_activity = sr.last_related_activity + AND s.object_type != 'datalistEntry' AND sr.start_time > '2022-09-21 00:00:00'; + +DELETE FROM sync_run + WHERE (objects_created + objects_deleted + objects_modified) = 0; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (182, NOW()); diff --git a/schema/mysql-migrations/upgrade_63.sql b/schema/mysql-migrations/upgrade_63.sql new file mode 100644 index 0000000..7d23612 --- /dev/null +++ b/schema/mysql-migrations/upgrade_63.sql @@ -0,0 +1,12 @@ +CREATE TABLE director_schema_migration ( + schema_version SMALLINT UNSIGNED NOT NULL, + migration_time DATETIME NOT NULL, + PRIMARY KEY(schema_version) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +DROP TABLE director_dbversion; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 63; + diff --git a/schema/mysql-migrations/upgrade_64.sql b/schema/mysql-migrations/upgrade_64.sql new file mode 100644 index 0000000..ded1a0c --- /dev/null +++ b/schema/mysql-migrations/upgrade_64.sql @@ -0,0 +1,10 @@ +CREATE TABLE director_setting ( + setting_name VARCHAR(64) NOT NULL, + setting_value VARCHAR(255) NOT NULL, + PRIMARY KEY(setting_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 64; + diff --git a/schema/mysql-migrations/upgrade_65.sql b/schema/mysql-migrations/upgrade_65.sql new file mode 100644 index 0000000..7c23c91 --- /dev/null +++ b/schema/mysql-migrations/upgrade_65.sql @@ -0,0 +1,37 @@ +ALTER TABLE icinga_zone + ADD COLUMN disabled ENUM('y', 'n') NOT NULL DEFAULT 'n' AFTER object_type; + +ALTER TABLE icinga_timeperiod + ADD COLUMN disabled ENUM('y', 'n') NOT NULL DEFAULT 'n' AFTER object_type; + +ALTER TABLE icinga_command + ADD COLUMN disabled ENUM('y', 'n') NOT NULL DEFAULT 'n' AFTER object_type; + +ALTER TABLE icinga_apiuser + ADD COLUMN disabled ENUM('y', 'n') NOT NULL DEFAULT 'n' AFTER object_type; + +ALTER TABLE icinga_endpoint + ADD COLUMN disabled ENUM('y', 'n') NOT NULL DEFAULT 'n' AFTER object_type; + +ALTER TABLE icinga_host + ADD COLUMN disabled ENUM('y', 'n') NOT NULL DEFAULT 'n' AFTER object_type; + +ALTER TABLE icinga_service + ADD COLUMN disabled ENUM('y', 'n') NOT NULL DEFAULT 'n' AFTER object_type; + +ALTER TABLE icinga_hostgroup + ADD COLUMN disabled ENUM('y', 'n') NOT NULL DEFAULT 'n' AFTER object_type; + +ALTER TABLE icinga_servicegroup + ADD COLUMN disabled ENUM('y', 'n') NOT NULL DEFAULT 'n' AFTER object_type; + +ALTER TABLE icinga_user + ADD COLUMN disabled ENUM('y', 'n') NOT NULL DEFAULT 'n' AFTER object_type; + +ALTER TABLE icinga_usergroup + ADD COLUMN disabled ENUM('y', 'n') NOT NULL DEFAULT 'n' AFTER object_type; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 65; + diff --git a/schema/mysql-migrations/upgrade_66.sql b/schema/mysql-migrations/upgrade_66.sql new file mode 100644 index 0000000..9ce2cd8 --- /dev/null +++ b/schema/mysql-migrations/upgrade_66.sql @@ -0,0 +1,37 @@ + +-- dropping old tables, as they have never been used + +DROP TABLE import_row_modifier_setting; +DROP TABLE import_row_modifier; + +CREATE TABLE import_row_modifier ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + source_id INT(10) UNSIGNED NOT NULL, + property_name VARCHAR(255) NOT NULL, + provider_class VARCHAR(72) NOT NULL, + priority SMALLINT UNSIGNED NOT NULL, + PRIMARY KEY (id), + KEY search_idx (property_name), + CONSTRAINT row_modifier_import_source + FOREIGN KEY source (source_id) + REFERENCES import_source (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE import_row_modifier_setting ( + row_modifier_id INT UNSIGNED NOT NULL, + setting_name VARCHAR(64) NOT NULL, + setting_value TEXT DEFAULT NULL, + PRIMARY KEY (row_modifier_id, setting_name), + CONSTRAINT row_modifier_settings + FOREIGN KEY row_modifier (row_modifier_id) + REFERENCES import_row_modifier (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 66; + diff --git a/schema/mysql-migrations/upgrade_67.sql b/schema/mysql-migrations/upgrade_67.sql new file mode 100644 index 0000000..4bbb1b9 --- /dev/null +++ b/schema/mysql-migrations/upgrade_67.sql @@ -0,0 +1,23 @@ +CREATE TABLE sync_run ( + id BIGINT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + rule_id INT(10) UNSIGNED DEFAULT NULL, + rule_name VARCHAR(255) NOT NULL, + start_time DATETIME NOT NULL, + duration_ms INT(10) UNSIGNED NOT NULL, + objects_deleted INT(10) UNSIGNED DEFAULT 0, + objects_created INT(10) UNSIGNED DEFAULT 0, + objects_modified INT(10) UNSIGNED DEFAULT 0, + first_related_activity VARBINARY(20) DEFAULT NULL, + last_related_activity VARBINARY(20) DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT sync_run_rule + FOREIGN KEY sync_rule (rule_id) + REFERENCES sync_rule (id) + ON DELETE SET NULL + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 67; + diff --git a/schema/mysql-migrations/upgrade_68.sql b/schema/mysql-migrations/upgrade_68.sql new file mode 100644 index 0000000..d2318b8 --- /dev/null +++ b/schema/mysql-migrations/upgrade_68.sql @@ -0,0 +1,6 @@ +ALTER TABLE sync_run MODIFY duration_ms INT(10) UNSIGNED DEFAULT NULL; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 68; + diff --git a/schema/mysql-migrations/upgrade_69.sql b/schema/mysql-migrations/upgrade_69.sql new file mode 100644 index 0000000..7bf764e --- /dev/null +++ b/schema/mysql-migrations/upgrade_69.sql @@ -0,0 +1,9 @@ +ALTER TABLE sync_run + DROP COLUMN first_related_activity, + ADD COLUMN last_former_activity VARBINARY(20) DEFAULT NULL AFTER objects_modified; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 69; + + diff --git a/schema/mysql-migrations/upgrade_70.sql b/schema/mysql-migrations/upgrade_70.sql new file mode 100644 index 0000000..1312c02 --- /dev/null +++ b/schema/mysql-migrations/upgrade_70.sql @@ -0,0 +1,13 @@ +ALTER TABLE icinga_timeperiod_range + DROP FOREIGN KEY icinga_timeperiod_range_timeperiod; + +ALTER TABLE icinga_timeperiod_range + ADD CONSTRAINT icinga_timeperiod_range_timeperiod + FOREIGN KEY timeperiod (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 70; diff --git a/schema/mysql-migrations/upgrade_71.sql b/schema/mysql-migrations/upgrade_71.sql new file mode 100644 index 0000000..87dbce1 --- /dev/null +++ b/schema/mysql-migrations/upgrade_71.sql @@ -0,0 +1,44 @@ +CREATE TABLE icinga_notification ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template') NOT NULL, + disabled ENUM('y', 'n') NOT NULL DEFAULT 'n', + host_id INT(10) UNSIGNED DEFAULT NULL, + service_id INT(10) UNSIGNED DEFAULT NULL, + times_begin INT(10) UNSIGNED DEFAULT NULL, + times_end INT(10) UNSIGNED DEFAULT NULL, + notification_interval INT(10) UNSIGNED DEFAULT NULL, + command_id INT(10) UNSIGNED DEFAULT NULL, + period_id INT(10) UNSIGNED DEFAULT NULL, + zone_id INT(10) UNSIGNED DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_notification_host + FOREIGN KEY host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_service + FOREIGN KEY service (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_command + FOREIGN KEY command (command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_period + FOREIGN KEY period (period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_zone + FOREIGN KEY zone (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 71; diff --git a/schema/mysql-migrations/upgrade_72.sql b/schema/mysql-migrations/upgrade_72.sql new file mode 100644 index 0000000..82aa478 --- /dev/null +++ b/schema/mysql-migrations/upgrade_72.sql @@ -0,0 +1,14 @@ + +ALTER TABLE director_generated_config + ADD COLUMN first_activity_checksum VARBINARY(20) NOT NULL AFTER duration; + +UPDATE director_generated_config SET first_activity_checksum = last_activity_checksum; + +ALTER TABLE director_deployment_log + ADD COLUMN last_activity_checksum VARBINARY(20) NOT NULL AFTER config_checksum; + +UPDATE director_deployment_log l JOIN director_generated_config c ON l.config_checksum = c.checksum SET l.last_activity_checksum = c.last_activity_checksum; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 72; diff --git a/schema/mysql-migrations/upgrade_73.sql b/schema/mysql-migrations/upgrade_73.sql new file mode 100644 index 0000000..ecf27ae --- /dev/null +++ b/schema/mysql-migrations/upgrade_73.sql @@ -0,0 +1,50 @@ +DROP TABLE icinga_user_filter_state; + +CREATE TABLE icinga_user_states_set ( + user_id INT(10) UNSIGNED NOT NULL, + property ENUM( + 'OK', + 'Warning', + 'Critical', + 'Unknown', + 'Up', + 'Down' + ) NOT NULL, + merge_behaviour ENUM('override', 'extend', 'blacklist') NOT NULL DEFAULT 'override' + COMMENT 'override: = [], extend: += [], blacklist: -= []', + PRIMARY KEY (user_id, property), + CONSTRAINT icinga_user_states_set_user + FOREIGN KEY icinga_user (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +DROP TABLE icinga_user_filter_type; + +CREATE TABLE icinga_user_filters_set ( + user_id INT(10) UNSIGNED NOT NULL, + property ENUM( + 'DowntimeStart', + 'DowntimeEnd', + 'DowntimeRemoved', + 'Custom', + 'Acknowledgement', + 'Problem', + 'Recovery', + 'FlappingStart', + 'FlappingEnd' + ) NOT NULL, + merge_behaviour ENUM('override', 'extend', 'blacklist') NOT NULL DEFAULT 'override' + COMMENT 'override: = [], extend: += [], blacklist: -= []', + PRIMARY KEY (user_id, property), + CONSTRAINT icinga_user_filters_set_user + FOREIGN KEY icinga_user (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 73; diff --git a/schema/mysql-migrations/upgrade_74.sql b/schema/mysql-migrations/upgrade_74.sql new file mode 100644 index 0000000..382f937 --- /dev/null +++ b/schema/mysql-migrations/upgrade_74.sql @@ -0,0 +1,14 @@ + +ALTER TABLE icinga_service + DROP FOREIGN KEY icinga_host; + +ALTER TABLE icinga_service + ADD CONSTRAINT icinga_service_host + FOREIGN KEY host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 74; diff --git a/schema/mysql-migrations/upgrade_75.sql b/schema/mysql-migrations/upgrade_75.sql new file mode 100644 index 0000000..4afcab0 --- /dev/null +++ b/schema/mysql-migrations/upgrade_75.sql @@ -0,0 +1,50 @@ +DROP TABLE icinga_user_states_set; + +CREATE TABLE icinga_user_states_set ( + user_id INT(10) UNSIGNED NOT NULL, + property ENUM( + 'OK', + 'Warning', + 'Critical', + 'Unknown', + 'Up', + 'Down' + ) NOT NULL, + merge_behaviour ENUM('override', 'extend', 'blacklist') NOT NULL DEFAULT 'override' + COMMENT 'override: = [], extend: += [], blacklist: -= []', + PRIMARY KEY (user_id, property, merge_behaviour), + CONSTRAINT icinga_user_states_set_user + FOREIGN KEY icinga_user (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +DROP TABLE icinga_user_filters_set; + +CREATE TABLE icinga_user_filters_set ( + user_id INT(10) UNSIGNED NOT NULL, + property ENUM( + 'DowntimeStart', + 'DowntimeEnd', + 'DowntimeRemoved', + 'Custom', + 'Acknowledgement', + 'Problem', + 'Recovery', + 'FlappingStart', + 'FlappingEnd' + ) NOT NULL, + merge_behaviour ENUM('override', 'extend', 'blacklist') NOT NULL DEFAULT 'override' + COMMENT 'override: = [], extend: += [], blacklist: -= []', + PRIMARY KEY (user_id, property, merge_behaviour), + CONSTRAINT icinga_user_filters_set_user + FOREIGN KEY icinga_user (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 75; diff --git a/schema/mysql-migrations/upgrade_76.sql b/schema/mysql-migrations/upgrade_76.sql new file mode 100644 index 0000000..a2c1d51 --- /dev/null +++ b/schema/mysql-migrations/upgrade_76.sql @@ -0,0 +1,28 @@ +DROP TABLE icinga_user_filters_set; + +CREATE TABLE icinga_user_types_set ( + user_id INT(10) UNSIGNED NOT NULL, + property ENUM( + 'DowntimeStart', + 'DowntimeEnd', + 'DowntimeRemoved', + 'Custom', + 'Acknowledgement', + 'Problem', + 'Recovery', + 'FlappingStart', + 'FlappingEnd' + ) NOT NULL, + merge_behaviour ENUM('override', 'extend', 'blacklist') NOT NULL DEFAULT 'override' + COMMENT 'override: = [], extend: += [], blacklist: -= []', + PRIMARY KEY (user_id, property, merge_behaviour), + CONSTRAINT icinga_user_types_set_user + FOREIGN KEY icinga_user (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 76; diff --git a/schema/mysql-migrations/upgrade_77.sql b/schema/mysql-migrations/upgrade_77.sql new file mode 100644 index 0000000..0b60cc5 --- /dev/null +++ b/schema/mysql-migrations/upgrade_77.sql @@ -0,0 +1,78 @@ +CREATE TABLE icinga_notification_states_set ( + notification_id INT(10) UNSIGNED NOT NULL, + property ENUM( + 'OK', + 'Warning', + 'Critical', + 'Unknown', + 'Up', + 'Down' + ) NOT NULL, + merge_behaviour ENUM('override', 'extend', 'blacklist') NOT NULL DEFAULT 'override' + COMMENT 'override: = [], extend: += [], blacklist: -= []', + PRIMARY KEY (notification_id, property, merge_behaviour), + CONSTRAINT icinga_notification_states_set_notification + FOREIGN KEY icinga_notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE icinga_notification_types_set ( + notification_id INT(10) UNSIGNED NOT NULL, + property ENUM( + 'DowntimeStart', + 'DowntimeEnd', + 'DowntimeRemoved', + 'Custom', + 'Acknowledgement', + 'Problem', + 'Recovery', + 'FlappingStart', + 'FlappingEnd' + ) NOT NULL, + merge_behaviour ENUM('override', 'extend', 'blacklist') NOT NULL DEFAULT 'override' + COMMENT 'override: = [], extend: += [], blacklist: -= []', + PRIMARY KEY (notification_id, property, merge_behaviour), + CONSTRAINT icinga_notification_types_set_notification + FOREIGN KEY icinga_notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE icinga_notification_var ( + notification_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) DEFAULT NULL, + varvalue TEXT DEFAULT NULL, + format enum ('string', 'json', 'expression'), + PRIMARY KEY (notification_id, varname), + key search_idx (varname), + CONSTRAINT icinga_notification_var_notification + FOREIGN KEY notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_notification_inheritance ( + notification_id INT(10) UNSIGNED NOT NULL, + parent_notification_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (notification_id, parent_notification_id), + UNIQUE KEY unique_order (notification_id, weight), + CONSTRAINT icinga_notification_inheritance_notification + FOREIGN KEY host (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_inheritance_parent_notification + FOREIGN KEY host (parent_notification_id) + REFERENCES icinga_notification (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 77; diff --git a/schema/mysql-migrations/upgrade_78.sql b/schema/mysql-migrations/upgrade_78.sql new file mode 100644 index 0000000..5988ff6 --- /dev/null +++ b/schema/mysql-migrations/upgrade_78.sql @@ -0,0 +1,20 @@ +CREATE TABLE icinga_user_field ( + user_id INT(10) UNSIGNED NOT NULL COMMENT 'Makes only sense for templates', + datafield_id INT(10) UNSIGNED NOT NULL, + is_required ENUM('y', 'n') NOT NULL, + PRIMARY KEY (user_id, datafield_id), + CONSTRAINT icinga_user_field_user + FOREIGN KEY user(user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_user_field_datafield + FOREIGN KEY datafield(datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 78; diff --git a/schema/mysql-migrations/upgrade_82.sql b/schema/mysql-migrations/upgrade_82.sql new file mode 100644 index 0000000..e1acff8 --- /dev/null +++ b/schema/mysql-migrations/upgrade_82.sql @@ -0,0 +1,17 @@ +ALTER TABLE sync_rule + MODIFY COLUMN object_type enum( + 'host', + 'service', + 'command', + 'user', + 'hostgroup', + 'servicegroup', + 'usergroup', + 'datalistEntry', + 'endpoint', + 'zone' + ) NOT NULL; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 82; diff --git a/schema/mysql-migrations/upgrade_84.sql b/schema/mysql-migrations/upgrade_84.sql new file mode 100644 index 0000000..1de287a --- /dev/null +++ b/schema/mysql-migrations/upgrade_84.sql @@ -0,0 +1,5 @@ +ALTER TABLE icinga_usergroup DROP COLUMN zone_id; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (84, NOW()); diff --git a/schema/mysql-migrations/upgrade_85.sql b/schema/mysql-migrations/upgrade_85.sql new file mode 100644 index 0000000..186e171 --- /dev/null +++ b/schema/mysql-migrations/upgrade_85.sql @@ -0,0 +1,15 @@ +CREATE TABLE icinga_notification_assignment ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + notification_id INT(10) UNSIGNED NOT NULL, + filter_string TEXT NOT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_notification_assignment + FOREIGN KEY notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (85, NOW()); diff --git a/schema/mysql-migrations/upgrade_86.sql b/schema/mysql-migrations/upgrade_86.sql new file mode 100644 index 0000000..58b81c0 --- /dev/null +++ b/schema/mysql-migrations/upgrade_86.sql @@ -0,0 +1,35 @@ +CREATE TABLE icinga_notification_user ( + notification_id INT(10) UNSIGNED NOT NULL, + user_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (notification_id, user_id), + CONSTRAINT icinga_notification_user_user + FOREIGN KEY user (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_user_notification + FOREIGN KEY notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_notification_usergroup ( + notification_id INT(10) UNSIGNED NOT NULL, + usergroup_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (notification_id, usergroup_id), + CONSTRAINT icinga_notification_usergroup_usergroup + FOREIGN KEY usergroup (usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_usergroup_notification + FOREIGN KEY notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (86, NOW()); diff --git a/schema/mysql-migrations/upgrade_87.sql b/schema/mysql-migrations/upgrade_87.sql new file mode 100644 index 0000000..a6da21f --- /dev/null +++ b/schema/mysql-migrations/upgrade_87.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_notification + MODIFY COLUMN object_type ENUM('object', 'template', 'apply') NOT NULL; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 87; diff --git a/schema/mysql-migrations/upgrade_89.sql b/schema/mysql-migrations/upgrade_89.sql new file mode 100644 index 0000000..cf6ac20 --- /dev/null +++ b/schema/mysql-migrations/upgrade_89.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_command_argument + ADD required ENUM('y', 'n') DEFAULT NULL AFTER repeat_key; + +INSERT INTO director_schema_migration + SET migration_time = NOW(), + schema_version = 89; diff --git a/schema/mysql-migrations/upgrade_90.sql b/schema/mysql-migrations/upgrade_90.sql new file mode 100644 index 0000000..e3ef4fb --- /dev/null +++ b/schema/mysql-migrations/upgrade_90.sql @@ -0,0 +1,5 @@ +ALTER TABLE icinga_service_assignment ADD assign_type ENUM('assign', 'ignore') NOT NULL DEFAULT 'assign'; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (90, NOW()); diff --git a/schema/mysql-migrations/upgrade_91.sql b/schema/mysql-migrations/upgrade_91.sql new file mode 100644 index 0000000..88a551f --- /dev/null +++ b/schema/mysql-migrations/upgrade_91.sql @@ -0,0 +1,5 @@ +ALTER TABLE icinga_notification_assignment ADD assign_type ENUM('assign', 'ignore') NOT NULL DEFAULT 'assign'; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (91, NOW()); diff --git a/schema/mysql-migrations/upgrade_92.sql b/schema/mysql-migrations/upgrade_92.sql new file mode 100644 index 0000000..b7d2503 --- /dev/null +++ b/schema/mysql-migrations/upgrade_92.sql @@ -0,0 +1,27 @@ +DELETE FROM director_datalist_entry WHERE entry_name IS NULL; +ALTER TABLE director_datalist_entry + MODIFY entry_name VARCHAR(255) NOT NULL; + +DELETE FROM icinga_command_var WHERE varname IS NULL; +ALTER TABLE icinga_command_var + MODIFY varname VARCHAR(255) NOT NULL; + +DELETE FROM icinga_host_var WHERE varname IS NULL; +ALTER TABLE icinga_host_var + MODIFY varname VARCHAR(255) NOT NULL; + +DELETE FROM icinga_service_var WHERE varname IS NULL; +ALTER TABLE icinga_service_var + MODIFY varname VARCHAR(255) NOT NULL; + +DELETE FROM icinga_user_var WHERE varname IS NULL; +ALTER TABLE icinga_user_var + MODIFY varname VARCHAR(255) NOT NULL; + +DELETE FROM icinga_notification_var WHERE varname IS NULL; +ALTER TABLE icinga_notification_var + MODIFY varname VARCHAR(255) NOT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (92, NOW()); diff --git a/schema/mysql-migrations/upgrade_93.sql b/schema/mysql-migrations/upgrade_93.sql new file mode 100644 index 0000000..845d4bf --- /dev/null +++ b/schema/mysql-migrations/upgrade_93.sql @@ -0,0 +1,22 @@ +ALTER TABLE sync_rule + ADD COLUMN sync_state ENUM( + 'unknown', + 'in-sync', + 'pending-changes', + 'failing' + ) NOT NULL DEFAULT 'unknown', + ADD COLUMN last_error_message VARCHAR(255) DEFAULT NULL, + ADD COLUMN last_attempt DATETIME DEFAULT NULL +; + +UPDATE sync_rule r + JOIN ( + SELECT rule_id, MAX(start_time) AS start_time + FROM sync_run + GROUP BY rule_id + ) lr ON r.id = lr.rule_id + SET r.last_attempt = lr.start_time; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (93, NOW()); diff --git a/schema/mysql-migrations/upgrade_94.sql b/schema/mysql-migrations/upgrade_94.sql new file mode 100644 index 0000000..5b55b37 --- /dev/null +++ b/schema/mysql-migrations/upgrade_94.sql @@ -0,0 +1,29 @@ +CREATE TABLE director_job ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + job_name VARCHAR(64) NOT NULL, + job_class VARCHAR(72) NOT NULL, + disabled ENUM('y', 'n') NOT NULL DEFAULT 'n', + run_interval INT(10) UNSIGNED NOT NULL, -- seconds + last_attempt_succeeded ENUM('y', 'n') DEFAULT NULL, + ts_last_attempt DATETIME DEFAULT NULL, + ts_last_error DATETIME DEFAULT NULL, + last_error_message TEXT, + PRIMARY KEY (id), + UNIQUE KEY (job_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_job_setting ( + job_id INT UNSIGNED NOT NULL, + setting_name VARCHAR(64) NOT NULL, + setting_value TEXT DEFAULT NULL, + PRIMARY KEY (job_id, setting_name), + CONSTRAINT job_settings + FOREIGN KEY director_job (job_id) + REFERENCES director_job (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (94, NOW()); diff --git a/schema/mysql-migrations/upgrade_95.sql b/schema/mysql-migrations/upgrade_95.sql new file mode 100644 index 0000000..aa49c5b --- /dev/null +++ b/schema/mysql-migrations/upgrade_95.sql @@ -0,0 +1,22 @@ +ALTER TABLE import_source + ADD COLUMN import_state ENUM( + 'unknown', + 'in-sync', + 'pending-changes', + 'failing' + ) NOT NULL DEFAULT 'unknown', + ADD COLUMN last_error_message TEXT DEFAULT NULL, + ADD COLUMN last_attempt DATETIME DEFAULT NULL +; + +UPDATE import_source s + JOIN ( + SELECT source_id, MAX(start_time) AS start_time + FROM import_run + GROUP BY source_id + ) ir ON s.id = ir.source_id + SET s.last_attempt = ir.start_time; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (95, NOW()); diff --git a/schema/mysql-migrations/upgrade_96.sql b/schema/mysql-migrations/upgrade_96.sql new file mode 100644 index 0000000..de96582 --- /dev/null +++ b/schema/mysql-migrations/upgrade_96.sql @@ -0,0 +1,5 @@ +ALTER TABLE icinga_notification ADD apply_to ENUM('host', 'service') DEFAULT NULL AFTER disabled; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (96, NOW()); diff --git a/schema/mysql-migrations/upgrade_97.sql b/schema/mysql-migrations/upgrade_97.sql new file mode 100644 index 0000000..7da33b2 --- /dev/null +++ b/schema/mysql-migrations/upgrade_97.sql @@ -0,0 +1,11 @@ +ALTER TABLE director_job + ADD COLUMN timeperiod_id INT(10) UNSIGNED DEFAULT NULL AFTER run_interval, + ADD CONSTRAINT director_job_period + FOREIGN KEY timeperiod (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (97, NOW()); diff --git a/schema/mysql.sql b/schema/mysql.sql new file mode 100644 index 0000000..02ac5d9 --- /dev/null +++ b/schema/mysql.sql @@ -0,0 +1,2442 @@ +-- +-- MySQL schema +-- ============ +-- +-- You should normally not be required to care about schema handling. +-- Director does all the migrations for you and guides you either in +-- the frontend or provides everything you need for automated migration +-- handling. Please find more related information in our documentation. + +SET sql_mode = 'STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES,ERROR_FOR_DIVISION_BY_ZERO'; + +CREATE TABLE director_daemon_info ( + instance_uuid_hex VARCHAR(32) NOT NULL, -- random by daemon + schema_version SMALLINT UNSIGNED NOT NULL, + fqdn VARCHAR(255) NOT NULL, + username VARCHAR(64) NOT NULL, + pid INT UNSIGNED NOT NULL, + binary_path VARCHAR(128) NOT NULL, + binary_realpath VARCHAR(128) NOT NULL, + php_binary_path VARCHAR(128) NOT NULL, + php_binary_realpath VARCHAR(128) NOT NULL, + php_version VARCHAR(64) NOT NULL, + php_integer_size SMALLINT NOT NULL, + running_with_systemd ENUM('y', 'n') NOT NULL, + ts_started BIGINT(20) NOT NULL, + ts_stopped BIGINT(20) DEFAULT NULL, + ts_last_modification BIGINT(20) DEFAULT NULL, + ts_last_update BIGINT(20) DEFAULT NULL, + process_info MEDIUMTEXT NOT NULL, + PRIMARY KEY (instance_uuid_hex) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_bin; + +CREATE TABLE director_activity_log ( + id BIGINT(20) UNSIGNED AUTO_INCREMENT NOT NULL, + object_type VARCHAR(64) NOT NULL, + object_name VARCHAR(255) NOT NULL, + action_name ENUM('create', 'delete', 'modify') NOT NULL, + old_properties TEXT DEFAULT NULL COMMENT 'Property hash, JSON', + new_properties TEXT DEFAULT NULL COMMENT 'Property hash, JSON', + author VARCHAR(64) NOT NULL, + change_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + checksum VARBINARY(20) NOT NULL, + parent_checksum VARBINARY(20) DEFAULT NULL, + PRIMARY KEY (id), + INDEX sort_idx (change_time), + INDEX search_idx (object_name), + INDEX search_idx2 (object_type(32), object_name(64), change_time), + INDEX search_author (author), + INDEX checksum (checksum) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_activity_log_remark ( + first_related_activity BIGINT(20) UNSIGNED NOT NULL, + last_related_activity BIGINT(20) UNSIGNED NOT NULL, + remark TEXT NOT NULL, + PRIMARY KEY (first_related_activity, last_related_activity), + CONSTRAINT activity_log_remark_begin + FOREIGN KEY first_related_activity (first_related_activity) + REFERENCES director_activity_log (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT activity_log_remark_end + FOREIGN KEY last_related_activity (last_related_activity) + REFERENCES director_activity_log (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_basket ( + uuid VARBINARY(16) NOT NULL, + basket_name VARCHAR(64) NOT NULL, + owner_type ENUM( + 'user', + 'usergroup', + 'role' + ) NOT NULL, + owner_value VARCHAR(255) NOT NULL, + objects MEDIUMTEXT NOT NULL, -- json-encoded + PRIMARY KEY (uuid), + UNIQUE INDEX basket_name (basket_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_bin; + +CREATE TABLE director_basket_content ( + checksum VARBINARY(20) NOT NULL, + summary VARCHAR(500) NOT NULL, -- json + content MEDIUMTEXT NOT NULL, -- json + PRIMARY KEY (checksum) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_bin; + +CREATE TABLE director_basket_snapshot ( + basket_uuid VARBINARY(16) NOT NULL, + ts_create BIGINT(20) NOT NULL, + content_checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (basket_uuid, ts_create), + INDEX sort_idx (ts_create), + CONSTRAINT basked_snapshot_basket + FOREIGN KEY director_basket_snapshot (basket_uuid) + REFERENCES director_basket (uuid) + ON DELETE CASCADE + ON UPDATE RESTRICT, + CONSTRAINT basked_snapshot_content + FOREIGN KEY content_checksum (content_checksum) + REFERENCES director_basket_content (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_bin; + +CREATE TABLE director_generated_config ( + checksum VARBINARY(20) NOT NULL COMMENT 'SHA1(last_activity_checksum;file_path=checksum;file_path=checksum;...)', + director_version VARCHAR(64) DEFAULT NULL, + director_db_version INT(10) DEFAULT NULL, + duration INT(10) UNSIGNED DEFAULT NULL COMMENT 'Config generation duration (ms)', + first_activity_checksum VARBINARY(20) NOT NULL, + last_activity_checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (checksum), + CONSTRAINT director_generated_config_activity + FOREIGN KEY activity_checksum (last_activity_checksum) + REFERENCES director_activity_log (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_generated_file ( + checksum VARBINARY(20) NOT NULL COMMENT 'SHA1(content)', + content LONGTEXT NOT NULL, + cnt_object INT(10) UNSIGNED NOT NULL DEFAULT 0, + cnt_template INT(10) UNSIGNED NOT NULL DEFAULT 0, + cnt_apply INT(10) UNSIGNED NOT NULL DEFAULT 0, + PRIMARY KEY (checksum) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_generated_config_file ( + config_checksum VARBINARY(20) NOT NULL, + file_checksum VARBINARY(20) NOT NULL, + file_path VARCHAR(128) NOT NULL COMMENT 'e.g. zones/nafta/hosts.conf', + CONSTRAINT director_generated_config_file_config + FOREIGN KEY config (config_checksum) + REFERENCES director_generated_config (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT director_generated_config_file_file + FOREIGN KEY checksum (file_checksum) + REFERENCES director_generated_file (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT, + PRIMARY KEY (config_checksum, file_path), + INDEX search_idx (file_checksum) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_deployment_log ( + id BIGINT(20) UNSIGNED AUTO_INCREMENT NOT NULL, + config_checksum VARBINARY(20) DEFAULT NULL, + last_activity_checksum VARBINARY(20) NOT NULL, + peer_identity VARCHAR(64) NOT NULL, + start_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + end_time TIMESTAMP NULL DEFAULT NULL, + abort_time TIMESTAMP NULL DEFAULT NULL, + duration_connection INT(10) UNSIGNED DEFAULT NULL + COMMENT 'The time it took to connect to an Icinga node (ms)', + duration_dump INT(10) UNSIGNED DEFAULT NULL + COMMENT 'Time spent dumping the config (ms)', + stage_name VARCHAR(96) DEFAULT NULL, + stage_collected ENUM('y', 'n') DEFAULT NULL, + connection_succeeded ENUM('y', 'n') DEFAULT NULL, + dump_succeeded ENUM('y', 'n') DEFAULT NULL, + startup_succeeded ENUM('y', 'n') DEFAULT NULL, + username VARCHAR(64) DEFAULT NULL COMMENT 'The user that triggered this deployment', + startup_log MEDIUMTEXT DEFAULT NULL, + PRIMARY KEY (id), + INDEX (start_time), + CONSTRAINT config_checksum + FOREIGN KEY config_checksum (config_checksum) + REFERENCES director_generated_config (checksum) + ON DELETE SET NULL + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_datalist ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + list_name VARCHAR(255) NOT NULL, + owner VARCHAR(255) NOT NULL, + PRIMARY KEY (id), + UNIQUE KEY list_name (list_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_datalist_entry ( + list_id INT(10) UNSIGNED NOT NULL, + entry_name VARCHAR(255) COLLATE utf8_bin NOT NULL, + entry_value TEXT DEFAULT NULL, + format enum ('string', 'expression', 'json'), + allowed_roles VARCHAR(255) DEFAULT NULL, + PRIMARY KEY (list_id, entry_name), + CONSTRAINT director_datalist_value_datalist + FOREIGN KEY datalist (list_id) + REFERENCES director_datalist (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_datafield_category ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + category_name VARCHAR(255) NOT NULL, + description TEXT DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY category_name (category_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_datafield ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + category_id INT(10) UNSIGNED DEFAULT NULL, + varname VARCHAR(64) NOT NULL COLLATE utf8_bin, + caption VARCHAR(255) NOT NULL, + description TEXT DEFAULT NULL, + datatype varchar(255) NOT NULL, +-- datatype_param? multiple ones? + format enum ('string', 'json', 'expression'), + PRIMARY KEY (id), + KEY search_idx (varname), + CONSTRAINT director_datafield_category + FOREIGN KEY category (category_id) + REFERENCES director_datafield_category (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_datafield_setting ( + datafield_id INT(10) UNSIGNED NOT NULL, + setting_name VARCHAR(64) NOT NULL, + setting_value TEXT NOT NULL, + PRIMARY KEY (datafield_id, setting_name), + CONSTRAINT datafield_id_settings + FOREIGN KEY datafield (datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_schema_migration ( + schema_version SMALLINT UNSIGNED NOT NULL, + migration_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY(schema_version) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_setting ( + setting_name VARCHAR(64) NOT NULL, + setting_value VARCHAR(255) NOT NULL, + PRIMARY KEY(setting_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +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) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_zone_inheritance ( + zone_id INT(10) UNSIGNED NOT NULL, + parent_zone_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (zone_id, parent_zone_id), + UNIQUE KEY unique_order (zone_id, weight), + CONSTRAINT icinga_zone_inheritance_zone + FOREIGN KEY zone (zone_id) + REFERENCES icinga_zone (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_zone_inheritance_parent_zone + FOREIGN KEY zone (parent_zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +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', + zone_id INT(10) UNSIGNED DEFAULT NULL, + object_type ENUM('object', 'template') NOT NULL, + 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) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_timeperiod_inheritance ( + timeperiod_id INT(10) UNSIGNED NOT NULL, + parent_timeperiod_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (timeperiod_id, parent_timeperiod_id), + UNIQUE KEY unique_order (timeperiod_id, weight), + CONSTRAINT icinga_timeperiod_inheritance_timeperiod + FOREIGN KEY host (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_timeperiod_inheritance_parent_timeperiod + FOREIGN KEY host (parent_timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_timeperiod_range ( + timeperiod_id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + range_key VARCHAR(255) NOT NULL COMMENT 'monday, ...', + range_value VARCHAR(255) NOT NULL COMMENT '00:00-24:00, ...', + range_type ENUM('include', 'exclude') NOT NULL DEFAULT 'include' + COMMENT 'include -> ranges {}, exclude ranges_ignore {} - not yet', + merge_behaviour ENUM('set', 'add', 'substract') NOT NULL DEFAULT 'set' + COMMENT 'set -> = {}, add -> += {}, substract -> -= {}', + PRIMARY KEY (timeperiod_id, range_type, range_key), + CONSTRAINT icinga_timeperiod_range_timeperiod + FOREIGN KEY timeperiod (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_job ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + job_name VARCHAR(64) NOT NULL, + job_class VARCHAR(72) NOT NULL, + disabled ENUM('y', 'n') NOT NULL DEFAULT 'n', + run_interval INT(10) UNSIGNED NOT NULL, -- seconds + timeperiod_id INT(10) UNSIGNED DEFAULT NULL, + last_attempt_succeeded ENUM('y', 'n') DEFAULT NULL, + ts_last_attempt TIMESTAMP NULL DEFAULT NULL, + ts_last_error TIMESTAMP NULL DEFAULT NULL, + last_error_message TEXT DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY (job_name), + CONSTRAINT director_job_period + FOREIGN KEY timeperiod (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_job_setting ( + job_id INT UNSIGNED NOT NULL, + setting_name VARCHAR(64) NOT NULL, + setting_value TEXT DEFAULT NULL, + PRIMARY KEY (job_id, setting_name), + CONSTRAINT job_settings + FOREIGN KEY director_job (job_id) + REFERENCES director_job (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +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', + disabled ENUM('y', 'n') NOT NULL DEFAULT 'n', + methods_execute VARCHAR(64) DEFAULT NULL, + command TEXT DEFAULT NULL, + is_string ENUM('y', 'n') NULL, + -- env text DEFAULT NULL, + -- vars text DEFAULT NULL, + 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) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_command_inheritance ( + command_id INT(10) UNSIGNED NOT NULL, + parent_command_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (command_id, parent_command_id), + UNIQUE KEY unique_order (command_id, weight), + CONSTRAINT icinga_command_inheritance_command + FOREIGN KEY command (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_command_inheritance_parent_command + FOREIGN KEY command (parent_command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_command_argument ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + command_id INT(10) UNSIGNED NOT NULL, + argument_name VARCHAR(64) COLLATE utf8_bin NOT NULL COMMENT '-x, --host', + argument_value TEXT DEFAULT NULL, + argument_format ENUM('string', 'expression', 'json') NULL DEFAULT NULL, + key_string VARCHAR(64) DEFAULT NULL COMMENT 'Overrides name', + description TEXT DEFAULT NULL, + skip_key ENUM('y', 'n') DEFAULT NULL, + set_if VARCHAR(255) DEFAULT NULL, -- (string expression, must resolve to a numeric value) + set_if_format ENUM('string', 'expression', 'json') DEFAULT NULL, + sort_order SMALLINT DEFAULT NULL, -- -> order + repeat_key ENUM('y', 'n') DEFAULT NULL COMMENT 'Useful with array values', + required ENUM('y', 'n') DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY unique_idx (command_id, argument_name), + INDEX sort_idx (command_id, sort_order), + CONSTRAINT icinga_command_argument_command + FOREIGN KEY command (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_command_field ( + command_id INT(10) UNSIGNED NOT NULL, + datafield_id INT(10) UNSIGNED NOT NULL, + is_required ENUM('y', 'n') NOT NULL, + var_filter TEXT DEFAULT NULL, + PRIMARY KEY (command_id, datafield_id), + CONSTRAINT icinga_command_field_command + FOREIGN KEY command_id (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_command_field_datafield + FOREIGN KEY datafield(datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_command_var ( + command_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + varvalue TEXT DEFAULT NULL, + format ENUM('string', 'expression', 'json') NOT NULL DEFAULT 'string', + checksum VARBINARY(20) DEFAULT NULL, + PRIMARY KEY (command_id, varname), + INDEX search_idx (varname), + INDEX checksum (checksum), + CONSTRAINT icinga_command_var_command + FOREIGN KEY command (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +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), + 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, + disabled ENUM('y', 'n') NOT NULL DEFAULT 'n', + host VARCHAR(255) DEFAULT NULL COMMENT 'IP address / hostname of remote node', + port SMALLINT UNSIGNED DEFAULT NULL COMMENT '5665 if not set', + 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) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_apiuser + FOREIGN KEY apiuser (apiuser_id) + REFERENCES icinga_apiuser (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_endpoint_inheritance ( + endpoint_id INT(10) UNSIGNED NOT NULL, + parent_endpoint_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (endpoint_id, parent_endpoint_id), + UNIQUE KEY unique_order (endpoint_id, weight), + CONSTRAINT icinga_endpoint_inheritance_endpoint + FOREIGN KEY endpoint (endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_endpoint_inheritance_parent_endpoint + FOREIGN KEY endpoint (parent_endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_host_template_choice ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + object_name VARCHAR(64) NOT NULL, + description TEXT DEFAULT NULL, + min_required SMALLINT UNSIGNED NOT NULL DEFAULT 0, + max_allowed SMALLINT UNSIGNED NOT NULL DEFAULT 1, + required_template_id INT(10) UNSIGNED DEFAULT NULL, + allowed_roles VARCHAR(255) DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY (object_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +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', + display_name VARCHAR(255) DEFAULT NULL, + address VARCHAR(255) DEFAULT NULL, + address6 VARCHAR(45) DEFAULT NULL, + check_command_id INT(10) UNSIGNED DEFAULT NULL, + max_check_attempts MEDIUMINT UNSIGNED DEFAULT NULL, + check_period_id INT(10) UNSIGNED DEFAULT NULL, + check_interval VARCHAR(8) DEFAULT NULL, + retry_interval VARCHAR(8) DEFAULT NULL, + check_timeout SMALLINT UNSIGNED DEFAULT NULL, + enable_notifications ENUM('y', 'n') DEFAULT NULL, + enable_active_checks ENUM('y', 'n') DEFAULT NULL, + enable_passive_checks ENUM('y', 'n') DEFAULT NULL, + enable_event_handler ENUM('y', 'n') DEFAULT NULL, + enable_flapping ENUM('y', 'n') DEFAULT NULL, + enable_perfdata ENUM('y', 'n') DEFAULT NULL, + event_command_id INT(10) UNSIGNED DEFAULT NULL, + flapping_threshold_high SMALLINT UNSIGNED default null, + flapping_threshold_low SMALLINT UNSIGNED default null, + volatile ENUM('y', 'n') DEFAULT NULL, + zone_id INT(10) UNSIGNED DEFAULT NULL, + command_endpoint_id INT(10) UNSIGNED DEFAULT NULL, + notes TEXT DEFAULT NULL, + notes_url VARCHAR(255) DEFAULT NULL, + action_url VARCHAR(255) DEFAULT NULL, + icon_image VARCHAR(255) DEFAULT NULL, + icon_image_alt VARCHAR(255) DEFAULT NULL, + has_agent ENUM('y', 'n') DEFAULT NULL, + master_should_connect ENUM('y', 'n') DEFAULT NULL, + accept_config ENUM('y', 'n') DEFAULT NULL, + custom_endpoint_name VARCHAR(255) DEFAULT NULL, + 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), + CONSTRAINT icinga_host_zone + FOREIGN KEY zone (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_host_check_period + FOREIGN KEY timeperiod (check_period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_host_check_command + FOREIGN KEY check_command (check_command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_host_event_command + FOREIGN KEY event_command (event_command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_host_command_endpoint + FOREIGN KEY command_endpoint (command_endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_host_template_choice + FOREIGN KEY choice (template_choice_id) + REFERENCES icinga_host_template_choice (id) + ON DELETE SET NULL + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_host_inheritance ( + host_id INT(10) UNSIGNED NOT NULL, + parent_host_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (host_id, parent_host_id), + UNIQUE KEY unique_order (host_id, weight), + CONSTRAINT icinga_host_inheritance_host + FOREIGN KEY host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_inheritance_parent_host + FOREIGN KEY host (parent_host_id) + REFERENCES icinga_host (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_host_field ( + host_id INT(10) UNSIGNED NOT NULL COMMENT 'Makes only sense for templates', + datafield_id INT(10) UNSIGNED NOT NULL, + is_required ENUM('y', 'n') NOT NULL, + var_filter TEXT DEFAULT NULL, + PRIMARY KEY (host_id, datafield_id), + CONSTRAINT icinga_host_field_host + FOREIGN KEY host(host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_field_datafield + FOREIGN KEY datafield(datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_host_var ( + host_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + varvalue TEXT DEFAULT NULL, + format enum ('string', 'json', 'expression'), -- immer string vorerst + checksum VARBINARY(20) DEFAULT NULL, + PRIMARY KEY (host_id, varname), + INDEX search_idx (varname), + INDEX checksum (checksum), + CONSTRAINT icinga_host_var_host + FOREIGN KEY host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE icinga_host_template_choice + ADD CONSTRAINT host_template_choice_required_template + FOREIGN KEY required_template (required_template_id) + REFERENCES icinga_host (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +CREATE TABLE icinga_service_set ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + uuid VARBINARY(16) NOT NULL, + object_name VARCHAR(128) NOT NULL, + object_type ENUM('object', 'template', 'external_object') NOT NULL, + host_id INT(10) UNSIGNED DEFAULT NULL, + description TEXT DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE INDEX uuid (uuid), + UNIQUE KEY object_key (object_name, host_id), + CONSTRAINT icinga_service_set_host + FOREIGN KEY host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_service_template_choice ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + object_name VARCHAR(64) NOT NULL, + description TEXT DEFAULT NULL, + min_required SMALLINT UNSIGNED NOT NULL DEFAULT 0, + max_allowed SMALLINT UNSIGNED NOT NULL DEFAULT 1, + required_template_id INT(10) UNSIGNED DEFAULT NULL, + allowed_roles VARCHAR(255) DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY (object_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +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', + display_name VARCHAR(255) DEFAULT NULL, + host_id INT(10) UNSIGNED DEFAULT NULL, + service_set_id INT(10) UNSIGNED DEFAULT NULL, + check_command_id INT(10) UNSIGNED DEFAULT NULL, + max_check_attempts MEDIUMINT UNSIGNED DEFAULT NULL, + check_period_id INT(10) UNSIGNED DEFAULT NULL, + check_interval VARCHAR(8) DEFAULT NULL, + retry_interval VARCHAR(8) DEFAULT NULL, + check_timeout SMALLINT UNSIGNED DEFAULT NULL, + enable_notifications ENUM('y', 'n') DEFAULT NULL, + enable_active_checks ENUM('y', 'n') DEFAULT NULL, + enable_passive_checks ENUM('y', 'n') DEFAULT NULL, + enable_event_handler ENUM('y', 'n') DEFAULT NULL, + enable_flapping ENUM('y', 'n') DEFAULT NULL, + enable_perfdata ENUM('y', 'n') DEFAULT NULL, + event_command_id INT(10) UNSIGNED DEFAULT NULL, + flapping_threshold_high SMALLINT UNSIGNED DEFAULT NULL, + flapping_threshold_low SMALLINT UNSIGNED DEFAULT NULL, + volatile ENUM('y', 'n') DEFAULT NULL, + zone_id INT(10) UNSIGNED DEFAULT NULL, + command_endpoint_id INT(10) UNSIGNED DEFAULT NULL, + notes TEXT DEFAULT NULL, + notes_url VARCHAR(255) DEFAULT NULL, + action_url VARCHAR(255) DEFAULT NULL, + icon_image VARCHAR(255) DEFAULT NULL, + icon_image_alt VARCHAR(255) DEFAULT NULL, + use_agent ENUM('y', 'n') DEFAULT NULL, + apply_for VARCHAR(255) DEFAULT NULL, + use_var_overrides ENUM('y', 'n') DEFAULT NULL, + 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) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_zone + FOREIGN KEY zone (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_service_check_period + FOREIGN KEY timeperiod (check_period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_service_check_command + FOREIGN KEY check_command (check_command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_service_event_command + FOREIGN KEY event_command (event_command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_service_command_endpoint + FOREIGN KEY command_endpoint (command_endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_service_service_set + FOREIGN KEY service_set (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_template_choice + FOREIGN KEY choice (template_choice_id) + REFERENCES icinga_service_template_choice (id) + ON DELETE SET NULL + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_service_inheritance ( + service_id INT(10) UNSIGNED NOT NULL, + parent_service_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (service_id, parent_service_id), + UNIQUE KEY unique_order (service_id, weight), + CONSTRAINT icinga_service_inheritance_service + FOREIGN KEY host (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_inheritance_parent_service + FOREIGN KEY host (parent_service_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_service_var ( + service_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + varvalue TEXT DEFAULT NULL, + format enum ('string', 'json', 'expression'), + checksum VARBINARY(20) DEFAULT NULL, + PRIMARY KEY (service_id, varname), + INDEX search_idx (varname), + INDEX checksum (checksum), + CONSTRAINT icinga_service_var_service + FOREIGN KEY service (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_service_field ( + service_id INT(10) UNSIGNED NOT NULL COMMENT 'Makes only sense for templates', + datafield_id INT(10) UNSIGNED NOT NULL, + is_required ENUM('y', 'n') NOT NULL, + var_filter TEXT DEFAULT NULL, + PRIMARY KEY (service_id, datafield_id), + CONSTRAINT icinga_service_field_service + FOREIGN KEY service(service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_field_datafield + FOREIGN KEY datafield(datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE icinga_service_template_choice + ADD CONSTRAINT service_template_choice_required_template + FOREIGN KEY required_template (required_template_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +CREATE TABLE icinga_host_service ( + host_id INT(10) UNSIGNED NOT NULL, + service_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (host_id, service_id), + CONSTRAINT icinga_host_service_host + FOREIGN KEY host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_service_service + FOREIGN KEY service (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE icinga_host_service_blacklist ( + host_id INT(10) UNSIGNED NOT NULL, + service_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (host_id, service_id), + CONSTRAINT icinga_host_service_bl_host + FOREIGN KEY host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_service_bl_service + FOREIGN KEY service (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE icinga_service_set_inheritance ( + service_set_id INT(10) UNSIGNED NOT NULL, + parent_service_set_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (service_set_id, parent_service_set_id), + UNIQUE KEY unique_order (service_set_id, weight), + CONSTRAINT icinga_service_set_inheritance_set + FOREIGN KEY host (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_set_inheritance_parent + FOREIGN KEY host (parent_service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_service_set_var ( + service_set_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + varvalue TEXT DEFAULT NULL, + format ENUM('string', 'expression', 'json') NOT NULL DEFAULT 'string', + checksum VARBINARY(20) DEFAULT NULL, + PRIMARY KEY (service_set_id, varname), + INDEX search_idx (varname), + INDEX checksum (checksum), + CONSTRAINT icinga_service_set_var_service + FOREIGN KEY command (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +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; + +-- TODO: probably useless +CREATE TABLE icinga_hostgroup_inheritance ( + hostgroup_id INT(10) UNSIGNED NOT NULL, + parent_hostgroup_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (hostgroup_id, parent_hostgroup_id), + UNIQUE KEY unique_order (hostgroup_id, weight), + CONSTRAINT icinga_hostgroup_inheritance_hostgroup + FOREIGN KEY host (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_hostgroup_inheritance_parent_hostgroup + FOREIGN KEY host (parent_hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +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; + +CREATE TABLE icinga_servicegroup_inheritance ( + servicegroup_id INT(10) UNSIGNED NOT NULL, + parent_servicegroup_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (servicegroup_id, parent_servicegroup_id), + UNIQUE KEY unique_order (servicegroup_id, weight), + CONSTRAINT icinga_servicegroup_inheritance_servicegroup + FOREIGN KEY host (servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_servicegroup_inheritance_parent_servicegroup + FOREIGN KEY host (parent_servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_servicegroup_service ( + servicegroup_id INT(10) UNSIGNED NOT NULL, + service_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (servicegroup_id, service_id), + CONSTRAINT icinga_servicegroup_service_service + FOREIGN KEY service (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_servicegroup_service_servicegroup + FOREIGN KEY servicegroup (servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE icinga_servicegroup_service_resolved ( + servicegroup_id INT(10) UNSIGNED NOT NULL, + service_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (servicegroup_id, service_id), + CONSTRAINT icinga_servicegroup_service_resolved_service + FOREIGN KEY service (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_servicegroup_service_resolved_servicegroup + FOREIGN KEY servicegroup (servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_hostgroup_host ( + hostgroup_id INT(10) UNSIGNED NOT NULL, + host_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (hostgroup_id, host_id), + CONSTRAINT icinga_hostgroup_host_host + FOREIGN KEY host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_hostgroup_host_hostgroup + FOREIGN KEY hostgroup (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_hostgroup_host_resolved ( + hostgroup_id INT(10) UNSIGNED NOT NULL, + host_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (hostgroup_id, host_id), + CONSTRAINT icinga_hostgroup_host_resolved_host + FOREIGN KEY host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_hostgroup_host_resolved_hostgroup + FOREIGN KEY hostgroup (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_hostgroup_parent ( + hostgroup_id INT(10) UNSIGNED NOT NULL, + parent_hostgroup_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (hostgroup_id, parent_hostgroup_id), + CONSTRAINT icinga_hostgroup_parent_hostgroup + FOREIGN KEY hostgroup (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_hostgroup_parent_parent + FOREIGN KEY parent (parent_hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +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', + display_name VARCHAR(255) DEFAULT NULL, + email VARCHAR(255) DEFAULT NULL, + pager VARCHAR(255) DEFAULT NULL, + enable_notifications ENUM('y', 'n') DEFAULT NULL, + 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) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_user_period + FOREIGN KEY period (period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_user_inheritance ( + user_id INT(10) UNSIGNED NOT NULL, + parent_user_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (user_id, parent_user_id), + UNIQUE KEY unique_order (user_id, weight), + CONSTRAINT icinga_user_inheritance_user + FOREIGN KEY host (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_user_inheritance_parent_user + FOREIGN KEY host (parent_user_id) + REFERENCES icinga_user (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_user_states_set ( + user_id INT(10) UNSIGNED NOT NULL, + property ENUM( + 'OK', + 'Warning', + 'Critical', + 'Unknown', + 'Up', + 'Down' + ) NOT NULL, + merge_behaviour ENUM('override', 'extend', 'blacklist') NOT NULL DEFAULT 'override' + COMMENT 'override: = [], extend: += [], blacklist: -= []', + PRIMARY KEY (user_id, property, merge_behaviour), + CONSTRAINT icinga_user_states_set_user + FOREIGN KEY icinga_user (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE icinga_user_types_set ( + user_id INT(10) UNSIGNED NOT NULL, + property ENUM( + 'DowntimeStart', + 'DowntimeEnd', + 'DowntimeRemoved', + 'Custom', + 'Acknowledgement', + 'Problem', + 'Recovery', + 'FlappingStart', + 'FlappingEnd' + ) NOT NULL, + merge_behaviour ENUM('override', 'extend', 'blacklist') NOT NULL DEFAULT 'override' + COMMENT 'override: = [], extend: += [], blacklist: -= []', + PRIMARY KEY (user_id, property, merge_behaviour), + CONSTRAINT icinga_user_types_set_user + FOREIGN KEY icinga_user (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE icinga_user_var ( + user_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + varvalue TEXT DEFAULT NULL, + format ENUM('string', 'json', 'expression') NOT NULL DEFAULT 'string', + checksum VARBINARY(20) DEFAULT NULL, + PRIMARY KEY (user_id, varname), + INDEX search_idx (varname), + INDEX checksum (checksum), + CONSTRAINT icinga_user_var_user + FOREIGN KEY icinga_user (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_user_field ( + user_id INT(10) UNSIGNED NOT NULL COMMENT 'Makes only sense for templates', + datafield_id INT(10) UNSIGNED NOT NULL, + is_required ENUM('y', 'n') NOT NULL, + var_filter TEXT DEFAULT NULL, + PRIMARY KEY (user_id, datafield_id), + CONSTRAINT icinga_user_field_user + FOREIGN KEY user(user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_user_field_datafield + FOREIGN KEY datafield(datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +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 + FOREIGN KEY zone (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_usergroup_inheritance ( + usergroup_id INT(10) UNSIGNED NOT NULL, + parent_usergroup_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (usergroup_id, parent_usergroup_id), + UNIQUE KEY unique_order (usergroup_id, weight), + CONSTRAINT icinga_usergroup_inheritance_usergroup + FOREIGN KEY usergroup (usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_usergroup_inheritance_parent_usergroup + FOREIGN KEY usergroup (parent_usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_usergroup_user ( + usergroup_id INT(10) UNSIGNED NOT NULL, + user_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (usergroup_id, user_id), + CONSTRAINT icinga_usergroup_user_user + FOREIGN KEY icinga_user (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_usergroup_user_usergroup + FOREIGN KEY usergroup (usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_usergroup_parent ( + usergroup_id INT(10) UNSIGNED NOT NULL, + parent_usergroup_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (usergroup_id, parent_usergroup_id), + CONSTRAINT icinga_usergroup_parent_usergroup + FOREIGN KEY usergroup (usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_usergroup_parent_parent + FOREIGN KEY parent (parent_usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +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', + apply_to ENUM('host', 'service') DEFAULT NULL, + host_id INT(10) UNSIGNED DEFAULT NULL, + service_id INT(10) UNSIGNED DEFAULT NULL, + times_begin INT(10) UNSIGNED DEFAULT NULL, + times_end INT(10) UNSIGNED DEFAULT NULL, + notification_interval INT(10) UNSIGNED DEFAULT NULL, + command_id INT(10) UNSIGNED DEFAULT NULL, + period_id INT(10) UNSIGNED DEFAULT NULL, + 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) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_service + FOREIGN KEY service (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_command + FOREIGN KEY command (command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_period + FOREIGN KEY period (period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_zone + FOREIGN KEY zone (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_notification_var ( + notification_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + varvalue TEXT DEFAULT NULL, + format enum ('string', 'json', 'expression'), + checksum VARBINARY(20) DEFAULT NULL, + PRIMARY KEY (notification_id, varname), + INDEX search_idx (varname), + INDEX checksum (checksum), + CONSTRAINT icinga_notification_var_notification + FOREIGN KEY notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_notification_field ( + notification_id INT(10) UNSIGNED NOT NULL COMMENT 'Makes only sense for templates', + datafield_id INT(10) UNSIGNED NOT NULL, + is_required ENUM('y', 'n') NOT NULL, + var_filter TEXT DEFAULT NULL, + PRIMARY KEY (notification_id, datafield_id), + CONSTRAINT icinga_notification_field_notification + FOREIGN KEY notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_field_datafield + FOREIGN KEY datafield(datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_notification_inheritance ( + notification_id INT(10) UNSIGNED NOT NULL, + parent_notification_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (notification_id, parent_notification_id), + UNIQUE KEY unique_order (notification_id, weight), + CONSTRAINT icinga_notification_inheritance_notification + FOREIGN KEY host (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_inheritance_parent_notification + FOREIGN KEY host (parent_notification_id) + REFERENCES icinga_notification (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_notification_states_set ( + notification_id INT(10) UNSIGNED NOT NULL, + property ENUM( + 'OK', + 'Warning', + 'Critical', + 'Unknown', + 'Up', + 'Down' + ) NOT NULL, + merge_behaviour ENUM('override', 'extend', 'blacklist') NOT NULL DEFAULT 'override' + COMMENT 'override: = [], extend: += [], blacklist: -= []', + PRIMARY KEY (notification_id, property, merge_behaviour), + CONSTRAINT icinga_notification_states_set_notification + FOREIGN KEY icinga_notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE icinga_notification_types_set ( + notification_id INT(10) UNSIGNED NOT NULL, + property ENUM( + 'DowntimeStart', + 'DowntimeEnd', + 'DowntimeRemoved', + 'Custom', + 'Acknowledgement', + 'Problem', + 'Recovery', + 'FlappingStart', + 'FlappingEnd' + ) NOT NULL, + merge_behaviour ENUM('override', 'extend', 'blacklist') NOT NULL DEFAULT 'override' + COMMENT 'override: = [], extend: += [], blacklist: -= []', + PRIMARY KEY (notification_id, property, merge_behaviour), + CONSTRAINT icinga_notification_types_set_notification + FOREIGN KEY icinga_notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE icinga_notification_user ( + notification_id INT(10) UNSIGNED NOT NULL, + user_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (notification_id, user_id), + CONSTRAINT icinga_notification_user_user + FOREIGN KEY user (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_user_notification + FOREIGN KEY notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_notification_usergroup ( + notification_id INT(10) UNSIGNED NOT NULL, + usergroup_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (notification_id, usergroup_id), + CONSTRAINT icinga_notification_usergroup_usergroup + FOREIGN KEY usergroup (usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_usergroup_notification + FOREIGN KEY notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE import_source ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + source_name VARCHAR(64) NOT NULL, + key_column VARCHAR(64) NOT NULL, + provider_class VARCHAR(128) NOT NULL, + import_state ENUM( + 'unknown', + 'in-sync', + 'pending-changes', + 'failing' + ) NOT NULL DEFAULT 'unknown', + last_error_message TEXT DEFAULT NULL, + last_attempt TIMESTAMP NULL DEFAULT NULL, + description TEXT DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE INDEX source_name (source_name), + INDEX search_idx (key_column) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE import_source_setting ( + source_id INT(10) UNSIGNED NOT NULL, + setting_name VARCHAR(64) NOT NULL, + setting_value TEXT NOT NULL, + PRIMARY KEY (source_id, setting_name), + CONSTRAINT import_source_settings_source + FOREIGN KEY source (source_id) + REFERENCES import_source (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE import_row_modifier ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + source_id INT(10) UNSIGNED NOT NULL, + property_name VARCHAR(255) NOT NULL, + target_property VARCHAR(255) DEFAULT NULL, + provider_class VARCHAR(128) NOT NULL, + priority SMALLINT UNSIGNED NOT NULL, + description TEXT DEFAULT NULL, + PRIMARY KEY (id), + KEY search_idx (property_name), + CONSTRAINT row_modifier_import_source + FOREIGN KEY source (source_id) + REFERENCES import_source (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE import_row_modifier_setting ( + row_modifier_id INT UNSIGNED NOT NULL, + setting_name VARCHAR(64) NOT NULL, + setting_value TEXT DEFAULT NULL, + PRIMARY KEY (row_modifier_id, setting_name), + CONSTRAINT row_modifier_settings + FOREIGN KEY row_modifier (row_modifier_id) + REFERENCES import_row_modifier (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE imported_rowset ( + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (checksum) +) ENGINE=InnoDB; + +CREATE TABLE import_run ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + source_id INT(10) UNSIGNED NOT NULL, + rowset_checksum VARBINARY(20) DEFAULT NULL, + start_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + end_time TIMESTAMP NULL DEFAULT NULL, + succeeded ENUM('y', 'n') DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT import_run_source + FOREIGN KEY import_source (source_id) + REFERENCES import_source (id) + ON DELETE CASCADE + ON UPDATE RESTRICT, + CONSTRAINT import_run_rowset + FOREIGN KEY rowset (rowset_checksum) + REFERENCES imported_rowset (checksum) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE imported_row ( + checksum VARBINARY(20) NOT NULL COMMENT 'sha1(object_name;property_checksum;...)', + object_name VARCHAR(255) NOT NULL, + PRIMARY KEY (checksum) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE imported_rowset_row ( + rowset_checksum VARBINARY(20) NOT NULL, + row_checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (rowset_checksum, row_checksum), + CONSTRAINT imported_rowset_row_rowset + FOREIGN KEY rowset_row_rowset (rowset_checksum) + REFERENCES imported_rowset (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT imported_rowset_row_row + FOREIGN KEY rowset_row_rowset (row_checksum) + REFERENCES imported_row (checksum) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE imported_property ( + checksum VARBINARY(20) NOT NULL, + property_name VARCHAR(64) NOT NULL, + property_value MEDIUMTEXT NOT NULL, + format enum ('string', 'expression', 'json'), + PRIMARY KEY (checksum), + KEY search_idx (property_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE imported_row_property ( + row_checksum VARBINARY(20) NOT NULL, + property_checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (row_checksum, property_checksum), + CONSTRAINT imported_row_property_row + FOREIGN KEY row_checksum (row_checksum) + REFERENCES imported_row (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT imported_row_property_property + FOREIGN KEY property_checksum (property_checksum) + REFERENCES imported_property (checksum) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE sync_rule ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + rule_name VARCHAR(255) NOT NULL, + object_type enum( + 'host', + 'service', + 'command', + 'user', + 'hostgroup', + 'servicegroup', + 'usergroup', + 'datalistEntry', + 'endpoint', + 'zone', + 'timePeriod', + 'serviceSet', + 'scheduledDowntime', + 'notification', + 'dependency' + ) NOT NULL, + update_policy ENUM('merge', 'override', 'ignore', 'update-only') NOT NULL, + purge_existing ENUM('y', 'n') NOT NULL DEFAULT 'n', + purge_action ENUM('delete', 'disable') NULL DEFAULT NULL, + filter_expression TEXT DEFAULT NULL, + sync_state ENUM( + 'unknown', + 'in-sync', + 'pending-changes', + 'failing' + ) NOT NULL DEFAULT 'unknown', + last_error_message TEXT DEFAULT NULL, + last_attempt TIMESTAMP NULL DEFAULT NULL, + description TEXT DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE INDEX rule_name (rule_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE sync_property ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + rule_id INT(10) UNSIGNED NOT NULL, + source_id INT(10) UNSIGNED NOT NULL, + source_expression VARCHAR(255) NOT NULL, + destination_field VARCHAR(64), + priority SMALLINT UNSIGNED NOT NULL, + filter_expression TEXT DEFAULT NULL, + merge_policy ENUM('override', 'merge') NOT NULL, + PRIMARY KEY (id), + CONSTRAINT sync_property_rule + FOREIGN KEY sync_rule (rule_id) + REFERENCES sync_rule (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT sync_property_source + FOREIGN KEY import_source (source_id) + REFERENCES import_source (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE sync_run ( + id BIGINT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + rule_id INT(10) UNSIGNED DEFAULT NULL, + rule_name VARCHAR(255) NOT NULL, + start_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + duration_ms INT(10) UNSIGNED DEFAULT NULL, + objects_deleted INT(10) UNSIGNED DEFAULT 0, + objects_created INT(10) UNSIGNED DEFAULT 0, + objects_modified INT(10) UNSIGNED DEFAULT 0, + last_former_activity VARBINARY(20) DEFAULT NULL, + last_related_activity VARBINARY(20) DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT sync_run_rule + FOREIGN KEY sync_rule (rule_id) + REFERENCES sync_rule (id) + ON DELETE SET NULL + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_var ( + checksum VARBINARY(20) NOT NULL, + rendered_checksum VARBINARY(20) NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + varvalue TEXT NOT NULL, + rendered TEXT NOT NULL, + PRIMARY KEY (checksum), + INDEX search_idx (varname) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_flat_var ( + var_checksum VARBINARY(20) NOT NULL, + flatname_checksum VARBINARY(20) NOT NULL, + flatname VARCHAR(512) NOT NULL COLLATE utf8_bin, + flatvalue TEXT NOT NULL, + PRIMARY KEY (var_checksum, flatname_checksum), + INDEX search_varname (flatname (191)), + INDEX search_varvalue (flatvalue (128)), + CONSTRAINT flat_var_var + FOREIGN KEY checksum (var_checksum) + REFERENCES icinga_var (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_command_resolved_var ( + command_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (command_id, checksum), + INDEX search_varname (varname), + CONSTRAINT command_resolved_var_command + FOREIGN KEY command (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT command_resolved_var_checksum + FOREIGN KEY checksum (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_host_resolved_var ( + host_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (host_id, checksum), + INDEX search_varname (varname), + FOREIGN KEY host_resolved_var_host (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + FOREIGN KEY host_resolved_var_checksum (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_notification_resolved_var ( + notification_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (notification_id, checksum), + INDEX search_varname (varname), + FOREIGN KEY notification_resolved_var_notification (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + FOREIGN KEY notification_resolved_var_checksum (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_service_set_resolved_var ( + service_set_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (service_set_id, checksum), + INDEX search_varname (varname), + FOREIGN KEY service_set_resolved_var_service_set (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + FOREIGN KEY service_set_resolved_var_checksum(checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_service_resolved_var ( + service_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (service_id, checksum), + INDEX search_varname (varname), + FOREIGN KEY service_resolve_var_service (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + FOREIGN KEY service_resolve_var_checksum(checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_user_resolved_var ( + user_id INT(10) UNSIGNED NOT NULL, + varname VARCHAR(255) NOT NULL COLLATE utf8_bin, + checksum VARBINARY(20) NOT NULL, + PRIMARY KEY (user_id, checksum), + INDEX search_varname (varname), + FOREIGN KEY user_resolve_var_user (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + FOREIGN KEY user_resolve_var_checksum(checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +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', + apply_to ENUM('host', 'service') DEFAULT NULL, + parent_host_id INT(10) UNSIGNED DEFAULT NULL, + parent_host_var VARCHAR(128) DEFAULT NULL, + parent_service_id INT(10) UNSIGNED DEFAULT NULL, + child_host_id INT(10) UNSIGNED DEFAULT NULL, + child_service_id INT(10) UNSIGNED DEFAULT NULL, + disable_checks ENUM('y', 'n') DEFAULT NULL, + disable_notifications ENUM('y', 'n') DEFAULT NULL, + ignore_soft_states ENUM('y', 'n') DEFAULT NULL, + period_id INT(10) UNSIGNED DEFAULT NULL, + zone_id INT(10) UNSIGNED DEFAULT NULL, + 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) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_parent_service + FOREIGN KEY parent_service (parent_service_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_child_host + FOREIGN KEY child_host (child_host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_child_service + FOREIGN KEY child_service (child_service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_period + FOREIGN KEY period (period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_zone + FOREIGN KEY zone (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_dependency_inheritance ( + dependency_id INT(10) UNSIGNED NOT NULL, + parent_dependency_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (dependency_id, parent_dependency_id), + UNIQUE KEY unique_order (dependency_id, weight), + CONSTRAINT icinga_dependency_inheritance_dependency + FOREIGN KEY dependency (dependency_id) + REFERENCES icinga_dependency (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_inheritance_parent_dependency + FOREIGN KEY parent_dependency (parent_dependency_id) + REFERENCES icinga_dependency (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_dependency_states_set ( + dependency_id INT(10) UNSIGNED NOT NULL, + property ENUM( + 'OK', + 'Warning', + 'Critical', + 'Unknown', + 'Up', + 'Down' + ) NOT NULL, + merge_behaviour ENUM('override', 'extend', 'blacklist') NOT NULL DEFAULT 'override' + COMMENT 'override: = [], extend: += [], blacklist: -= []', + PRIMARY KEY (dependency_id, property, merge_behaviour), + CONSTRAINT icinga_dependency_states_set_dependency + FOREIGN KEY icinga_dependency (dependency_id) + REFERENCES icinga_dependency (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB; + +CREATE TABLE icinga_timeperiod_include ( + timeperiod_id INT(10) UNSIGNED NOT NULL, + include_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (timeperiod_id, include_id), + CONSTRAINT icinga_timeperiod_include + FOREIGN KEY timeperiod (include_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE RESTRICT, + CONSTRAINT icinga_timeperiod_include_timeperiod + FOREIGN KEY include (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE TABLE icinga_timeperiod_exclude ( + timeperiod_id INT(10) UNSIGNED NOT NULL, + exclude_id INT(10) UNSIGNED NOT NULL, + PRIMARY KEY (timeperiod_id, exclude_id), + CONSTRAINT icinga_timeperiod_exclude + FOREIGN KEY timeperiod (exclude_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE RESTRICT, + CONSTRAINT icinga_timeperiod_exclude_timeperiod + FOREIGN KEY exclude (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +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, + disabled ENUM('y', 'n') NOT NULL DEFAULT 'n', + apply_to ENUM('host', 'service') DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + author VARCHAR(255) DEFAULT NULL, + comment TEXT DEFAULT NULL, + fixed ENUM('y', 'n') DEFAULT NULL, + 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) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_scheduled_downtime_inheritance ( + scheduled_downtime_id INT(10) UNSIGNED NOT NULL, + parent_scheduled_downtime_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (scheduled_downtime_id, parent_scheduled_downtime_id), + UNIQUE KEY unique_order (scheduled_downtime_id, weight), + CONSTRAINT icinga_scheduled_downtime_inheritance_downtime + FOREIGN KEY host (scheduled_downtime_id) + REFERENCES icinga_scheduled_downtime (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_scheduled_downtime_inheritance_parent_downtime + FOREIGN KEY host (parent_scheduled_downtime_id) + REFERENCES icinga_scheduled_downtime (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE icinga_scheduled_downtime_range ( + scheduled_downtime_id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + range_key VARCHAR(255) NOT NULL COMMENT 'monday, ...', + range_value VARCHAR(255) NOT NULL COMMENT '00:00-24:00, ...', + range_type ENUM('include', 'exclude') NOT NULL DEFAULT 'include' + COMMENT 'include -> ranges {}, exclude ranges_ignore {} - not yet', + merge_behaviour ENUM('set', 'add', 'substract') NOT NULL DEFAULT 'set' + COMMENT 'set -> = {}, add -> += {}, substract -> -= {}', + PRIMARY KEY (scheduled_downtime_id, range_type, range_key), + CONSTRAINT icinga_scheduled_downtime_range_downtime + FOREIGN KEY scheduled_downtime (scheduled_downtime_id) + REFERENCES icinga_scheduled_downtime (id) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_branch ( + uuid VARBINARY(16) NOT NULL, + owner VARCHAR(255) NOT NULL, + branch_name VARCHAR(255) NOT NULL, + description TEXT DEFAULT NULL, + ts_merge_request BIGINT DEFAULT NULL, + PRIMARY KEY(uuid), + UNIQUE KEY (branch_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE director_branch_activity ( + timestamp_ns BIGINT(20) NOT NULL, + object_uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + action ENUM ('create', 'modify', 'delete') NOT NULL, + object_table VARCHAR(64) NOT NULL, + author VARCHAR(255) NOT NULL, + former_properties LONGTEXT NOT NULL, -- json-encoded + modified_properties LONGTEXT NOT NULL, + PRIMARY KEY (timestamp_ns), + INDEX object_uuid (object_uuid), + INDEX branch_uuid (branch_uuid), + CONSTRAINT branch_activity_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_host ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + address VARCHAR(255) DEFAULT NULL, + address6 VARCHAR(45) DEFAULT NULL, + check_command VARCHAR(255) DEFAULT NULL, + max_check_attempts MEDIUMINT UNSIGNED DEFAULT NULL, + check_period VARCHAR(255) DEFAULT NULL, + check_interval VARCHAR(8) DEFAULT NULL, + retry_interval VARCHAR(8) DEFAULT NULL, + check_timeout SMALLINT UNSIGNED DEFAULT NULL, + enable_notifications ENUM('y', 'n') DEFAULT NULL, + enable_active_checks ENUM('y', 'n') DEFAULT NULL, + enable_passive_checks ENUM('y', 'n') DEFAULT NULL, + enable_event_handler ENUM('y', 'n') DEFAULT NULL, + enable_flapping ENUM('y', 'n') DEFAULT NULL, + enable_perfdata ENUM('y', 'n') DEFAULT NULL, + event_command VARCHAR(255) DEFAULT NULL, + flapping_threshold_high SMALLINT UNSIGNED DEFAULT NULL, + flapping_threshold_low SMALLINT UNSIGNED DEFAULT NULL, + volatile ENUM('y', 'n') DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + command_endpoint VARCHAR(255) DEFAULT NULL, + notes TEXT DEFAULT NULL, + notes_url VARCHAR(255) DEFAULT NULL, + action_url VARCHAR(255) DEFAULT NULL, + icon_image VARCHAR(255) DEFAULT NULL, + icon_image_alt VARCHAR(255) DEFAULT NULL, + has_agent ENUM('y', 'n') DEFAULT NULL, + master_should_connect ENUM('y', 'n') DEFAULT NULL, + accept_config ENUM('y', 'n') DEFAULT NULL, + custom_endpoint_name VARCHAR(255) DEFAULT NULL, + api_key VARCHAR(40) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + `groups` TEXT DEFAULT NULL, + vars MEDIUMTEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_host_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_hostgroup ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_hostgroup_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_servicegroup ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_servicegroup_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_usergroup ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_usergroup_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_user ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + email VARCHAR(255) DEFAULT NULL, + pager VARCHAR(255) DEFAULT NULL, + enable_notifications ENUM('y', 'n') DEFAULT NULL, + period VARCHAR(255) DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + states TEXT DEFAULT NULL, + types TEXT DEFAULT NULL, + + imports TEXT DEFAULT NULL, + `groups` TEXT DEFAULT NULL, + vars MEDIUMTEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_user_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_zone ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + parent VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + is_global ENUM('y', 'n') DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_zone_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_timeperiod ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + update_method VARCHAR(64) DEFAULT NULL COMMENT 'Usually LegacyTimePeriod', + zone VARCHAR(255) DEFAULT NULL, + prefer_includes ENUM('y', 'n') DEFAULT NULL, + + imports TEXT DEFAULT NULL, + ranges TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_timeperiod_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_command ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + methods_execute VARCHAR(64) DEFAULT NULL, + command TEXT DEFAULT NULL, + is_string ENUM('y', 'n') NULL, + timeout SMALLINT UNSIGNED DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + arguments TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_command_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_apiuser ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + password VARCHAR(255) DEFAULT NULL, + client_dn VARCHAR(64) DEFAULT NULL, + permissions TEXT DEFAULT NULL COMMENT 'JSON-encoded permissions', + + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_apiuser_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_endpoint ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + host VARCHAR(255) DEFAULT NULL, + port SMALLINT UNSIGNED DEFAULT NULL, + log_duration VARCHAR(32) DEFAULT NULL, + apiuser VARCHAR(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_endpoint_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_service ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'apply') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + display_name VARCHAR(255) DEFAULT NULL, + host VARCHAR(255) DEFAULT NULL, + service_set VARCHAR(255) DEFAULT NULL, + check_command VARCHAR(255) DEFAULT NULL, + max_check_attempts MEDIUMINT UNSIGNED DEFAULT NULL, + check_period VARCHAR(255) DEFAULT NULL, + check_interval VARCHAR(8) DEFAULT NULL, + retry_interval VARCHAR(8) DEFAULT NULL, + check_timeout SMALLINT UNSIGNED DEFAULT NULL, + enable_notifications ENUM('y', 'n') DEFAULT NULL, + enable_active_checks ENUM('y', 'n') DEFAULT NULL, + enable_passive_checks ENUM('y', 'n') DEFAULT NULL, + enable_event_handler ENUM('y', 'n') DEFAULT NULL, + enable_flapping ENUM('y', 'n') DEFAULT NULL, + enable_perfdata ENUM('y', 'n') DEFAULT NULL, + event_command VARCHAR(255) DEFAULT NULL, + flapping_threshold_high SMALLINT UNSIGNED DEFAULT NULL, + flapping_threshold_low SMALLINT UNSIGNED DEFAULT NULL, + volatile ENUM('y', 'n') DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + command_endpoint VARCHAR(255) DEFAULT NULL, + notes TEXT DEFAULT NULL, + notes_url VARCHAR(255) DEFAULT NULL, + action_url VARCHAR(255) DEFAULT NULL, + icon_image VARCHAR(255) DEFAULT NULL, + icon_image_alt VARCHAR(255) DEFAULT NULL, + use_agent ENUM('y', 'n') DEFAULT NULL, + apply_for VARCHAR(255) DEFAULT NULL, + use_var_overrides ENUM('y', 'n') DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + -- template_choice VARCHAR(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + `groups` TEXT DEFAULT NULL, + vars MEDIUMTEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + INDEX search_object_name (object_name), + INDEX search_display_name (display_name), + CONSTRAINT icinga_service_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_service_set ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(128) DEFAULT NULL, + object_type ENUM('object', 'template', 'external_object') DEFAULT NULL, + host VARCHAR(255) DEFAULT NULL, + description TEXT DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + INDEX search_object_name (object_name), + CONSTRAINT icinga_service_set_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_notification ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'apply') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + apply_to ENUM('host', 'service') DEFAULT NULL, + host VARCHAR(255) DEFAULT NULL, + service VARCHAR(255) DEFAULT NULL, + times_begin INT(10) UNSIGNED DEFAULT NULL, + times_end INT(10) UNSIGNED DEFAULT NULL, + notification_interval INT(10) UNSIGNED DEFAULT NULL, + command VARCHAR(255) DEFAULT NULL, + period VARCHAR(255) DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + + states TEXT DEFAULT NULL, + types TEXT DEFAULT NULL, + users TEXT DEFAULT NULL, + usergroups TEXT DEFAULT NULL, + + imports TEXT DEFAULT NULL, + vars MEDIUMTEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_notification_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_scheduled_downtime ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'apply') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + apply_to ENUM('host', 'service') DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + author VARCHAR(255) DEFAULT NULL, + comment TEXT DEFAULT NULL, + fixed ENUM('y', 'n') DEFAULT NULL, + duration INT(10) UNSIGNED DEFAULT NULL, + with_services ENUM('y', 'n') NULL DEFAULT NULL, + + imports TEXT DEFAULT NULL, + ranges TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_scheduled_downtime_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE branched_icinga_dependency ( + uuid VARBINARY(16) NOT NULL, + branch_uuid VARBINARY(16) NOT NULL, + branch_created ENUM('y', 'n') NOT NULL DEFAULT 'n', + branch_deleted ENUM('y', 'n') NOT NULL DEFAULT 'n', + + object_name VARCHAR(255) DEFAULT NULL, + object_type ENUM('object', 'template', 'apply') DEFAULT NULL, + disabled ENUM('y', 'n') DEFAULT NULL, + apply_to ENUM('host', 'service') DEFAULT NULL, + parent_host VARCHAR(255) DEFAULT NULL, + parent_host_var VARCHAR(128) DEFAULT NULL, + parent_service VARCHAR(255) DEFAULT NULL, + child_host VARCHAR(255) DEFAULT NULL, + child_service VARCHAR(255) DEFAULT NULL, + disable_checks ENUM('y', 'n') DEFAULT NULL, + disable_notifications ENUM('y', 'n') DEFAULT NULL, + ignore_soft_states ENUM('y', 'n') DEFAULT NULL, + period VARCHAR(255) DEFAULT NULL, + zone VARCHAR(255) DEFAULT NULL, + assign_filter TEXT DEFAULT NULL, + parent_service_by_name VARCHAR(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + UNIQUE INDEX branch_object_name (branch_uuid, object_name), + INDEX search_object_name (object_name), + CONSTRAINT icinga_dependency_branch + FOREIGN KEY branch (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (182, NOW()); diff --git a/schema/pgsql-legacy-changes/upgrade-10.sql b/schema/pgsql-legacy-changes/upgrade-10.sql new file mode 100644 index 0000000..4fd3cc1 --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade-10.sql @@ -0,0 +1,20 @@ +CREATE TABLE icinga_usergroup_inheritance ( + usergroup_id integer NOT NULL, + parent_usergroup_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (usergroup_id, parent_usergroup_id), + CONSTRAINT icinga_usergroup_inheritance_usergroup + FOREIGN KEY (usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_usergroup_inheritance_parent_usergroup + FOREIGN KEY (parent_usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX usergroup_inheritance_unique_order ON icinga_usergroup_inheritance (usergroup_id, weight); +CREATE INDEX usergroup_inheritance_usergroup ON icinga_usergroup_inheritance (usergroup_id); +CREATE INDEX usergroup_inheritance_usergroup_parent ON icinga_usergroup_inheritance (parent_usergroup_id); diff --git a/schema/pgsql-legacy-changes/upgrade-11.sql b/schema/pgsql-legacy-changes/upgrade-11.sql new file mode 100644 index 0000000..fce4e61 --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade-11.sql @@ -0,0 +1,20 @@ +CREATE TABLE icinga_endpoint_inheritance ( + endpoint_id integer NOT NULL, + parent_endpoint_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (endpoint_id, parent_endpoint_id), + CONSTRAINT icinga_endpoint_inheritance_endpoint + FOREIGN KEY (endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_endpoint_inheritance_parent_endpoint + FOREIGN KEY (parent_endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX endpoint_inheritance_unique_order ON icinga_endpoint_inheritance (endpoint_id, weight); +CREATE INDEX endpoint_inheritance_endpoint ON icinga_endpoint_inheritance (endpoint_id); +CREATE INDEX endpoint_inheritance_endpoint_parent ON icinga_endpoint_inheritance (parent_endpoint_id); diff --git a/schema/pgsql-legacy-changes/upgrade-2.sql b/schema/pgsql-legacy-changes/upgrade-2.sql new file mode 100644 index 0000000..9b73e52 --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade-2.sql @@ -0,0 +1,2 @@ +ALTER TABLE icinga_zone ADD is_global enum_boolean NOT NULL DEFAULT 'n'; + diff --git a/schema/pgsql-legacy-changes/upgrade-3.sql b/schema/pgsql-legacy-changes/upgrade-3.sql new file mode 100644 index 0000000..77cb345 --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade-3.sql @@ -0,0 +1,21 @@ +CREATE TABLE icinga_service_inheritance ( + service_id integer NOT NULL, + parent_service_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (service_id, parent_service_id), + CONSTRAINT icinga_service_inheritance_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_inheritance_parent_service + FOREIGN KEY (parent_service_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX service_inheritance_unique_order ON icinga_service_inheritance (service_id, weight); +CREATE INDEX service_inheritance_service ON icinga_service_inheritance (service_id); +CREATE INDEX service_inheritance_service_parent ON icinga_service_inheritance (parent_service_id); + diff --git a/schema/pgsql-legacy-changes/upgrade-4.sql b/schema/pgsql-legacy-changes/upgrade-4.sql new file mode 100644 index 0000000..7e81f1a --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade-4.sql @@ -0,0 +1,20 @@ +CREATE TABLE icinga_user_inheritance ( + user_id integer NOT NULL, + parent_user_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (user_id, parent_user_id), + CONSTRAINT icinga_user_inheritance_user + FOREIGN KEY (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_user_inheritance_parent_user + FOREIGN KEY (parent_user_id) + REFERENCES icinga_user (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX user_inheritance_unique_order ON icinga_user_inheritance (user_id, weight); +CREATE INDEX user_inheritance_user ON icinga_user_inheritance (user_id); +CREATE INDEX user_inheritance_user_parent ON icinga_user_inheritance (parent_user_id);
\ No newline at end of file diff --git a/schema/pgsql-legacy-changes/upgrade-5.sql b/schema/pgsql-legacy-changes/upgrade-5.sql new file mode 100644 index 0000000..2671177 --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade-5.sql @@ -0,0 +1,20 @@ +CREATE TABLE icinga_timeperiod_inheritance ( + timeperiod_id integer NOT NULL, + parent_timeperiod_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (timeperiod_id, parent_timeperiod_id), + CONSTRAINT icinga_timeperiod_inheritance_timeperiod + FOREIGN KEY (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_timeperiod_inheritance_parent_timeperiod + FOREIGN KEY (parent_timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX timeperiod_inheritance_unique_order ON icinga_timeperiod_inheritance (timeperiod_id, weight); +CREATE INDEX timeperiod_inheritance_timeperiod ON icinga_timeperiod_inheritance (timeperiod_id); +CREATE INDEX timeperiod_inheritance_timeperiod_parent ON icinga_timeperiod_inheritance (parent_timeperiod_id);
\ No newline at end of file diff --git a/schema/pgsql-legacy-changes/upgrade-6.sql b/schema/pgsql-legacy-changes/upgrade-6.sql new file mode 100644 index 0000000..2bc32a8 --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade-6.sql @@ -0,0 +1,20 @@ +CREATE TABLE icinga_hostgroup_inheritance ( + hostgroup_id integer NOT NULL, + parent_hostgroup_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (hostgroup_id, parent_hostgroup_id), + CONSTRAINT icinga_hostgroup_inheritance_hostgroup + FOREIGN KEY (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_hostgroup_inheritance_parent_hostgroup + FOREIGN KEY (parent_hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX hostgroup_inheritance_unique_order ON icinga_hostgroup_inheritance (hostgroup_id, weight); +CREATE INDEX hostgroup_inheritance_hostgroup ON icinga_hostgroup_inheritance (hostgroup_id); +CREATE INDEX hostgroup_inheritance_hostgroup_parent ON icinga_hostgroup_inheritance (parent_hostgroup_id);
\ No newline at end of file diff --git a/schema/pgsql-legacy-changes/upgrade-7.sql b/schema/pgsql-legacy-changes/upgrade-7.sql new file mode 100644 index 0000000..0d781f6 --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade-7.sql @@ -0,0 +1,20 @@ +CREATE TABLE icinga_servicegroup_inheritance ( + servicegroup_id integer NOT NULL, + parent_servicegroup_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (servicegroup_id, parent_servicegroup_id), + CONSTRAINT icinga_servicegroup_inheritance_servicegroup + FOREIGN KEY (servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_servicegroup_inheritance_parent_servicegroup + FOREIGN KEY (parent_servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX servicegroup_inheritance_unique_order ON icinga_servicegroup_inheritance (servicegroup_id, weight); +CREATE INDEX servicegroup_inheritance_servicegroup ON icinga_servicegroup_inheritance (servicegroup_id); +CREATE INDEX servicegroup_inheritance_servicegroup_parent ON icinga_servicegroup_inheritance (parent_servicegroup_id); diff --git a/schema/pgsql-legacy-changes/upgrade-8.sql b/schema/pgsql-legacy-changes/upgrade-8.sql new file mode 100644 index 0000000..61a9abe --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade-8.sql @@ -0,0 +1,20 @@ +CREATE TABLE icinga_command_inheritance ( + command_id integer NOT NULL, + parent_command_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (command_id, parent_command_id), + CONSTRAINT icinga_command_inheritance_command + FOREIGN KEY (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_command_inheritance_parent_command + FOREIGN KEY (parent_command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX command_inheritance_unique_order ON icinga_command_inheritance (command_id, weight); +CREATE INDEX command_inheritance_command ON icinga_command_inheritance (command_id); +CREATE INDEX command_inheritance_command_parent ON icinga_command_inheritance (parent_command_id); diff --git a/schema/pgsql-legacy-changes/upgrade-9.sql b/schema/pgsql-legacy-changes/upgrade-9.sql new file mode 100644 index 0000000..401a864 --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade-9.sql @@ -0,0 +1,20 @@ +CREATE TABLE icinga_zone_inheritance ( + zone_id integer NOT NULL, + parent_zone_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (zone_id, parent_zone_id), + CONSTRAINT icinga_zone_inheritance_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_zone_inheritance_parent_zone + FOREIGN KEY (parent_zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX zone_inheritance_unique_order ON icinga_zone_inheritance (zone_id, weight); +CREATE INDEX zone_inheritance_zone ON icinga_zone_inheritance (zone_id); +CREATE INDEX zone_inheritance_zone_parent ON icinga_zone_inheritance (parent_zone_id); diff --git a/schema/pgsql-legacy-changes/upgrade_1.sql b/schema/pgsql-legacy-changes/upgrade_1.sql new file mode 100644 index 0000000..11921c7 --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade_1.sql @@ -0,0 +1,13 @@ +ALTER TABLE icinga_hostgroup_parent DROP CONSTRAINT icinga_hostgroup_parent_parent; +ALTER TABLE icinga_hostgroup_parent ADD CONSTRAINT icinga_hostgroup_parent_parent + FOREIGN KEY (parent_hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE icinga_usergroup_parent DROP CONSTRAINT icinga_usergroup_parent_parent; +ALTER TABLE icinga_usergroup_parent ADD CONSTRAINT icinga_usergroup_parent_parent + FOREIGN KEY (parent_usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE;
\ No newline at end of file diff --git a/schema/pgsql-legacy-changes/upgrade_21.sql b/schema/pgsql-legacy-changes/upgrade_21.sql new file mode 100644 index 0000000..1a4fc5a --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade_21.sql @@ -0,0 +1,17 @@ +DROP TABLE director_datalist_value; + +CREATE TABLE director_datalist_entry ( + list_id integer NOT NULL, + entry_name character varying(255) DEFAULT NULL, + entry_value text DEFAULT NULL, + format enum_property_format, + PRIMARY KEY (list_id, entry_name), + CONSTRAINT director_datalist_entry_datalist + FOREIGN KEY (list_id) + REFERENCES director_datalist (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX datalist_entry_datalist ON director_datalist_entry (list_id); + diff --git a/schema/pgsql-legacy-changes/upgrade_22.sql b/schema/pgsql-legacy-changes/upgrade_22.sql new file mode 100644 index 0000000..d7aaf51 --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade_22.sql @@ -0,0 +1,55 @@ +CREATE TABLE icinga_host_field ( + host_id integer NOT NULL, + fieldname character varying(64) NOT NULL, + caption character varying(255) NOT NULL, + datatype_id integer NOT NULL, +-- datatype_param? multiple ones? + default_value text DEFAULT NULL, + format enum_property_format, + PRIMARY KEY (host_id, fieldname), + CONSTRAINT icinga_host_field_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_field_datatype + FOREIGN KEY (datatype_id) + REFERENCES director_datatype (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX host_field_key ON icinga_host_field (host_id, fieldname); +CREATE INDEX host_field_search_idx ON icinga_host_field (fieldname); +CREATE INDEX host_field_host ON icinga_host_field (host_id); +CREATE INDEX host_field_datatype ON icinga_host_field (datatype); + +COMMENT ON COLUMN icinga_host_field.host_id IS 'Makes only sense for templates'; + + +CREATE TABLE icinga_service_field ( + service_id integer NOT NULL, + fieldname character varying(64) NOT NULL, + caption character varying(255) NOT NULL, + datatype_id integer NOT NULL, +-- datatype_param? multiple ones? + default_value text DEFAULT NULL, + format enum_property_format, + PRIMARY KEY (service_id, fieldname), + CONSTRAINT icinga_service_field_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_field_datatype + FOREIGN KEY datatype (datatype_id) + REFERENCES director_datatype (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX service_field_key ON icinga_service_field (service_id, fieldname); +CREATE INDEX service_field_search_idx ON icinga_service_field (fieldname); +CREATE INDEX service_field_service ON icinga_service_field (service_id); +CREATE INDEX service_field_datatype ON icinga_service_field (datatype); +COMMENT ON COLUMN icinga_service_field.service_id IS 'Makes only sense for templates'; diff --git a/schema/pgsql-legacy-changes/upgrade_23.sql b/schema/pgsql-legacy-changes/upgrade_23.sql new file mode 100644 index 0000000..9d02ca6 --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade_23.sql @@ -0,0 +1,60 @@ +DROP TABLE director_datatype; + +CREATE TABLE director_datafield ( + id serial, + varname character varying(255) NOT NULL, + caption character varying(255) NOT NULL, + description text DEFAULT NULL, + datatype character varying(255) NOT NULL, +-- datatype_param? multiple ones? + format enum_property_format, + PRIMARY KEY (id) +); + +DROP TABLE icinga_host_field; + +CREATE TABLE icinga_host_field ( + host_id integer NOT NULL, + datafield_id integer NOT NULL, + is_required enum_boolean DEFAULT NULL, + PRIMARY KEY (host_id, datafield_id), + CONSTRAINT icinga_host_field_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_field_datafield + FOREIGN KEY (datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX host_field_key ON icinga_host_field (host_id, datafield_id); +CREATE INDEX host_field_host ON icinga_host_field (host_id); +CREATE INDEX host_field_datafield ON icinga_host_field (datafield_id); +COMMENT ON COLUMN icinga_host_field.host_id IS 'Makes only sense for templates'; + +DROP TABLE icinga_service_field; + +CREATE TABLE icinga_service_field ( + service_id integer NOT NULL, + datafield_id integer NOT NULL, + is_required enum_boolean DEFAULT NULL, + PRIMARY KEY (service_id, datafield_id), + CONSTRAINT icinga_service_field_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_field_datafield + FOREIGN KEY (datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX service_field_key ON icinga_service_field (service_id, datafield_id); +CREATE INDEX service_field_service ON icinga_service_field (service_id); +CREATE INDEX service_field_datafield ON icinga_service_field (datafield_id); +COMMENT ON COLUMN icinga_service_field.service_id IS 'Makes only sense for templates'; diff --git a/schema/pgsql-legacy-changes/upgrade_34.sql b/schema/pgsql-legacy-changes/upgrade_34.sql new file mode 100644 index 0000000..c8e57ab --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade_34.sql @@ -0,0 +1,189 @@ +ALTER TABLE director_generated_file ALTER COLUMN content SET DEFAULT NULL; +ALTER TABLE icinga_host_field ALTER COLUMN is_required SET NOT NULL; +ALTER TABLE icinga_service_field ALTER COLUMN is_required SET NOT NULL; + +CREATE TABLE import_source ( + id serial, + source_name character varying(64) NOT NULL, + key_column character varying(64) NOT NULL, + provider_class character varying(72) NOT NULL, + PRIMARY KEY (id) +); + +CREATE INDEX import_source_search_idx ON import_source (key_column); + + +CREATE TABLE import_source_setting ( + source_id integer NOT NULL, + setting_name character varying(64) NOT NULL, + setting_value text NOT NULL, + PRIMARY KEY (source_id, setting_name), + CONSTRAINT import_source_settings_source + FOREIGN KEY (source_id) + REFERENCES import_source (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX import_source_setting_source ON import_source_setting (source_id); + + +CREATE TABLE imported_rowset ( + checksum bytea CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (checksum) +); + + +CREATE TABLE import_run ( + id serial, + source_id integer NOT NULL, + rowset_checksum bytea CHECK(LENGTH(rowset_checksum) = 20), + start_time timestamp with time zone NOT NULL, + end_time timestamp with time zone NOT NULL, + succeeded enum_boolean DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT import_run_source + FOREIGN KEY (source_id) + REFERENCES import_source (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT import_run_rowset + FOREIGN KEY (rowset_checksum) + REFERENCES imported_rowset (checksum) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE INDEX import_run_import_source ON import_run (source_id); +CREATE INDEX import_run_rowset ON import_run (rowset_checksum); + + +CREATE TABLE imported_row ( + checksum bytea CHECK(LENGTH(checksum) = 20), + object_name character varying(255) NOT NULL, + PRIMARY KEY (checksum) +); + +COMMENT ON COLUMN imported_row.checksum IS 'sha1(object_name;property_checksum;...)'; + + +CREATE TABLE imported_rowset_row ( + rowset_checksum bytea CHECK(LENGTH(checksum) = 20), + row_checksum bytea CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (rowset_checksum, row_checksum), + CONSTRAINT imported_rowset_row_rowset + FOREIGN KEY (rowset_checksum) + REFERENCES imported_rowset (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT imported_rowset_row_row + FOREIGN KEY (row_checksum) + REFERENCES imported_row (checksum) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE INDEX imported_rowset_row_rowset_checksum ON imported_rowset_row (rowset_checksum); +CREATE INDEX imported_rowset_row_row_checksum ON imported_rowset_row (row_checksum); + +CREATE TABLE imported_property ( + checksum bytea CHECK(LENGTH(checksum) = 20), + property_name character varying(64) NOT NULL, + property_value text NOT NULL, + format enum_property_format, + PRIMARY KEY (checksum) +); + +CREATE INDEX imported_property_search_idx ON imported_property (property_name); + +CREATE TABLE imported_row_property ( + row_checksum bytea CHECK(LENGTH(row_checksum) = 20), + property_checksum bytea CHECK(LENGTH(property_checksum) = 20), + PRIMARY KEY (row_checksum, property_checksum), + CONSTRAINT imported_row_property_row + FOREIGN KEY (row_checksum) + REFERENCES imported_row (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT imported_row_property_property + FOREIGN KEY (property_checksum) + REFERENCES imported_property (checksum) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE INDEX imported_row_property_row_checksum ON imported_row_property (row_checksum); +CREATE INDEX imported_row_property_property_checksum ON imported_row_property (property_checksum); + + +CREATE TYPE enum_sync_rule_object_type AS ENUM('host', 'user'); +CREATE TYPE enum_sync_rule_update_policy AS ENUM('merge', 'override', 'ignore'); + +CREATE TABLE sync_rule ( + id serial, + rule_name character varying(255) NOT NULL, + object_type enum_sync_rule_object_type NOT NULL, + update_policy enum_sync_rule_update_policy NOT NULL, + purge_existing enum_boolean NOT NULL DEFAULT 'n', + filter_expression text DEFAULT NULL, + PRIMARY KEY (id) +); + + +CREATE TYPE enum_sync_property_merge_policy AS ENUM('override', 'merge'); + +CREATE TABLE sync_property ( + id serial, + rule_id integer NOT NULL, + source_id integer NOT NULL, + source_expression character varying(255) NOT NULL, + destination_field character varying(64), + priority smallint NOT NULL, + filter_expression text DEFAULT NULL, + merge_policy enum_sync_property_merge_policy NOT NULL, + PRIMARY KEY (id), + CONSTRAINT sync_property_rule + FOREIGN KEY (rule_id) + REFERENCES sync_rule (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT sync_property_source + FOREIGN KEY (source_id) + REFERENCES import_source (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE INDEX sync_property_rule ON sync_property (rule_id); +CREATE INDEX sync_property_source ON sync_property (source_id); + + +CREATE TABLE import_row_modifier ( + id serial, + property_id integer NOT NULL, + provider_class character varying(72) NOT NULL, + PRIMARY KEY (id) +); + + +CREATE TABLE import_row_modifier_setting ( + modifier_id integer NOT NULL, + setting_name character varying(64) NOT NULL, + setting_value text DEFAULT NULL, + PRIMARY KEY (modifier_id) +); + + +CREATE TABLE director_datafield_setting ( + datafield_id integer NOT NULL, + setting_name character varying(64) NOT NULL, + setting_value text NOT NULL, + PRIMARY KEY (datafield_id, setting_name), + CONSTRAINT datafield_id_settings + FOREIGN KEY (datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX director_datafield_datafield ON director_datafield_setting (datafield_id); diff --git a/schema/pgsql-legacy-changes/upgrade_35.sql b/schema/pgsql-legacy-changes/upgrade_35.sql new file mode 100644 index 0000000..b5e1294 --- /dev/null +++ b/schema/pgsql-legacy-changes/upgrade_35.sql @@ -0,0 +1,2 @@ +ALTER TABLE icinga_command_argument DROP COLUMN value_format, ADD COLUMN argument_format enum_property_format NOT NULL DEFAULT 'string'; + diff --git a/schema/pgsql-migrations/upgrade_100.sql b/schema/pgsql-migrations/upgrade_100.sql new file mode 100644 index 0000000..5f2e708 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_100.sql @@ -0,0 +1,6 @@ +ALTER TABLE import_row_modifier + ADD COLUMN target_property character varying(255) DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (100, NOW()); diff --git a/schema/pgsql-migrations/upgrade_101.sql b/schema/pgsql-migrations/upgrade_101.sql new file mode 100644 index 0000000..4243c01 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_101.sql @@ -0,0 +1,9 @@ +ALTER TABLE icinga_host + ADD COLUMN api_key character varying(40) DEFAULT NULL; + +CREATE UNIQUE INDEX host_api_key ON icinga_host (api_key); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (101, NOW()); + diff --git a/schema/pgsql-migrations/upgrade_102.sql b/schema/pgsql-migrations/upgrade_102.sql new file mode 100644 index 0000000..4805d8a --- /dev/null +++ b/schema/pgsql-migrations/upgrade_102.sql @@ -0,0 +1,13 @@ +UPDATE director_deployment_log SET startup_log = LEFT(startup_log, 20480) || ' + +[..] shortened ' +|| (LENGTH(startup_log) - 40960) +|| ' bytes by Director on schema upgrade [..] + +' || RIGHT(startup_log, 20480) WHERE LENGTH(startup_log) > 61440; + +VACUUM FULL director_deployment_log; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (102, NOW()); diff --git a/schema/pgsql-migrations/upgrade_103.sql b/schema/pgsql-migrations/upgrade_103.sql new file mode 100644 index 0000000..ac001bf --- /dev/null +++ b/schema/pgsql-migrations/upgrade_103.sql @@ -0,0 +1,11 @@ +UPDATE icinga_command_argument + SET + argument_name = '(no key)', + skip_key = 'y' + WHERE argument_name is null; + +ALTER TABLE icinga_command_argument ALTER COLUMN argument_name SET NOT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (103, NOW()); diff --git a/schema/pgsql-migrations/upgrade_104.sql b/schema/pgsql-migrations/upgrade_104.sql new file mode 100644 index 0000000..f1972e7 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_104.sql @@ -0,0 +1,25 @@ +ALTER TABLE icinga_timeperiod_range + ADD COLUMN range_key character varying(255) DEFAULT NULL, + ADD COLUMN range_value character varying(255) DEFAULT NULL; + +UPDATE icinga_timeperiod_range + SET range_key = timeperiod_key, + range_value = timeperiod_value; + +ALTER TABLE icinga_timeperiod_range + ALTER COLUMN range_key SET NOT NULL, + ALTER COLUMN range_key DROP DEFAULT, + ALTER COLUMN range_value SET NOT NULL, + ALTER COLUMN range_value DROP DEFAULT; + +ALTER TABLE icinga_timeperiod_range + DROP CONSTRAINT icinga_timeperiod_range_pkey, + ADD PRIMARY KEY (timeperiod_id, range_type, range_key); + +ALTER TABLE icinga_timeperiod_range + DROP COLUMN timeperiod_key, + DROP COLUMN timeperiod_value; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (104, NOW()); diff --git a/schema/pgsql-migrations/upgrade_105.sql b/schema/pgsql-migrations/upgrade_105.sql new file mode 100644 index 0000000..69ea047 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_105.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_service + ADD COLUMN use_var_overrides enum_boolean DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (105, NOW()); diff --git a/schema/pgsql-migrations/upgrade_106.sql b/schema/pgsql-migrations/upgrade_106.sql new file mode 100644 index 0000000..206db82 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_106.sql @@ -0,0 +1,9 @@ +ALTER TABLE sync_property + ALTER COLUMN merge_policy DROP NOT NULL; + +ALTER TABLE sync_run + ALTER COLUMN rule_id DROP NOT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (106, NOW()); diff --git a/schema/pgsql-migrations/upgrade_107.sql b/schema/pgsql-migrations/upgrade_107.sql new file mode 100644 index 0000000..293d038 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_107.sql @@ -0,0 +1,9 @@ +ALTER TABLE import_source + ALTER COLUMN last_error_message TYPE TEXT; + +ALTER TABLE sync_rule + ALTER COLUMN last_error_message TYPE TEXT; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (107, NOW()); diff --git a/schema/pgsql-migrations/upgrade_109.sql b/schema/pgsql-migrations/upgrade_109.sql new file mode 100644 index 0000000..f17123c --- /dev/null +++ b/schema/pgsql-migrations/upgrade_109.sql @@ -0,0 +1,16 @@ +CREATE TABLE icinga_hostgroup_assignment ( + id bigserial, + hostgroup_id integer NOT NULL, + filter_string TEXT NOT NULL, + assign_type enum_assign_type NOT NULL DEFAULT 'assign', + PRIMARY KEY (id), + CONSTRAINT icinga_hostgroup_assignment + FOREIGN KEY (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (109, NOW()); diff --git a/schema/pgsql-migrations/upgrade_110.sql b/schema/pgsql-migrations/upgrade_110.sql new file mode 100644 index 0000000..800f7ab --- /dev/null +++ b/schema/pgsql-migrations/upgrade_110.sql @@ -0,0 +1,104 @@ +UPDATE icinga_host_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_host_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_service_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_service_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + + +UPDATE icinga_command_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_command_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_user_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_user_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_notification_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_notification_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (110, NOW()); diff --git a/schema/pgsql-migrations/upgrade_111.sql b/schema/pgsql-migrations/upgrade_111.sql new file mode 100644 index 0000000..e5ea92b --- /dev/null +++ b/schema/pgsql-migrations/upgrade_111.sql @@ -0,0 +1,11 @@ +ALTER TABLE import_run + DROP CONSTRAINT import_run_source, + ADD CONSTRAINT import_run_source + FOREIGN KEY (source_id) + REFERENCES import_source (id) + ON DELETE CASCADE + ON UPDATE RESTRICT; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (111, NOW()); diff --git a/schema/pgsql-migrations/upgrade_113.sql b/schema/pgsql-migrations/upgrade_113.sql new file mode 100644 index 0000000..6bc541a --- /dev/null +++ b/schema/pgsql-migrations/upgrade_113.sql @@ -0,0 +1,6 @@ +COMMENT ON COLUMN icinga_timeperiod_range.range_key IS 'monday, ...'; +COMMENT ON COLUMN icinga_timeperiod_range.range_value IS '00:00-24:00, ...'; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (113, NOW()); diff --git a/schema/pgsql-migrations/upgrade_114.sql b/schema/pgsql-migrations/upgrade_114.sql new file mode 100644 index 0000000..6bd3f18 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_114.sql @@ -0,0 +1,63 @@ +CREATE TABLE icinga_service_set ( + id serial, + host_id integer NOT NULL, + object_name character varying(128) NOT NULL, + object_type enum_object_type_all NOT NULL, + description text NOT NULL, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX service_set_name ON icinga_service_set (object_name, host_id); + + +CREATE TABLE icinga_service_set_service ( + service_set_id serial, + service_id serial, + PRIMARY KEY (service_set_id, service_id), + CONSTRAINT icinga_service_set_set + FOREIGN KEY (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_set_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + + +CREATE TABLE icinga_service_set_assignment ( + id serial, + service_set_id integer NOT NULL, + filter_string text NOT NULL, + assign_type enum_assign_type NOT NULL DEFAULT 'assign', + PRIMARY KEY (id), + CONSTRAINT icinga_service_set_assignment + FOREIGN KEY (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + + +CREATE TABLE icinga_service_set_var ( + service_set_id integer NOT NULL, + varname character varying(255) NOT NULL, + varvalue text DEFAULT NULL, + format enum_property_format NOT NULL DEFAULT 'string', + PRIMARY KEY (service_set_id, varname), + CONSTRAINT icinga_service_set_var_service_set + FOREIGN KEY (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX service_set_var_service_set ON icinga_service_set_var (service_set_id); +CREATE INDEX service_set_var_search_idx ON icinga_service_set_var (varname); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (114, NOW()); diff --git a/schema/pgsql-migrations/upgrade_115.sql b/schema/pgsql-migrations/upgrade_115.sql new file mode 100644 index 0000000..0846355 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_115.sql @@ -0,0 +1,28 @@ +CREATE TABLE icinga_service_set_inheritance ( + service_set_id integer NOT NULL, + parent_service_set_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (service_set_id, parent_service_set_id), + CONSTRAINT icinga_service_set_inheritance_set + FOREIGN KEY (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_set_inheritance_parent + FOREIGN KEY (parent_service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX service_set_inheritance_unique_order ON icinga_service_set_inheritance (service_set_id, weight); +CREATE INDEX service_set_inheritance_set ON icinga_service_set_inheritance (service_set_id); +CREATE INDEX service_set_inheritance_parent ON icinga_service_set_inheritance (parent_service_set_id); + + +ALTER TABLE icinga_service_set ALTER COLUMN host_id DROP NOT NULL; +ALTER TABLE icinga_service_set ALTER COLUMN description DROP NOT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (115, NOW()); diff --git a/schema/pgsql-migrations/upgrade_116.sql b/schema/pgsql-migrations/upgrade_116.sql new file mode 100644 index 0000000..3190739 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_116.sql @@ -0,0 +1,6 @@ +ALTER TYPE enum_sync_rule_object_type ADD VALUE 'timePeriod'; +ALTER TYPE enum_sync_rule_object_type ADD VALUE 'serviceSet'; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (116, NOW()); diff --git a/schema/pgsql-migrations/upgrade_117.sql b/schema/pgsql-migrations/upgrade_117.sql new file mode 100644 index 0000000..6f3820f --- /dev/null +++ b/schema/pgsql-migrations/upgrade_117.sql @@ -0,0 +1,26 @@ +CREATE TABLE icinga_notification_field ( + notification_id integer NOT NULL, + datafield_id integer NOT NULL, + is_required enum_boolean NOT NULL, + PRIMARY KEY (notification_id, datafield_id), + CONSTRAINT icinga_notification_field_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_field_datafield + FOREIGN KEY (datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX notification_field_key ON icinga_notification_field (notification_id, datafield_id); +CREATE INDEX notification_field_notification ON icinga_notification_field (notification_id); +CREATE INDEX notification_field_datafield ON icinga_notification_field (datafield_id); +COMMENT ON COLUMN icinga_notification_field.notification_id IS 'Makes only sense for templates'; + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (117, NOW()); diff --git a/schema/pgsql-migrations/upgrade_119.sql b/schema/pgsql-migrations/upgrade_119.sql new file mode 100644 index 0000000..66ddba1 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_119.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_service + ADD COLUMN apply_for character varying(255) DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (119, NOW()); diff --git a/schema/pgsql-migrations/upgrade_120.sql b/schema/pgsql-migrations/upgrade_120.sql new file mode 100644 index 0000000..94d7364 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_120.sql @@ -0,0 +1,201 @@ +ALTER TABLE icinga_service ADD COLUMN assign_filter text DEFAULT NULL; + +WITH flat_assign AS ( + + SELECT + service_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN MAX(sa.filter_string) + ELSE ARRAY_TO_STRING(ARRAY_AGG(sa.filter_string), '&') END AS filter_string + FROM ( + SELECT + sa_not.service_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN MAX(sa_not.filter_string) + ELSE '(' || ARRAY_TO_STRING(ARRAY_AGG(sa_not.filter_string), '&') || ')' END AS filter_string + FROM ( SELECT + sa.service_id, + '!' || sa.filter_string AS filter_string + FROM icinga_service_assignment sa + WHERE assign_type = 'ignore' + ) sa_not + GROUP BY service_id + + UNION ALL + + SELECT + sa_yes.service_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN MAX(sa_yes.filter_string) + ELSE '(' || ARRAY_TO_STRING(ARRAY_AGG(sa_yes.filter_string), '|') || ')' END AS filter_string + FROM ( SELECT + sa.service_id, + sa.filter_string AS filter_string + FROM icinga_service_assignment sa + WHERE assign_type = 'assign' + ) sa_yes + GROUP BY service_id + + ) sa GROUP BY service_id + +) UPDATE icinga_service s + SET assign_filter = flat_assign.filter_string + FROM flat_assign + WHERE s.id = flat_assign.service_id; + +DROP TABLE icinga_service_assignment; + +ALTER TABLE icinga_service_set ADD COLUMN assign_filter text DEFAULT NULL; + +WITH flat_assign AS ( + + SELECT + service_set_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN MAX(sa.filter_string) + ELSE ARRAY_TO_STRING(ARRAY_AGG(sa.filter_string), '&') END AS filter_string + FROM ( + SELECT + sa_not.service_set_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN MAX(sa_not.filter_string) + ELSE '(' || ARRAY_TO_STRING(ARRAY_AGG(sa_not.filter_string), '&') || ')' END AS filter_string + FROM ( SELECT + sa.service_set_id, + '!' || sa.filter_string AS filter_string + FROM icinga_service_set_assignment sa + WHERE assign_type = 'ignore' + ) sa_not + GROUP BY service_set_id + + UNION ALL + + SELECT + sa_yes.service_set_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN MAX(sa_yes.filter_string) + ELSE '(' || ARRAY_TO_STRING(ARRAY_AGG(sa_yes.filter_string), '|') || ')' END AS filter_string + FROM ( SELECT + sa.service_set_id, + sa.filter_string AS filter_string + FROM icinga_service_set_assignment sa + WHERE assign_type = 'assign' + ) sa_yes + GROUP BY service_set_id + + ) sa GROUP BY service_set_id + +) UPDATE icinga_service_set s + SET assign_filter = flat_assign.filter_string + FROM flat_assign + WHERE s.id = flat_assign.service_set_id; + +DROP TABLE icinga_service_set_assignment; + + +ALTER TABLE icinga_notification ADD COLUMN assign_filter text DEFAULT NULL; + +WITH flat_assign AS ( + + SELECT + notification_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN MAX(sa.filter_string) + ELSE ARRAY_TO_STRING(ARRAY_AGG(sa.filter_string), '&') END AS filter_string + FROM ( + SELECT + sa_not.notification_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN MAX(sa_not.filter_string) + ELSE '(' || ARRAY_TO_STRING(ARRAY_AGG(sa_not.filter_string), '&') || ')' END AS filter_string + FROM ( SELECT + sa.notification_id, + '!' || sa.filter_string AS filter_string + FROM icinga_notification_assignment sa + WHERE assign_type = 'ignore' + ) sa_not + GROUP BY notification_id + + UNION ALL + + SELECT + sa_yes.notification_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN MAX(sa_yes.filter_string) + ELSE '(' || ARRAY_TO_STRING(ARRAY_AGG(sa_yes.filter_string), '|') || ')' END AS filter_string + FROM ( SELECT + sa.notification_id, + sa.filter_string AS filter_string + FROM icinga_notification_assignment sa + WHERE assign_type = 'assign' + ) sa_yes + GROUP BY notification_id + + ) sa GROUP BY notification_id + +) UPDATE icinga_notification s + SET assign_filter = flat_assign.filter_string + FROM flat_assign + WHERE s.id = flat_assign.notification_id; + + +DROP TABLE icinga_notification_assignment; + +ALTER TABLE icinga_hostgroup ADD COLUMN assign_filter text DEFAULT NULL; + +WITH flat_assign AS ( + + SELECT + hostgroup_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN MAX(sa.filter_string) + ELSE ARRAY_TO_STRING(ARRAY_AGG(sa.filter_string), '&') END AS filter_string + FROM ( + SELECT + sa_not.hostgroup_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN MAX(sa_not.filter_string) + ELSE '(' || ARRAY_TO_STRING(ARRAY_AGG(sa_not.filter_string), '&') || ')' END AS filter_string + FROM ( SELECT + sa.hostgroup_id, + '!' || sa.filter_string AS filter_string + FROM icinga_hostgroup_assignment sa + WHERE assign_type = 'ignore' + ) sa_not + GROUP BY hostgroup_id + + UNION ALL + + SELECT + sa_yes.hostgroup_id, + CASE WHEN COUNT(*) = 0 THEN NULL + WHEN COUNT(*) = 1 THEN MAX(sa_yes.filter_string) + ELSE '(' || ARRAY_TO_STRING(ARRAY_AGG(sa_yes.filter_string), '|') || ')' END AS filter_string + FROM ( SELECT + sa.hostgroup_id, + sa.filter_string AS filter_string + FROM icinga_hostgroup_assignment sa + WHERE assign_type = 'assign' + ) sa_yes + GROUP BY hostgroup_id + + ) sa GROUP BY hostgroup_id + +) UPDATE icinga_hostgroup s + SET assign_filter = flat_assign.filter_string + FROM flat_assign + WHERE s.id = flat_assign.hostgroup_id; + + +DROP TABLE icinga_hostgroup_assignment; + + +ALTER TABLE icinga_servicegroup ADD COLUMN assign_filter text DEFAULT NULL; + + +DROP TYPE enum_assign_type; + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (120, NOW()); diff --git a/schema/pgsql-migrations/upgrade_121.sql b/schema/pgsql-migrations/upgrade_121.sql new file mode 100644 index 0000000..f6a1050 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_121.sql @@ -0,0 +1,8 @@ +ALTER TABLE icinga_service + ADD COLUMN service_set_id integer DEFAULT NULL; + +DROP TABLE icinga_service_set_service; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (121, NOW()); diff --git a/schema/pgsql-migrations/upgrade_122.sql b/schema/pgsql-migrations/upgrade_122.sql new file mode 100644 index 0000000..6f3f884 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_122.sql @@ -0,0 +1,12 @@ +ALTER TABLE director_generated_file + ADD COLUMN cnt_apply SMALLINT NOT NULL DEFAULT 0; + +UPDATE director_generated_file +SET cnt_apply = ROUND( + (LENGTH(content) - LENGTH( REPLACE(content, 'apply ', '') ) ) + / LENGTH('apply ') +); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (122, NOW()); diff --git a/schema/pgsql-migrations/upgrade_123.sql b/schema/pgsql-migrations/upgrade_123.sql new file mode 100644 index 0000000..bc97854 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_123.sql @@ -0,0 +1,34 @@ +-- cleanup dangling service_set before we add foreign key +DELETE FROM icinga_service_set AS ss + WHERE NOT EXISTS ( + SELECT 1 FROM icinga_host AS h + WHERE h.id = ss.host_id + ) + AND object_type = 'object' + AND host_id IS NOT NULL; + +-- cleanup dangling services to service_set +DELETE FROM icinga_service AS s + WHERE NOT EXISTS ( + SELECT 1 FROM icinga_service_set AS ss + WHERE ss.id = s.service_set_id + ) + AND object_type IN ('object', 'apply') + AND service_set_id IS NOT NULL; + + +ALTER TABLE icinga_service_set + ADD CONSTRAINT icinga_service_set_host FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE icinga_service + ADD CONSTRAINT icinga_service_service_set FOREIGN KEY (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (123, NOW()); diff --git a/schema/pgsql-migrations/upgrade_124.sql b/schema/pgsql-migrations/upgrade_124.sql new file mode 100644 index 0000000..e8b74fa --- /dev/null +++ b/schema/pgsql-migrations/upgrade_124.sql @@ -0,0 +1,21 @@ +ALTER TABLE icinga_service_set + DROP CONSTRAINT icinga_service_set_host; + +ALTER TABLE icinga_service_set + ADD CONSTRAINT icinga_service_set_host FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE; + +ALTER TABLE icinga_service + DROP CONSTRAINT icinga_service_service_set; + +ALTER TABLE icinga_service + ADD CONSTRAINT icinga_service_service_set FOREIGN KEY (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (124, NOW()); diff --git a/schema/pgsql-migrations/upgrade_125.sql b/schema/pgsql-migrations/upgrade_125.sql new file mode 100644 index 0000000..b1ffea1 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_125.sql @@ -0,0 +1,18 @@ +ALTER TABLE icinga_command_field + ADD COLUMN var_filter TEXT DEFAULT NULL; + +ALTER TABLE icinga_host_field + ADD COLUMN var_filter TEXT DEFAULT NULL; + +ALTER TABLE icinga_notification_field + ADD COLUMN var_filter TEXT DEFAULT NULL; + +ALTER TABLE icinga_service_field + ADD COLUMN var_filter TEXT DEFAULT NULL; + +ALTER TABLE icinga_user_field + ADD COLUMN var_filter TEXT DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (125, NOW()); diff --git a/schema/pgsql-migrations/upgrade_127.sql b/schema/pgsql-migrations/upgrade_127.sql new file mode 100644 index 0000000..0cf1a12 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_127.sql @@ -0,0 +1,197 @@ +ALTER TABLE icinga_command_var + ADD COLUMN checksum bytea DEFAULT NULL CHECK(LENGTH(checksum) = 20); +CREATE INDEX command_var_search_idx ON icinga_command_var (varname); +CREATE INDEX command_var_checksum ON icinga_command_var (checksum); + + +ALTER TABLE icinga_host_var + ADD COLUMN checksum bytea DEFAULT NULL CHECK(LENGTH(checksum) = 20); +CREATE INDEX host_var_checksum ON icinga_host_var (checksum); + + +ALTER TABLE icinga_notification_var + ADD COLUMN checksum bytea DEFAULT NULL CHECK(LENGTH(checksum) = 20); +CREATE INDEX notification_var_command ON icinga_notification_var (notification_id); +CREATE INDEX notification_var_checksum ON icinga_notification_var (checksum); + + +ALTER TABLE icinga_service_set_var + ADD COLUMN checksum bytea DEFAULT NULL CHECK(LENGTH(checksum) = 20); +CREATE INDEX service_set_var_checksum ON icinga_service_set_var (checksum); + + +ALTER TABLE icinga_service_var + ADD COLUMN checksum bytea DEFAULT NULL CHECK(LENGTH(checksum) = 20); +CREATE INDEX service_var_checksum ON icinga_service_var (checksum); + + +ALTER TABLE icinga_user_var + ADD COLUMN checksum bytea DEFAULT NULL CHECK(LENGTH(checksum) = 20); +CREATE INDEX user_var_checksum ON icinga_user_var (checksum); + + +CREATE TABLE icinga_var ( + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + rendered_checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + varname character varying(255) NOT NULL, + varvalue TEXT NOT NULL, + rendered TEXT NOT NULL, + PRIMARY KEY (checksum) +); + +CREATE INDEX var_search_idx ON icinga_var (varname); + + +CREATE TABLE icinga_flat_var ( + var_checksum bytea NOT NULL CHECK(LENGTH(var_checksum) = 20), + flatname_checksum bytea NOT NULL CHECK(LENGTH(flatname_checksum) = 20), + flatname character varying(512) NOT NULL, + flatvalue TEXT NOT NULL, + PRIMARY KEY (var_checksum, flatname_checksum), + CONSTRAINT flat_var_var + FOREIGN KEY (var_checksum) + REFERENCES icinga_var (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX flat_var_var_checksum ON icinga_flat_var (var_checksum); +CREATE INDEX flat_var_search_varname ON icinga_flat_var (flatname); +CREATE INDEX flat_var_search_varvalue ON icinga_flat_var (flatvalue); + + +CREATE TABLE icinga_command_resolved_var ( + command_id integer NOT NULL, + varname character varying(255) NOT NULL, + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (command_id, checksum), + CONSTRAINT command_resolved_var_command + FOREIGN KEY (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT command_resolved_var_checksum + FOREIGN KEY (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX command_resolved_var_search_varname ON icinga_command_resolved_var (varname); +CREATE INDEX command_resolved_var_command_id ON icinga_command_resolved_var (command_id); +CREATE INDEX command_resolved_var_schecksum ON icinga_command_resolved_var (checksum); + + +CREATE TABLE icinga_host_resolved_var ( + host_id integer NOT NULL, + varname character varying(255) NOT NULL, + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (host_id, checksum), + CONSTRAINT host_resolved_var_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT host_resolved_var_checksum + FOREIGN KEY (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX host_resolved_var_search_varname ON icinga_host_resolved_var (varname); +CREATE INDEX host_resolved_var_host_id ON icinga_host_resolved_var (host_id); +CREATE INDEX host_resolved_var_schecksum ON icinga_host_resolved_var (checksum); + + +CREATE TABLE icinga_notification_resolved_var ( + notification_id integer NOT NULL, + varname character varying(255) NOT NULL, + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (notification_id, checksum), + CONSTRAINT notification_resolved_var_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT notification_resolved_var_checksum + FOREIGN KEY (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX notification_resolved_var_search_varname ON icinga_notification_resolved_var (varname); +CREATE INDEX notification_resolved_var_notification_id ON icinga_notification_resolved_var (notification_id); +CREATE INDEX notification_resolved_var_schecksum ON icinga_notification_resolved_var (checksum); + + +CREATE TABLE icinga_service_set_resolved_var ( + service_set_id integer NOT NULL, + varname character varying(255) NOT NULL, + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (service_set_id, checksum), + CONSTRAINT service_set_resolved_var_service_set + FOREIGN KEY (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT service_set_resolved_var_checksum + FOREIGN KEY (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX service_set_resolved_var_search_varname ON icinga_service_set_resolved_var (varname); +CREATE INDEX service_set_resolved_var_service_set_id ON icinga_service_set_resolved_var (service_set_id); +CREATE INDEX service_set_resolved_var_schecksum ON icinga_service_set_resolved_var (checksum); + + +CREATE TABLE icinga_service_resolved_var ( + service_id integer NOT NULL, + varname character varying(255) NOT NULL, + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (service_id, checksum), + CONSTRAINT service_resolved_var_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT service_resolved_var_checksum + FOREIGN KEY (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX service_resolved_var_search_varname ON icinga_service_resolved_var (varname); +CREATE INDEX service_resolved_var_service_id ON icinga_service_resolved_var (service_id); +CREATE INDEX service_resolved_var_schecksum ON icinga_service_resolved_var (checksum); + + +CREATE TABLE icinga_user_resolved_var ( + user_id integer NOT NULL, + varname character varying(255) NOT NULL, + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (user_id, checksum), + CONSTRAINT user_resolved_var_user + FOREIGN KEY (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT user_resolved_var_checksum + FOREIGN KEY (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX user_resolved_var_search_varname ON icinga_user_resolved_var (varname); +CREATE INDEX user_resolved_var_user_id ON icinga_user_resolved_var (user_id); +CREATE INDEX user_resolved_var_schecksum ON icinga_user_resolved_var (checksum); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (127, NOW()); diff --git a/schema/pgsql-migrations/upgrade_128.sql b/schema/pgsql-migrations/upgrade_128.sql new file mode 100644 index 0000000..20dbbc6 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_128.sql @@ -0,0 +1,5 @@ +CREATE INDEX activity_log_author ON director_activity_log (author); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (128, NOW()); diff --git a/schema/pgsql-migrations/upgrade_131.sql b/schema/pgsql-migrations/upgrade_131.sql new file mode 100644 index 0000000..37fc5b7 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_131.sql @@ -0,0 +1,22 @@ +CREATE TABLE icinga_hostgroup_host_resolved ( + hostgroup_id integer NOT NULL, + host_id integer NOT NULL, + PRIMARY KEY (hostgroup_id, host_id), + CONSTRAINT icinga_hostgroup_host_resolved_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_hostgroup_host_resolved_hostgroup + FOREIGN KEY (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX hostgroup_host_resolved_host ON icinga_hostgroup_host_resolved (host_id); +CREATE INDEX hostgroup_host_resolved_hostgroup ON icinga_hostgroup_host_resolved (hostgroup_id); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (131, NOW()); diff --git a/schema/pgsql-migrations/upgrade_132.sql b/schema/pgsql-migrations/upgrade_132.sql new file mode 100644 index 0000000..8168c68 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_132.sql @@ -0,0 +1,25 @@ +CREATE TABLE icinga_host_template_choice ( + id serial, + object_name character varying(64) NOT NULL, + description text DEFAULT NULL, + min_required smallint NOT NULL DEFAULT 0, + max_allowed smallint NOT NULL DEFAULT 1, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX host_template_choice_object_name ON icinga_host_template_choice (object_name); + + +ALTER TABLE icinga_host + ADD COLUMN template_choice_id int DEFAULT NULL, + ADD CONSTRAINT icinga_host_template_choice + FOREIGN KEY (template_choice_id) + REFERENCES icinga_host_template_choice (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +CREATE INDEX host_template_choice ON icinga_host (template_choice_id); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (132, NOW()); diff --git a/schema/pgsql-migrations/upgrade_133.sql b/schema/pgsql-migrations/upgrade_133.sql new file mode 100644 index 0000000..2cfc722 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_133.sql @@ -0,0 +1,25 @@ +CREATE TABLE icinga_service_template_choice ( + id serial, + object_name character varying(64) NOT NULL, + description text DEFAULT NULL, + min_required smallint NOT NULL DEFAULT 0, + max_allowed smallint NOT NULL DEFAULT 1, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX service_template_choice_object_name ON icinga_service_template_choice (object_name); + + +ALTER TABLE icinga_service + ADD COLUMN template_choice_id int DEFAULT NULL, + ADD CONSTRAINT icinga_service_template_choice + FOREIGN KEY (template_choice_id) + REFERENCES icinga_service_template_choice (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +CREATE INDEX service_template_choice ON icinga_service (template_choice_id); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (133, NOW()); diff --git a/schema/pgsql-migrations/upgrade_134.sql b/schema/pgsql-migrations/upgrade_134.sql new file mode 100644 index 0000000..d08510f --- /dev/null +++ b/schema/pgsql-migrations/upgrade_134.sql @@ -0,0 +1,19 @@ +ALTER TABLE icinga_host + DROP CONSTRAINT icinga_host_template_choice, + ADD CONSTRAINT icinga_host_template_choice_v2 + FOREIGN KEY (template_choice_id) + REFERENCES icinga_host_template_choice (id) + ON DELETE SET NULL + ON UPDATE CASCADE; + +ALTER TABLE icinga_service + DROP CONSTRAINT icinga_service_template_choice, + ADD CONSTRAINT icinga_service_template_choice_v2 + FOREIGN KEY (template_choice_id) + REFERENCES icinga_service_template_choice (id) + ON DELETE SET NULL + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (134, NOW()); diff --git a/schema/pgsql-migrations/upgrade_135.sql b/schema/pgsql-migrations/upgrade_135.sql new file mode 100644 index 0000000..63adfc0 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_135.sql @@ -0,0 +1,9 @@ +ALTER TABLE icinga_host + ADD COLUMN check_timeout smallint DEFAULT NULL; + +ALTER TABLE icinga_service + ADD COLUMN check_timeout smallint DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (135, NOW()); diff --git a/schema/pgsql-migrations/upgrade_136.sql b/schema/pgsql-migrations/upgrade_136.sql new file mode 100644 index 0000000..f1a3729 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_136.sql @@ -0,0 +1,6 @@ +ALTER TABLE director_datalist_entry + ADD COLUMN allowed_roles character varying(255) DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (136, NOW()); diff --git a/schema/pgsql-migrations/upgrade_137.sql b/schema/pgsql-migrations/upgrade_137.sql new file mode 100644 index 0000000..220c1c3 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_137.sql @@ -0,0 +1,9 @@ +ALTER TABLE import_source + ADD COLUMN description text DEFAULT NULL; + +ALTER TABLE sync_rule + ADD COLUMN description text DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (137, NOW()); diff --git a/schema/pgsql-migrations/upgrade_138.sql b/schema/pgsql-migrations/upgrade_138.sql new file mode 100644 index 0000000..84efc53 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_138.sql @@ -0,0 +1,6 @@ +ALTER TABLE import_row_modifier + ADD COLUMN description text DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (138, NOW()); diff --git a/schema/pgsql-migrations/upgrade_139.sql b/schema/pgsql-migrations/upgrade_139.sql new file mode 100644 index 0000000..705d2a9 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_139.sql @@ -0,0 +1,9 @@ +UPDATE import_row_modifier SET priority = id; + +CREATE UNIQUE INDEX import_row_modifier_prio + ON import_row_modifier (source_id, priority); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (139, NOW()); diff --git a/schema/pgsql-migrations/upgrade_140.sql b/schema/pgsql-migrations/upgrade_140.sql new file mode 100644 index 0000000..996e9ef --- /dev/null +++ b/schema/pgsql-migrations/upgrade_140.sql @@ -0,0 +1,5 @@ +UPDATE sync_property SET priority = 10000 - priority; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (140, NOW()); diff --git a/schema/pgsql-migrations/upgrade_141.sql b/schema/pgsql-migrations/upgrade_141.sql new file mode 100644 index 0000000..a382208 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_141.sql @@ -0,0 +1,7 @@ +UPDATE icinga_service_set + SET object_type = 'template' + WHERE object_type = 'object' AND host_id IS NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (141, NOW()); diff --git a/schema/pgsql-migrations/upgrade_142.sql b/schema/pgsql-migrations/upgrade_142.sql new file mode 100644 index 0000000..5b0c1f3 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_142.sql @@ -0,0 +1,13 @@ +ALTER TABLE import_run + DROP CONSTRAINT import_run_source; + +ALTER TABLE import_run + ADD CONSTRAINT import_run_source + FOREIGN KEY (source_id) + REFERENCES import_source (id) + ON DELETE CASCADE + ON UPDATE RESTRICT; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (142, NOW()); diff --git a/schema/pgsql-migrations/upgrade_143.sql b/schema/pgsql-migrations/upgrade_143.sql new file mode 100644 index 0000000..3c8e9c5 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_143.sql @@ -0,0 +1,27 @@ +ALTER TABLE icinga_host_template_choice + ADD COLUMN required_template_id integer DEFAULT NULL, + ADD COLUMN allowed_roles character varying(255) DEFAULT NULL, + ADD CONSTRAINT host_template_choice_required_template + FOREIGN KEY (required_template_id) + REFERENCES icinga_host (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE icinga_service_template_choice + ADD COLUMN required_template_id integer DEFAULT NULL, + ADD COLUMN allowed_roles character varying(255) DEFAULT NULL, + ADD CONSTRAINT service_template_choice_required_template + FOREIGN KEY (required_template_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +CREATE INDEX host_template_choice_required_template + ON icinga_host_template_choice (required_template_id); + +CREATE INDEX service_template_choice_required_template + ON icinga_service_template_choice (required_template_id); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (143, NOW()); diff --git a/schema/pgsql-migrations/upgrade_144.sql b/schema/pgsql-migrations/upgrade_144.sql new file mode 100644 index 0000000..4516f5e --- /dev/null +++ b/schema/pgsql-migrations/upgrade_144.sql @@ -0,0 +1,99 @@ +CREATE TABLE icinga_dependency ( + id serial, + object_name character varying(255) NOT NULL, + object_type enum_object_type_all NOT NULL, + disabled enum_boolean DEFAULT 'n', + apply_to enum_host_service NULL DEFAULT NULL, + parent_host_id integer DEFAULT NULL, + parent_service_id integer DEFAULT NULL, + child_host_id integer DEFAULT NULL, + child_service_id integer DEFAULT NULL, + disable_checks enum_boolean DEFAULT NULL, + disable_notifications enum_boolean DEFAULT NULL, + ignore_soft_states enum_boolean DEFAULT NULL, + period_id integer DEFAULT NULL, + zone_id integer DEFAULT NULL, + assign_filter text DEFAULT NULL, + parent_service_by_name character varying(255), + PRIMARY KEY (id), + CONSTRAINT icinga_dependency_parent_host + FOREIGN KEY (parent_host_id) + REFERENCES icinga_host (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_parent_service + FOREIGN KEY (parent_service_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_child_host + FOREIGN KEY (child_host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_child_service + FOREIGN KEY (child_service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_period + FOREIGN KEY (period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +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); +CREATE INDEX dependency_child_service ON icinga_dependency (child_service_id); +CREATE INDEX dependency_period ON icinga_dependency (period_id); +CREATE INDEX dependency_zone ON icinga_dependency (zone_id); + + +CREATE TABLE icinga_dependency_inheritance ( + dependency_id integer NOT NULL, + parent_dependency_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (dependency_id, parent_dependency_id), + CONSTRAINT icinga_dependency_inheritance_dependency + FOREIGN KEY (dependency_id) + REFERENCES icinga_dependency (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_inheritance_parent_dependency + FOREIGN KEY (parent_dependency_id) + REFERENCES icinga_dependency (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX dependency_inheritance_unique_order ON icinga_dependency_inheritance (dependency_id, weight); +CREATE INDEX dependency_inheritance_dependency ON icinga_dependency_inheritance (dependency_id); +CREATE INDEX dependency_inheritance_dependency_parent ON icinga_dependency_inheritance (parent_dependency_id); + + +CREATE TABLE icinga_dependency_states_set ( + dependency_id integer NOT NULL, + property enum_state_name NOT NULL, + merge_behaviour enum_set_merge_behaviour NOT NULL DEFAULT 'override', + PRIMARY KEY (dependency_id, property, merge_behaviour), + CONSTRAINT icinga_dependency_states_set_dependency + FOREIGN KEY (dependency_id) + REFERENCES icinga_dependency (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX dependency_states_set_dependency ON icinga_dependency_states_set (dependency_id); +COMMENT ON COLUMN icinga_dependency_states_set.merge_behaviour IS 'override: = [], extend: += [], blacklist: -= []'; + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (144, NOW()); diff --git a/schema/pgsql-migrations/upgrade_146.sql b/schema/pgsql-migrations/upgrade_146.sql new file mode 100644 index 0000000..ce92a31 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_146.sql @@ -0,0 +1,14 @@ +ALTER TABLE icinga_host + DROP COLUMN flapping_threshold, + ADD COLUMN flapping_threshold_high smallint DEFAULT NULL, + ADD COLUMN flapping_threshold_low smallint DEFAULT NULL; + +ALTER TABLE icinga_service + DROP COLUMN flapping_threshold, + ADD COLUMN flapping_threshold_high smallint DEFAULT NULL, + ADD COLUMN flapping_threshold_low smallint DEFAULT NULL; + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (146, NOW()); diff --git a/schema/pgsql-migrations/upgrade_147.sql b/schema/pgsql-migrations/upgrade_147.sql new file mode 100644 index 0000000..c0c5741 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_147.sql @@ -0,0 +1,23 @@ +CREATE TABLE icinga_host_service_blacklist( + host_id integer NOT NULL, + service_id integer NOT NULL, + PRIMARY KEY (host_id, service_id), + CONSTRAINT icinga_host_service__bl_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_service_bl_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX host_service_bl_host ON icinga_host_service_blacklist (host_id); +CREATE INDEX host_service_bl_service ON icinga_host_service_blacklist (service_id); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (147, NOW()); diff --git a/schema/pgsql-migrations/upgrade_148.sql b/schema/pgsql-migrations/upgrade_148.sql new file mode 100644 index 0000000..e0f24a7 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_148.sql @@ -0,0 +1,10 @@ +ALTER TABLE import_source + ALTER COLUMN provider_class TYPE character varying(128); + +ALTER TABLE import_row_modifier + ALTER COLUMN provider_class TYPE character varying(128); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (148, NOW()); diff --git a/schema/pgsql-migrations/upgrade_149.sql b/schema/pgsql-migrations/upgrade_149.sql new file mode 100644 index 0000000..9fe8d5e --- /dev/null +++ b/schema/pgsql-migrations/upgrade_149.sql @@ -0,0 +1,14 @@ +ALTER TABLE icinga_usergroup + ADD COLUMN zone_id integer DEFAULT NULL, + ADD CONSTRAINT icinga_usergroup_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +CREATE INDEX usergroup_zone ON icinga_usergroup (zone_id); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (149, NOW()); diff --git a/schema/pgsql-migrations/upgrade_150.sql b/schema/pgsql-migrations/upgrade_150.sql new file mode 100644 index 0000000..ca838bb --- /dev/null +++ b/schema/pgsql-migrations/upgrade_150.sql @@ -0,0 +1,17 @@ +UPDATE icinga_user u +SET period_id = NULL +WHERE NOT EXISTS ( + SELECT id FROM icinga_timeperiod + WHERE id = u.period_id +) AND u.period_id IS NOT NULL; + +ALTER TABLE icinga_user + ADD CONSTRAINT icinga_user_period + FOREIGN KEY (period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (150, NOW()); diff --git a/schema/pgsql-migrations/upgrade_151.sql b/schema/pgsql-migrations/upgrade_151.sql new file mode 100644 index 0000000..a24189a --- /dev/null +++ b/schema/pgsql-migrations/upgrade_151.sql @@ -0,0 +1,38 @@ +ALTER TABLE icinga_timeperiod + ADD COLUMN prefer_includes enum_boolean DEFAULT NULL; + +CREATE TABLE icinga_timeperiod_include ( + timeperiod_id integer NOT NULL, + include_id integer NOT NULL, + PRIMARY KEY (timeperiod_id, include_id), + CONSTRAINT icinga_timeperiod_timeperiod_include + FOREIGN KEY (include_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_timeperiod_include + FOREIGN KEY (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE TABLE icinga_timeperiod_exclude ( + timeperiod_id integer NOT NULL, + exclude_id integer NOT NULL, + PRIMARY KEY (timeperiod_id, exclude_id), + CONSTRAINT icinga_timeperiod_timeperiod_exclude + FOREIGN KEY (exclude_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_timeperiod_exclude + FOREIGN KEY (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +INSERT INTO director_schema_migration + (schema_version, migration_time) +VALUES (151, NOW()); diff --git a/schema/pgsql-migrations/upgrade_152.sql b/schema/pgsql-migrations/upgrade_152.sql new file mode 100644 index 0000000..b1d816c --- /dev/null +++ b/schema/pgsql-migrations/upgrade_152.sql @@ -0,0 +1,7 @@ +CREATE UNIQUE INDEX import_source_name ON import_source (source_name); + +CREATE UNIQUE INDEX sync_rule_name ON sync_rule (rule_name); + +INSERT INTO director_schema_migration + (schema_version, migration_time) +VALUES (152, NOW()); diff --git a/schema/pgsql-migrations/upgrade_153.sql b/schema/pgsql-migrations/upgrade_153.sql new file mode 100644 index 0000000..f2c5dbd --- /dev/null +++ b/schema/pgsql-migrations/upgrade_153.sql @@ -0,0 +1,45 @@ +CREATE TYPE enum_owner_type AS ENUM('user', 'usergroup', 'role'); + +CREATE TABLE director_basket ( + uuid bytea CHECK(LENGTH(uuid) = 16) NOT NULL, + basket_name VARCHAR(64) NOT NULL, + owner_type enum_owner_type NOT NULL, + owner_value VARCHAR(255) NOT NULL, + objects text NOT NULL, -- json-encoded + PRIMARY KEY (uuid) +); + +CREATE UNIQUE INDEX basket_basket_name ON director_basket (basket_name); + + +CREATE TABLE director_basket_content ( + checksum bytea CHECK(LENGTH(checksum) = 20) NOT NULL, + summary VARCHAR(255) NOT NULL, -- json + content text NOT NULL, -- json + PRIMARY KEY (checksum) +); + + +CREATE TABLE director_basket_snapshot ( + basket_uuid bytea CHECK(LENGTH(basket_uuid) = 16) NOT NULL, + ts_create bigint NOT NULL, + content_checksum bytea CHECK(LENGTH(content_checksum) = 20) NOT NULL, + PRIMARY KEY (basket_uuid, ts_create), + CONSTRAINT basked_snapshot_basket + FOREIGN KEY (basket_uuid) + REFERENCES director_basket (uuid) + ON DELETE CASCADE + ON UPDATE RESTRICT, + CONSTRAINT basked_snapshot_content + FOREIGN KEY (content_checksum) + REFERENCES director_basket_content (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX basket_snapshot_sort_idx ON director_basket_snapshot (ts_create); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (153, NOW()); diff --git a/schema/pgsql-migrations/upgrade_154.sql b/schema/pgsql-migrations/upgrade_154.sql new file mode 100644 index 0000000..08274b0 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_154.sql @@ -0,0 +1,12 @@ + +UPDATE icinga_command_argument +SET argument_format = NULL +WHERE argument_value IS NULL; + +UPDATE icinga_command_argument +SET set_if_format = NULL +WHERE set_if IS NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (154, NOW()); diff --git a/schema/pgsql-migrations/upgrade_155.sql b/schema/pgsql-migrations/upgrade_155.sql new file mode 100644 index 0000000..d967e63 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_155.sql @@ -0,0 +1,22 @@ +CREATE TABLE icinga_servicegroup_service_resolved ( + servicegroup_id integer NOT NULL, + service_id integer NOT NULL, + PRIMARY KEY (servicegroup_id, service_id), + CONSTRAINT icinga_servicegroup_service_resolved_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_servicegroup_service_resolved_servicegroup + FOREIGN KEY (servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX servicegroup_service_resolved_service ON icinga_servicegroup_service_resolved (service_id); +CREATE INDEX servicegroup_service_resolved_servicegroup ON icinga_servicegroup_service_resolved (servicegroup_id); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (155, NOW()); diff --git a/schema/pgsql-migrations/upgrade_156.sql b/schema/pgsql-migrations/upgrade_156.sql new file mode 100644 index 0000000..aa80cb3 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_156.sql @@ -0,0 +1,6 @@ +DROP INDEX IF EXISTS command_object_name; +CREATE UNIQUE INDEX command_object_name ON icinga_command (object_name); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (156, NOW()); diff --git a/schema/pgsql-migrations/upgrade_157.sql b/schema/pgsql-migrations/upgrade_157.sql new file mode 100644 index 0000000..02ce370 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_157.sql @@ -0,0 +1,6 @@ +ALTER TABLE director_basket_content + ALTER COLUMN summary TYPE VARCHAR(500); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (157, NOW()); diff --git a/schema/pgsql-migrations/upgrade_158.sql b/schema/pgsql-migrations/upgrade_158.sql new file mode 100644 index 0000000..e9d3599 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_158.sql @@ -0,0 +1,6 @@ +DROP INDEX IF EXISTS notification_var_search_idx; +CREATE INDEX notification_var_search_idx ON icinga_notification_var (varname); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (158, NOW()); diff --git a/schema/pgsql-migrations/upgrade_160.sql b/schema/pgsql-migrations/upgrade_160.sql new file mode 100644 index 0000000..5258146 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_160.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_command + ADD COLUMN is_string enum_boolean NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (160, NOW()); diff --git a/schema/pgsql-migrations/upgrade_161.sql b/schema/pgsql-migrations/upgrade_161.sql new file mode 100644 index 0000000..b8618d9 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_161.sql @@ -0,0 +1,70 @@ +CREATE TABLE icinga_scheduled_downtime ( + id serial, + object_name character varying(255) NOT NULL, + zone_id integer DEFAULT NULL, + object_type enum_object_type_all NOT NULL, + disabled enum_boolean NOT NULL DEFAULT 'n', + apply_to enum_host_service NULL DEFAULT NULL, + assign_filter text DEFAULT NULL, + author character varying(255) DEFAULT NULL, + comment text DEFAULT NULL, + fixed enum_boolean DEFAULT NULL, + duration int DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_scheduled_downtime_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX scheduled_downtime_object_name ON icinga_scheduled_downtime (object_name); +CREATE INDEX scheduled_downtime_zone ON icinga_scheduled_downtime (zone_id); + + +CREATE TABLE icinga_scheduled_downtime_inheritance ( + scheduled_downtime_id integer NOT NULL, + parent_scheduled_downtime_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (scheduled_downtime_id, parent_scheduled_downtime_id), + CONSTRAINT icinga_scheduled_downtime_inheritance_scheduled_downtime + FOREIGN KEY (scheduled_downtime_id) + REFERENCES icinga_scheduled_downtime (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_scheduled_downtime_inheritance_parent_scheduled_downtime + FOREIGN KEY (parent_scheduled_downtime_id) + REFERENCES icinga_scheduled_downtime (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX scheduled_downtime_inheritance_unique_order ON icinga_scheduled_downtime_inheritance (scheduled_downtime_id, weight); +CREATE INDEX scheduled_downtime_inheritance_scheduled_downtime ON icinga_scheduled_downtime_inheritance (scheduled_downtime_id); +CREATE INDEX scheduled_downtime_inheritance_scheduled_downtime_parent ON icinga_scheduled_downtime_inheritance (parent_scheduled_downtime_id); + + +CREATE TABLE icinga_scheduled_downtime_range ( + scheduled_downtime_id serial, + range_key character varying(255) NOT NULL, + range_value character varying(255) NOT NULL, + range_type enum_timeperiod_range_type NOT NULL DEFAULT 'include', + merge_behaviour enum_merge_behaviour NOT NULL DEFAULT 'set', + PRIMARY KEY (scheduled_downtime_id, range_type, range_key), + CONSTRAINT icinga_scheduled_downtime_range_scheduled_downtime + FOREIGN KEY (scheduled_downtime_id) + REFERENCES icinga_scheduled_downtime (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX scheduled_downtime_range_scheduled_downtime ON icinga_scheduled_downtime_range (scheduled_downtime_id); +COMMENT ON COLUMN icinga_scheduled_downtime_range.range_key IS 'monday, ...'; +COMMENT ON COLUMN icinga_scheduled_downtime_range.range_value IS '00:00-24:00, ...'; +COMMENT ON COLUMN icinga_scheduled_downtime_range.range_type IS 'include -> ranges {}, exclude ranges_ignore {} - not yet'; +COMMENT ON COLUMN icinga_scheduled_downtime_range.merge_behaviour IS 'set -> = {}, add -> += {}, substract -> -= {}'; + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (161, NOW()); diff --git a/schema/pgsql-migrations/upgrade_162.sql b/schema/pgsql-migrations/upgrade_162.sql new file mode 100644 index 0000000..f90a14e --- /dev/null +++ b/schema/pgsql-migrations/upgrade_162.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_scheduled_downtime + ADD COLUMN with_services enum_boolean NULL DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (162, NOW()); diff --git a/schema/pgsql-migrations/upgrade_164.sql b/schema/pgsql-migrations/upgrade_164.sql new file mode 100644 index 0000000..eaa3ef0 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_164.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_dependency + ADD COLUMN parent_host_var character varying(128) DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (164, NOW()); diff --git a/schema/pgsql-migrations/upgrade_165.sql b/schema/pgsql-migrations/upgrade_165.sql new file mode 100644 index 0000000..225897f --- /dev/null +++ b/schema/pgsql-migrations/upgrade_165.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_host + ALTER COLUMN address TYPE character varying(255); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (165, NOW()); diff --git a/schema/pgsql-migrations/upgrade_166.sql b/schema/pgsql-migrations/upgrade_166.sql new file mode 100644 index 0000000..8d2edaf --- /dev/null +++ b/schema/pgsql-migrations/upgrade_166.sql @@ -0,0 +1,7 @@ +ALTER TYPE enum_sync_rule_object_type ADD VALUE 'scheduledDowntime'; +ALTER TYPE enum_sync_rule_object_type ADD VALUE 'notification'; +ALTER TYPE enum_sync_rule_object_type ADD VALUE 'dependency'; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (166, NOW()); diff --git a/schema/pgsql-migrations/upgrade_167.sql b/schema/pgsql-migrations/upgrade_167.sql new file mode 100644 index 0000000..25599cc --- /dev/null +++ b/schema/pgsql-migrations/upgrade_167.sql @@ -0,0 +1,24 @@ +CREATE TABLE director_daemon_info ( + instance_uuid_hex character varying(32) NOT NULL, -- random by daemon + schema_version SMALLINT NOT NULL, + fqdn character varying(255) NOT NULL, + username character varying(64) NOT NULL, + pid integer NOT NULL, + binary_path character varying(128) NOT NULL, + binary_realpath character varying(128) NOT NULL, + php_binary_path character varying(128) NOT NULL, + php_binary_realpath character varying(128) NOT NULL, + php_version character varying(64) NOT NULL, + php_integer_size SMALLINT NOT NULL, + running_with_systemd enum_boolean DEFAULT NULL, + ts_started bigint NOT NULL, + ts_stopped bigint DEFAULT NULL, + ts_last_modification bigint DEFAULT NULL, + ts_last_update bigint NOT NULL, + process_info text NOT NULL, + PRIMARY KEY (instance_uuid_hex) +); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (167, NOW()); diff --git a/schema/pgsql-migrations/upgrade_168.sql b/schema/pgsql-migrations/upgrade_168.sql new file mode 100644 index 0000000..7525a00 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_168.sql @@ -0,0 +1,25 @@ + +CREATE TABLE director_datafield_category ( + id serial, + category_name character varying(255) NOT NULL, + description text DEFAULT NULL, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX datafield_category_name ON director_datafield_category (category_name); + + +ALTER TABLE director_datafield + ADD COLUMN category_id integer DEFAULT NULL, + ADD CONSTRAINT director_datafield_category + FOREIGN KEY (category_id) + REFERENCES director_datafield_category (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +CREATE INDEX datafield_category ON director_datafield (category_id); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (168, NOW()); diff --git a/schema/pgsql-migrations/upgrade_169.sql b/schema/pgsql-migrations/upgrade_169.sql new file mode 100644 index 0000000..28b68bc --- /dev/null +++ b/schema/pgsql-migrations/upgrade_169.sql @@ -0,0 +1,8 @@ +CREATE DOMAIN d_smallint AS integer CHECK (VALUE >= 0) CHECK (VALUE < 65536); + +ALTER TABLE icinga_endpoint ALTER COLUMN port TYPE d_smallint; + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (169, NOW()); diff --git a/schema/pgsql-migrations/upgrade_170.sql b/schema/pgsql-migrations/upgrade_170.sql new file mode 100644 index 0000000..50cfb2b --- /dev/null +++ b/schema/pgsql-migrations/upgrade_170.sql @@ -0,0 +1,5 @@ +ALTER TYPE enum_sync_rule_update_policy ADD VALUE 'update-only' AFTER 'ignore'; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (170, NOW()); diff --git a/schema/pgsql-migrations/upgrade_171.sql b/schema/pgsql-migrations/upgrade_171.sql new file mode 100644 index 0000000..76ab309 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_171.sql @@ -0,0 +1,3 @@ +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (171, NOW()); diff --git a/schema/pgsql-migrations/upgrade_172.sql b/schema/pgsql-migrations/upgrade_172.sql new file mode 100644 index 0000000..49e66a2 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_172.sql @@ -0,0 +1,13 @@ +CREATE TYPE enum_sync_rule_purge_action AS ENUM('delete', 'disable'); + +ALTER TABLE sync_rule + ADD COLUMN purge_action enum_sync_rule_purge_action NULL DEFAULT NULL; + +UPDATE sync_rule SET purge_action = 'delete'; + +ALTER TABLE sync_rule + ALTER COLUMN purge_action SET NOT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (172, NOW()); diff --git a/schema/pgsql-migrations/upgrade_173.sql b/schema/pgsql-migrations/upgrade_173.sql new file mode 100644 index 0000000..fdd1b14 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_173.sql @@ -0,0 +1,6 @@ +ALTER TABLE sync_rule + ALTER COLUMN purge_action SET DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (173, NOW()); diff --git a/schema/pgsql-migrations/upgrade_174.sql b/schema/pgsql-migrations/upgrade_174.sql new file mode 100644 index 0000000..9b5c7ef --- /dev/null +++ b/schema/pgsql-migrations/upgrade_174.sql @@ -0,0 +1,61 @@ +ALTER TABLE icinga_zone DROP COLUMN IF EXISTS uuid; + +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; + +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; + +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; + +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; + +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; + +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; + +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; + +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; + +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; + +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; + +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; + +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; + +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; + +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; + +INSERT INTO director_schema_migration +(schema_version, migration_time) +VALUES (174, NOW()); diff --git a/schema/pgsql-migrations/upgrade_175.sql b/schema/pgsql-migrations/upgrade_175.sql new file mode 100644 index 0000000..81234fe --- /dev/null +++ b/schema/pgsql-migrations/upgrade_175.sql @@ -0,0 +1,512 @@ +CREATE TABLE director_branch ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + owner character varying(255) NOT NULL, + branch_name character varying(255) NOT NULL, + description text DEFAULT NULL, + ts_merge_request bigint DEFAULT NULL, + PRIMARY KEY(uuid) +); +CREATE UNIQUE INDEX branch_branch_name ON director_branch (branch_name); + +CREATE TYPE enum_branch_action AS ENUM('create', 'modify', 'delete'); + +CREATE TABLE director_branch_activity ( + timestamp_ns bigint NOT NULL, + object_uuid bytea NOT NULL CHECK(LENGTH(object_uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + action enum_branch_action NOT NULL, + object_table character varying(64) NOT NULL, + author character varying(255) NOT NULL, + former_properties text NOT NULL, + modified_properties text NOT NULL, + PRIMARY KEY (timestamp_ns), + CONSTRAINT branch_activity_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); +CREATE INDEX branch_activity_object_uuid ON director_branch_activity (object_uuid); +CREATE INDEX branch_activity_branch_uuid ON director_branch_activity (branch_uuid); + + +CREATE TABLE branched_icinga_host ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + display_name CHARACTER VARYING(255) DEFAULT NULL, + address character varying(255) DEFAULT NULL, + address6 character varying(45) DEFAULT NULL, + check_command character varying(255) DEFAULT NULL, + max_check_attempts integer DEFAULT NULL, + check_period character varying(255) DEFAULT NULL, + check_interval character varying(8) DEFAULT NULL, + retry_interval character varying(8) DEFAULT NULL, + check_timeout smallint DEFAULT NULL, + enable_notifications enum_boolean DEFAULT NULL, + enable_active_checks enum_boolean DEFAULT NULL, + enable_passive_checks enum_boolean DEFAULT NULL, + enable_event_handler enum_boolean DEFAULT NULL, + enable_flapping enum_boolean DEFAULT NULL, + enable_perfdata enum_boolean DEFAULT NULL, + event_command character varying(255) DEFAULT NULL, + flapping_threshold_high smallint default null, + flapping_threshold_low smallint default null, + volatile enum_boolean DEFAULT NULL, + zone character varying(255) DEFAULT NULL, + command_endpoint character varying(255) DEFAULT NULL, + notes text DEFAULT NULL, + notes_url character varying(255) DEFAULT NULL, + action_url character varying(255) DEFAULT NULL, + icon_image character varying(255) DEFAULT NULL, + icon_image_alt character varying(255) DEFAULT NULL, + has_agent enum_boolean DEFAULT NULL, + master_should_connect enum_boolean DEFAULT NULL, + accept_config enum_boolean DEFAULT NULL, + api_key character varying(40) DEFAULT NULL, + -- template_choice character varying(255) DEFAULT NULL, -- TODO: Forbid them! + + imports TEXT DEFAULT NULL, + groups TEXT DEFAULT NULL, + vars TEXT DEFAULT NULL, + + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_host_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX host_branch_object_name ON branched_icinga_host (branch_uuid, object_name); +CREATE INDEX branched_host_search_object_name ON branched_icinga_host (object_name); +CREATE INDEX branched_host_search_display_name ON branched_icinga_host (display_name); + + +CREATE TABLE branched_icinga_hostgroup ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + display_name character varying(255) DEFAULT NULL, + assign_filter text DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_hostgroup_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX hostgroup_branch_object_name ON branched_icinga_hostgroup (branch_uuid, object_name); +CREATE INDEX branched_hostgroup_search_object_name ON branched_icinga_hostgroup (object_name); +CREATE INDEX branched_hostgroup_search_display_name ON branched_icinga_hostgroup (display_name); + + +CREATE TABLE branched_icinga_servicegroup ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + display_name character varying(255) DEFAULT NULL, + assign_filter text DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_servicegroup_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX servicegroup_branch_object_name ON branched_icinga_servicegroup (branch_uuid, object_name); +CREATE INDEX branched_servicegroup_search_object_name ON branched_icinga_servicegroup (object_name); +CREATE INDEX branched_servicegroup_search_display_name ON branched_icinga_servicegroup (display_name); + + +CREATE TABLE branched_icinga_usergroup ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + display_name character varying(255) DEFAULT NULL, + assign_filter text DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_usergroup_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX usergroup_branch_object_name ON branched_icinga_usergroup (branch_uuid, object_name); +CREATE INDEX branched_usergroup_search_object_name ON branched_icinga_usergroup (object_name); +CREATE INDEX branched_usergroup_search_display_name ON branched_icinga_usergroup (display_name); + + +CREATE TABLE branched_icinga_user ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + display_name character varying(255) DEFAULT NULL, + email character varying(255) DEFAULT NULL, + pager character varying(255) DEFAULT NULL, + enable_notifications enum_boolean DEFAULT NULL, + period character varying(255) DEFAULT NULL, + zone character varying(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + groups TEXT DEFAULT NULL, + vars TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_user_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX user_branch_object_name ON branched_icinga_user (branch_uuid, object_name); +CREATE INDEX branched_user_search_object_name ON branched_icinga_user (object_name); +CREATE INDEX branched_user_search_display_name ON branched_icinga_user (display_name); + + +CREATE TABLE branched_icinga_zone ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + parent character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + is_global enum_boolean DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_zone_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX zone_branch_object_name ON branched_icinga_zone (branch_uuid, object_name); +CREATE INDEX branched_zone_search_object_name ON branched_icinga_zone (object_name); + + +CREATE TABLE branched_icinga_timeperiod ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + display_name character varying(255) DEFAULT NULL, + update_method character varying(64) DEFAULT NULL, + zone character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + prefer_includes enum_boolean DEFAULT NULL, + + imports TEXT DEFAULT NULL, + ranges TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_timeperiod_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX timeperiod_branch_object_name ON branched_icinga_timeperiod (branch_uuid, object_name); +CREATE INDEX branched_timeperiod_search_object_name ON branched_icinga_timeperiod (object_name); +CREATE INDEX branched_timeperiod_search_display_name ON branched_icinga_timeperiod (display_name); + + +CREATE TABLE branched_icinga_command ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean NOT NULL DEFAULT NULL, + methods_execute character varying(64) DEFAULT NULL, + command text DEFAULT NULL, + is_string enum_boolean DEFAULT NULL, +-- env text DEFAULT NULL, + timeout smallint DEFAULT NULL, + zone character varying(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + arguments TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_command_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX command_branch_object_name ON branched_icinga_command (branch_uuid, object_name); +CREATE INDEX branched_command_search_object_name ON branched_icinga_command (object_name); + + +CREATE TABLE branched_icinga_apiuser ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name CHARACTER VARYING(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean NOT NULL DEFAULT NULL, + password CHARACTER VARYING(255) DEFAULT NULL, + client_dn CHARACTER VARYING(64) DEFAULT NULL, + permissions TEXT DEFAULT NULL, + + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_apiuser_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX apiuser_branch_object_name ON branched_icinga_apiuser (branch_uuid, object_name); +CREATE INDEX branched_apiuser_search_object_name ON branched_icinga_apiuser (object_name); + + +CREATE TABLE branched_icinga_endpoint ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + zone character varying(255) DEFAULT NULL, + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean NOT NULL DEFAULT NULL, + host character varying(255) DEFAULT NULL, + port d_smallint DEFAULT NULL, + log_duration character varying(32) DEFAULT NULL, + apiuser character varying(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_endpoint_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX endpoint_branch_object_name ON branched_icinga_endpoint (branch_uuid, object_name); +CREATE INDEX branched_endpoint_search_object_name ON branched_icinga_endpoint (object_name); + + +CREATE TABLE branched_icinga_service ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + display_name character varying(255) DEFAULT NULL, + host character varying(255) DEFAULT NULL, + service_set character varying(255) DEFAULT NULL, + check_command character varying(255) DEFAULT NULL, + max_check_attempts integer DEFAULT NULL, + check_period character varying(255) DEFAULT NULL, + check_interval character varying(8) DEFAULT NULL, + retry_interval character varying(8) DEFAULT NULL, + check_timeout smallint DEFAULT NULL, + enable_notifications enum_boolean DEFAULT NULL, + enable_active_checks enum_boolean DEFAULT NULL, + enable_passive_checks enum_boolean DEFAULT NULL, + enable_event_handler enum_boolean DEFAULT NULL, + enable_flapping enum_boolean DEFAULT NULL, + enable_perfdata enum_boolean DEFAULT NULL, + event_command character varying(255) DEFAULT NULL, + flapping_threshold_high smallint DEFAULT NULL, + flapping_threshold_low smallint DEFAULT NULL, + volatile enum_boolean DEFAULT NULL, + zone character varying(255) DEFAULT NULL, + command_endpoint character varying(255) DEFAULT NULL, + notes text DEFAULT NULL, + notes_url character varying(255) DEFAULT NULL, + action_url character varying(255) DEFAULT NULL, + icon_image character varying(255) DEFAULT NULL, + icon_image_alt character varying(255) DEFAULT NULL, + use_agent enum_boolean DEFAULT NULL, + apply_for character varying(255) DEFAULT NULL, + use_var_overrides enum_boolean DEFAULT NULL, + assign_filter text DEFAULT NULL, + -- template_choice_id int DEFAULT NULL, + + imports TEXT DEFAULT NULL, + groups TEXT DEFAULT NULL, + vars TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_service_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX service_branch_object_name ON branched_icinga_service (branch_uuid, object_name); +CREATE INDEX branched_service_search_object_name ON branched_icinga_service (object_name); +CREATE INDEX branched_service_search_display_name ON branched_icinga_service (display_name); + + +CREATE TABLE branched_icinga_notification ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name CHARACTER VARYING(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + apply_to enum_host_service DEFAULT NULL, + host character varying(255) DEFAULT NULL, + service character varying(255) DEFAULT NULL, + times_begin integer DEFAULT NULL, + times_end integer DEFAULT NULL, + notification_interval integer DEFAULT NULL, + command character varying(255) DEFAULT NULL, + period character varying(255) DEFAULT NULL, + zone character varying(255) DEFAULT NULL, + assign_filter text DEFAULT NULL, + + states TEXT DEFAULT NULL, + types TEXT DEFAULT NULL, + users TEXT DEFAULT NULL, + usergroups TEXT DEFAULT NULL, + + imports TEXT DEFAULT NULL, + vars TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_notification_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX notification_branch_object_name ON branched_icinga_notification (branch_uuid, object_name); +CREATE INDEX branched_notification_search_object_name ON branched_icinga_notification (object_name); + + +CREATE TABLE branched_icinga_scheduled_downtime ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + zone_id integer DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + apply_to enum_host_service DEFAULT NULL, + assign_filter text DEFAULT NULL, + author character varying(255) DEFAULT NULL, + comment text DEFAULT NULL, + fixed enum_boolean DEFAULT NULL, + duration int DEFAULT NULL, + with_services enum_boolean DEFAULT NULL, + + imports TEXT DEFAULT NULL, + ranges TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_scheduled_downtime_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX scheduled_downtime_branch_object_name ON branched_icinga_scheduled_downtime (branch_uuid, object_name); +CREATE INDEX branched_scheduled_downtime_search_object_name ON branched_icinga_scheduled_downtime (object_name); + + +CREATE TABLE branched_icinga_dependency ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) NOT NULL, + object_type enum_object_type_all NOT NULL, + disabled enum_boolean DEFAULT 'n', + apply_to enum_host_service NULL DEFAULT NULL, + parent_host character varying(255) DEFAULT NULL, + parent_host_var character varying(128) DEFAULT NULL, + parent_service character varying(255) DEFAULT NULL, + child_host character varying(255) DEFAULT NULL, + child_service character varying(255) DEFAULT NULL, + disable_checks enum_boolean DEFAULT NULL, + disable_notifications enum_boolean DEFAULT NULL, + ignore_soft_states enum_boolean DEFAULT NULL, + period_id integer DEFAULT NULL, + zone_id integer DEFAULT NULL, + assign_filter text DEFAULT NULL, + parent_service_by_name character varying(255), + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_dependency_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX dependency_branch_object_name ON branched_icinga_dependency (branch_uuid, object_name); +CREATE INDEX branched_dependency_search_object_name ON branched_icinga_dependency (object_name); + + +INSERT INTO director_schema_migration +(schema_version, migration_time) +VALUES (175, NOW()); diff --git a/schema/pgsql-migrations/upgrade_176.sql b/schema/pgsql-migrations/upgrade_176.sql new file mode 100644 index 0000000..eadcb18 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_176.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_host ADD COLUMN custom_endpoint_name character varying(255) DEFAULT NULL; +ALTER TABLE branched_icinga_host ADD COLUMN custom_endpoint_name character varying(255) DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES ('176', NOW()); diff --git a/schema/pgsql-migrations/upgrade_177.sql b/schema/pgsql-migrations/upgrade_177.sql new file mode 100644 index 0000000..09784b1 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_177.sql @@ -0,0 +1,8 @@ +ALTER TABLE icinga_service_set ADD COLUMN uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16); +UPDATE icinga_service_set SET uuid = decode(replace(gen_random_uuid()::text, '-', ''), 'hex') WHERE uuid IS NULL; +ALTER TABLE icinga_service_set ALTER COLUMN uuid SET NOT NULL; +CREATE UNIQUE INDEX service_set_uuid ON icinga_service_set (uuid); + +INSERT INTO director_schema_migration +(schema_version, migration_time) +VALUES (177, NOW()); diff --git a/schema/pgsql-migrations/upgrade_178.sql b/schema/pgsql-migrations/upgrade_178.sql new file mode 100644 index 0000000..8419384 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_178.sql @@ -0,0 +1,23 @@ +CREATE TABLE director_activity_log_remark ( + first_related_activity bigint NOT NULL, + last_related_activity bigint NOT NULL, + remark TEXT NOT NULL, + PRIMARY KEY (first_related_activity, last_related_activity), + CONSTRAINT activity_log_remark_begin + FOREIGN KEY (first_related_activity) + REFERENCES director_activity_log (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT activity_log_remark_end + FOREIGN KEY (last_related_activity) + REFERENCES director_activity_log (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX first_related_activity ON director_activity_log_remark (first_related_activity); +CREATE INDEX last_related_activity ON director_activity_log_remark (last_related_activity); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (178, NOW()); diff --git a/schema/pgsql-migrations/upgrade_179.sql b/schema/pgsql-migrations/upgrade_179.sql new file mode 100644 index 0000000..d050eee --- /dev/null +++ b/schema/pgsql-migrations/upgrade_179.sql @@ -0,0 +1,5 @@ +CREATE INDEX start_time_idx ON director_deployment_log (start_time); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (179, NOW()); diff --git a/schema/pgsql-migrations/upgrade_180.sql b/schema/pgsql-migrations/upgrade_180.sql new file mode 100644 index 0000000..b6ae70d --- /dev/null +++ b/schema/pgsql-migrations/upgrade_180.sql @@ -0,0 +1,32 @@ +CREATE TABLE branched_icinga_service_set ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + host character varying(255) DEFAULT NULL, + description TEXT DEFAULT NULL, + assign_filter text DEFAULT NULL, + + + imports TEXT DEFAULT NULL, + vars TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_service_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX service_set_branch_object_name ON branched_icinga_service_set (branch_uuid, object_name); +CREATE INDEX branched_service_set_search_object_name ON branched_icinga_service_set (object_name); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (180, NOW()); diff --git a/schema/pgsql-migrations/upgrade_181.sql b/schema/pgsql-migrations/upgrade_181.sql new file mode 100644 index 0000000..0fdd2a6 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_181.sql @@ -0,0 +1,19 @@ +ALTER TABLE branched_icinga_host DROP CONSTRAINT branched_icinga_host_uuid_key; +ALTER TABLE branched_icinga_hostgroup DROP CONSTRAINT branched_icinga_hostgroup_uuid_key; +ALTER TABLE branched_icinga_servicegroup DROP CONSTRAINT branched_icinga_servicegroup_uuid_key; +ALTER TABLE branched_icinga_usergroup DROP CONSTRAINT branched_icinga_usergroup_uuid_key; +ALTER TABLE branched_icinga_user DROP CONSTRAINT branched_icinga_user_uuid_key; +ALTER TABLE branched_icinga_zone DROP CONSTRAINT branched_icinga_zone_uuid_key; +ALTER TABLE branched_icinga_timeperiod DROP CONSTRAINT branched_icinga_timeperiod_uuid_key; +ALTER TABLE branched_icinga_command DROP CONSTRAINT branched_icinga_command_uuid_key; +ALTER TABLE branched_icinga_apiuser DROP CONSTRAINT branched_icinga_apiuser_uuid_key; +ALTER TABLE branched_icinga_endpoint DROP CONSTRAINT branched_icinga_endpoint_uuid_key; +ALTER TABLE branched_icinga_service DROP CONSTRAINT branched_icinga_service_uuid_key; +ALTER TABLE branched_icinga_service_set DROP CONSTRAINT branched_icinga_service_set_uuid_key; +ALTER TABLE branched_icinga_notification DROP CONSTRAINT branched_icinga_notification_uuid_key; +ALTER TABLE branched_icinga_scheduled_downtime DROP CONSTRAINT branched_icinga_scheduled_downtime_uuid_key; +ALTER TABLE branched_icinga_dependency DROP CONSTRAINT branched_icinga_dependency_uuid_key; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (181, NOW()); diff --git a/schema/pgsql-migrations/upgrade_182.sql b/schema/pgsql-migrations/upgrade_182.sql new file mode 100644 index 0000000..634d048 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_182.sql @@ -0,0 +1,14 @@ +DELETE FROM sync_run AS sr + WHERE EXISTS ( + SELECT 1 FROM sync_rule AS s + WHERE s.id = sr.rule_id + AND s.object_type != 'datalistEntry' + AND sr.start_time > '2022-09-21 00:00:00' + ) AND sr.last_former_activity = sr.last_related_activity; + +DELETE FROM sync_run + WHERE (objects_created + objects_deleted + objects_modified) = 0; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (182, NOW()); diff --git a/schema/pgsql-migrations/upgrade_77.sql b/schema/pgsql-migrations/upgrade_77.sql new file mode 100644 index 0000000..de10121 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_77.sql @@ -0,0 +1,72 @@ +ALTER TYPE enum_merge_behaviour ADD VALUE 'override'; + + +CREATE TABLE icinga_notification_states_set ( + notification_id integer NOT NULL, + property enum_state_name NOT NULL, + merge_behaviour enum_merge_behaviour NOT NULL DEFAULT 'override', + PRIMARY KEY (notification_id, property, merge_behaviour), + CONSTRAINT icinga_notification_states_set_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +COMMENT ON COLUMN icinga_notification_states_set.merge_behaviour IS 'override: = [], extend: += [], blacklist: -= []'; + + +CREATE TABLE icinga_notification_types_set ( + notification_id integer NOT NULL, + property enum_type_name NOT NULL, + merge_behaviour enum_merge_behaviour NOT NULL DEFAULT 'override', + PRIMARY KEY (notification_id, property, merge_behaviour), + CONSTRAINT icinga_notification_types_set_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +COMMENT ON COLUMN icinga_notification_types_set.merge_behaviour IS 'override: = [], extend: += [], blacklist: -= []'; + + +CREATE TABLE icinga_notification_var ( + notification_id integer NOT NULL, + varname VARCHAR(255) DEFAULT NULL, + varvalue TEXT DEFAULT NULL, + format enum_property_format, + PRIMARY KEY (notification_id, varname), + CONSTRAINT icinga_notification_var_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX notification_var_search_idx ON icinga_notification_var (varname); + + +CREATE TABLE icinga_notification_inheritance ( + notification_id integer NOT NULL, + parent_notification_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (notification_id, parent_notification_id), + CONSTRAINT icinga_notification_inheritance_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_inheritance_parent_notification + FOREIGN KEY (parent_notification_id) + REFERENCES icinga_notification (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX notification_inheritance ON icinga_notification_inheritance (notification_id, weight); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (77, NOW()); diff --git a/schema/pgsql-migrations/upgrade_78.sql b/schema/pgsql-migrations/upgrade_78.sql new file mode 100644 index 0000000..a95d294 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_78.sql @@ -0,0 +1,25 @@ +CREATE TABLE icinga_user_field ( + user_id integer NOT NULL, + datafield_id integer NOT NULL, + is_required enum_boolean NOT NULL, + PRIMARY KEY (user_id, datafield_id), + CONSTRAINT icinga_user_field_user + FOREIGN KEY (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_user_field_datafield + FOREIGN KEY (datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX user_field_key ON icinga_user_field (user_id, datafield_id); +CREATE INDEX user_field_user ON icinga_user_field (user_id); +CREATE INDEX user_field_datafield ON icinga_user_field (datafield_id); +COMMENT ON COLUMN icinga_user_field.user_id IS 'Makes only sense for templates'; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (78, NOW()); diff --git a/schema/pgsql-migrations/upgrade_79.sql b/schema/pgsql-migrations/upgrade_79.sql new file mode 100644 index 0000000..2b9551d --- /dev/null +++ b/schema/pgsql-migrations/upgrade_79.sql @@ -0,0 +1,11 @@ +ALTER TABLE icinga_user_states_set + DROP CONSTRAINT icinga_user_states_set_pkey, + ADD PRIMARY KEY (user_id, property, merge_behaviour); + +ALTER TABLE icinga_user_types_set + DROP CONSTRAINT icinga_user_types_set_pkey, + ADD PRIMARY KEY (user_id, property, merge_behaviour); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (79, NOW()); diff --git a/schema/pgsql-migrations/upgrade_80.sql b/schema/pgsql-migrations/upgrade_80.sql new file mode 100644 index 0000000..074af1c --- /dev/null +++ b/schema/pgsql-migrations/upgrade_80.sql @@ -0,0 +1,11 @@ +ALTER TABLE icinga_timeperiod_range + DROP CONSTRAINT icinga_timeperiod_range_timeperiod, + ADD CONSTRAINT icinga_timeperiod_range_timeperiod + FOREIGN KEY (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (80, NOW()); diff --git a/schema/pgsql-migrations/upgrade_81.sql b/schema/pgsql-migrations/upgrade_81.sql new file mode 100644 index 0000000..6a52a46 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_81.sql @@ -0,0 +1,5 @@ +ALTER TABLE import_run ALTER COLUMN end_time DROP NOT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (81, NOW()); diff --git a/schema/pgsql-migrations/upgrade_82.sql b/schema/pgsql-migrations/upgrade_82.sql new file mode 100644 index 0000000..0c6f5b8 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_82.sql @@ -0,0 +1,12 @@ +ALTER TYPE enum_sync_rule_object_type ADD VALUE 'service' AFTER 'host'; +ALTER TYPE enum_sync_rule_object_type ADD VALUE 'command' AFTER 'service'; +ALTER TYPE enum_sync_rule_object_type ADD VALUE 'hostgroup'; +ALTER TYPE enum_sync_rule_object_type ADD VALUE 'servicegroup'; +ALTER TYPE enum_sync_rule_object_type ADD VALUE 'usergroup'; +ALTER TYPE enum_sync_rule_object_type ADD VALUE 'datalistEntry'; +ALTER TYPE enum_sync_rule_object_type ADD VALUE 'endpoint'; +ALTER TYPE enum_sync_rule_object_type ADD VALUE 'zone'; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (82, NOW()); diff --git a/schema/pgsql-migrations/upgrade_83.sql b/schema/pgsql-migrations/upgrade_83.sql new file mode 100644 index 0000000..2a2fecf --- /dev/null +++ b/schema/pgsql-migrations/upgrade_83.sql @@ -0,0 +1,7 @@ +ALTER TABLE icinga_command ALTER COLUMN command TYPE text; +ALTER TABLE icinga_command ALTER COLUMN command DROP DEFAULT; +ALTER TABLE icinga_command ALTER COLUMN command SET DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (83, NOW()); diff --git a/schema/pgsql-migrations/upgrade_84.sql b/schema/pgsql-migrations/upgrade_84.sql new file mode 100644 index 0000000..1de287a --- /dev/null +++ b/schema/pgsql-migrations/upgrade_84.sql @@ -0,0 +1,5 @@ +ALTER TABLE icinga_usergroup DROP COLUMN zone_id; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (84, NOW()); diff --git a/schema/pgsql-migrations/upgrade_85.sql b/schema/pgsql-migrations/upgrade_85.sql new file mode 100644 index 0000000..6aca709 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_85.sql @@ -0,0 +1,15 @@ +CREATE TABLE icinga_notification_assignment ( + id bigserial, + notification_id integer NOT NULL, + filter_string TEXT NOT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_notification_assignment + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (85, NOW()); diff --git a/schema/pgsql-migrations/upgrade_86.sql b/schema/pgsql-migrations/upgrade_86.sql new file mode 100644 index 0000000..9672f3e --- /dev/null +++ b/schema/pgsql-migrations/upgrade_86.sql @@ -0,0 +1,35 @@ +CREATE TABLE icinga_notification_user ( + notification_id integer NOT NULL, + user_id integer NOT NULL, + PRIMARY KEY (notification_id, user_id), + CONSTRAINT icinga_notification_user_user + FOREIGN KEY (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_user_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE TABLE icinga_notification_usergroup ( + notification_id integer NOT NULL, + usergroup_id integer NOT NULL, + PRIMARY KEY (notification_id, usergroup_id), + CONSTRAINT icinga_notification_usergroup_usergroup + FOREIGN KEY (usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_usergroup_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (86, NOW()); diff --git a/schema/pgsql-migrations/upgrade_88.sql b/schema/pgsql-migrations/upgrade_88.sql new file mode 100644 index 0000000..1f65333 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_88.sql @@ -0,0 +1,6 @@ +ALTER TABLE director_generated_config_file + ALTER COLUMN file_path TYPE character varying(128); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (88, NOW()); diff --git a/schema/pgsql-migrations/upgrade_89.sql b/schema/pgsql-migrations/upgrade_89.sql new file mode 100644 index 0000000..58b1542 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_89.sql @@ -0,0 +1,5 @@ +ALTER TABLE icinga_command_argument ADD required enum_boolean DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (89, NOW()); diff --git a/schema/pgsql-migrations/upgrade_90.sql b/schema/pgsql-migrations/upgrade_90.sql new file mode 100644 index 0000000..e2a6f09 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_90.sql @@ -0,0 +1,6 @@ +CREATE TYPE enum_assign_type AS ENUM('assign', 'ignore'); +ALTER TABLE icinga_service_assignment ADD assign_type enum_assign_type NOT NULL DEFAULT 'assign'; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (90, NOW()); diff --git a/schema/pgsql-migrations/upgrade_91.sql b/schema/pgsql-migrations/upgrade_91.sql new file mode 100644 index 0000000..c20a24a --- /dev/null +++ b/schema/pgsql-migrations/upgrade_91.sql @@ -0,0 +1,5 @@ +ALTER TABLE icinga_notification_assignment ADD assign_type enum_assign_type NOT NULL DEFAULT 'assign'; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (91, NOW()); diff --git a/schema/pgsql-migrations/upgrade_92.sql b/schema/pgsql-migrations/upgrade_92.sql new file mode 100644 index 0000000..670a996 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_92.sql @@ -0,0 +1,27 @@ +DELETE FROM director_datalist_entry WHERE entry_name IS NULL; +ALTER TABLE director_datalist_entry ALTER COLUMN entry_name DROP DEFAULT; +ALTER TABLE director_datalist_entry ALTER COLUMN entry_name SET NOT NULL; + +DELETE FROM icinga_command_var WHERE varname IS NULL; +ALTER TABLE icinga_command_var ALTER COLUMN varname DROP DEFAULT; +ALTER TABLE icinga_command_var ALTER COLUMN varname SET NOT NULL; + +DELETE FROM icinga_host_var WHERE varname IS NULL; +ALTER TABLE icinga_host_var ALTER COLUMN varname DROP DEFAULT; +ALTER TABLE icinga_host_var ALTER COLUMN varname SET NOT NULL; + +DELETE FROM icinga_service_var WHERE varname IS NULL; +ALTER TABLE icinga_service_var ALTER COLUMN varname DROP DEFAULT; +ALTER TABLE icinga_service_var ALTER COLUMN varname SET NOT NULL; + +DELETE FROM icinga_user_var WHERE varname IS NULL; +ALTER TABLE icinga_user_var ALTER COLUMN varname DROP DEFAULT; +ALTER TABLE icinga_user_var ALTER COLUMN varname SET NOT NULL; + +DELETE FROM icinga_notification_var WHERE varname IS NULL; +ALTER TABLE icinga_notification_var ALTER COLUMN varname DROP DEFAULT; +ALTER TABLE icinga_notification_var ALTER COLUMN varname SET NOT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (92, NOW()); diff --git a/schema/pgsql-migrations/upgrade_93.sql b/schema/pgsql-migrations/upgrade_93.sql new file mode 100644 index 0000000..680c3f6 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_93.sql @@ -0,0 +1,24 @@ +CREATE TYPE enum_sync_state AS ENUM( + 'unknown', + 'in-sync', + 'pending-changes', + 'failing' +); + +ALTER TABLE sync_rule + ADD COLUMN sync_state enum_sync_state NOT NULL DEFAULT 'unknown', + ADD COLUMN last_error_message character varying(255) NULL DEFAULT NULL, + ADD COLUMN last_attempt timestamp with time zone NULL DEFAULT NULL +; + +UPDATE sync_rule + SET last_attempt = lr.start_time + FROM ( + SELECT rule_id, MAX(start_time) AS start_time + FROM sync_run + GROUP BY rule_id + ) lr WHERE sync_rule.id = lr.rule_id; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (93, NOW()); diff --git a/schema/pgsql-migrations/upgrade_94.sql b/schema/pgsql-migrations/upgrade_94.sql new file mode 100644 index 0000000..5341a8b --- /dev/null +++ b/schema/pgsql-migrations/upgrade_94.sql @@ -0,0 +1,34 @@ +CREATE TABLE director_job ( + id serial, + job_name character varying(64) NOT NULL, + job_class character varying(72) NOT NULL, + disabled enum_boolean NOT NULL DEFAULT 'n', + run_interval integer NOT NULL, -- seconds + last_attempt_succeeded enum_boolean DEFAULT NULL, + ts_last_attempt timestamp with time zone DEFAULT NULL, + ts_last_error timestamp with time zone DEFAULT NULL, + last_error_message text NULL DEFAULT NULL, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX director_job_unique_job_name ON director_job (job_name); + + +CREATE TABLE director_job_setting ( + job_id integer NOT NULL, + setting_name character varying(64) NOT NULL, + setting_value text DEFAULT NULL, + PRIMARY KEY (job_id, setting_name), + CONSTRAINT director_job_setting_job + FOREIGN KEY (job_id) + REFERENCES director_job (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX director_job_setting_job ON director_job_setting (job_id); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (94, NOW()); diff --git a/schema/pgsql-migrations/upgrade_95.sql b/schema/pgsql-migrations/upgrade_95.sql new file mode 100644 index 0000000..21a212b --- /dev/null +++ b/schema/pgsql-migrations/upgrade_95.sql @@ -0,0 +1,20 @@ +ALTER TABLE import_source + ADD COLUMN import_state enum_sync_state NOT NULL DEFAULT 'unknown', + ADD COLUMN last_error_message character varying(255) NULL DEFAULT NULL, + ADD COLUMN last_attempt timestamp with time zone NULL DEFAULT NULL +; + + +UPDATE import_source + SET last_attempt = ir.start_time + FROM ( + SELECT source_id, MAX(start_time) AS start_time + FROM import_run + GROUP BY source_id + ) ir WHERE import_source.id = ir.source_id; + + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (95, NOW()); diff --git a/schema/pgsql-migrations/upgrade_96.sql b/schema/pgsql-migrations/upgrade_96.sql new file mode 100644 index 0000000..f96daa7 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_96.sql @@ -0,0 +1,7 @@ +CREATE TYPE enum_host_service AS ENUM('host', 'service'); + +ALTER TABLE icinga_notification ADD apply_to enum_host_service NULL DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (96, NOW()); diff --git a/schema/pgsql-migrations/upgrade_97.sql b/schema/pgsql-migrations/upgrade_97.sql new file mode 100644 index 0000000..5c9f1bc --- /dev/null +++ b/schema/pgsql-migrations/upgrade_97.sql @@ -0,0 +1,11 @@ +ALTER TABLE director_job + ADD COLUMN timeperiod_id integer DEFAULT NULL, + ADD CONSTRAINT director_job_period + FOREIGN KEY (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (97, NOW()); diff --git a/schema/pgsql-migrations/upgrade_98.sql b/schema/pgsql-migrations/upgrade_98.sql new file mode 100644 index 0000000..006ae88 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_98.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE FUNCTION unix_timestamp(timestamp with time zone) RETURNS bigint AS ' + SELECT EXTRACT(EPOCH FROM $1)::bigint AS result +' LANGUAGE sql; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (98, NOW()); diff --git a/schema/pgsql.sql b/schema/pgsql.sql new file mode 100644 index 0000000..b9b2cf8 --- /dev/null +++ b/schema/pgsql.sql @@ -0,0 +1,2781 @@ +-- +-- PostgreSQL schema +-- ================= +-- +-- You should normally not be required to care about schema handling. +-- Director does all the migrations for you and guides you either in +-- the frontend or provides everything you need for automated migration +-- handling. Please find more related information in our documentation. + +CREATE TYPE enum_activity_action AS ENUM('create', 'delete', 'modify'); +CREATE TYPE enum_boolean AS ENUM('y', 'n'); +CREATE TYPE enum_property_format AS ENUM('string', 'expression', 'json'); +CREATE TYPE enum_object_type_all AS ENUM('object', 'template', 'apply', 'external_object'); -- TODO: can we check for an invalid +CREATE TYPE enum_object_type AS ENUM('object', 'template', 'external_object'); +CREATE TYPE enum_timeperiod_range_type AS ENUM('include', 'exclude'); +CREATE TYPE enum_merge_behaviour AS ENUM('set', 'add', 'substract', 'override'); +CREATE TYPE enum_set_merge_behaviour AS ENUM('override', 'extend', 'blacklist'); +CREATE TYPE enum_command_object_type AS ENUM('object', 'template', 'external_object'); +CREATE TYPE enum_apply_object_type AS ENUM('object', 'template', 'apply', 'external_object'); +CREATE TYPE enum_state_name AS ENUM('OK', 'Warning', 'Critical', 'Unknown', 'Up', 'Down'); +CREATE TYPE enum_type_name AS ENUM('DowntimeStart', 'DowntimeEnd', 'DowntimeRemoved', 'Custom', 'Acknowledgement', 'Problem', 'Recovery', 'FlappingStart', 'FlappingEnd'); +CREATE TYPE enum_sync_rule_object_type AS ENUM( + 'host', + 'service', + 'command', + 'user', + 'hostgroup', + 'servicegroup', + 'usergroup', + 'datalistEntry', + 'endpoint', + 'zone', + 'timePeriod', + 'serviceSet', + 'scheduledDowntime', + 'notification', + 'dependency' +); +CREATE TYPE enum_sync_rule_update_policy AS ENUM('merge', 'override', 'ignore', 'update-only'); +CREATE TYPE enum_sync_rule_purge_action AS ENUM('delete', 'disable'); +CREATE TYPE enum_sync_property_merge_policy AS ENUM('override', 'merge'); +CREATE TYPE enum_sync_state AS ENUM( + 'unknown', + 'in-sync', + 'pending-changes', + 'failing' +); +CREATE TYPE enum_host_service AS ENUM('host', 'service'); +CREATE TYPE enum_owner_type AS ENUM('user', 'usergroup', 'role'); +CREATE DOMAIN d_smallint AS integer CHECK (VALUE >= 0) CHECK (VALUE < 65536); + +CREATE OR REPLACE FUNCTION unix_timestamp(timestamp with time zone) RETURNS bigint AS ' + SELECT EXTRACT(EPOCH FROM $1)::bigint AS result +' LANGUAGE sql; + + +CREATE TABLE director_daemon_info ( + instance_uuid_hex character varying(32) NOT NULL, -- random by daemon + schema_version SMALLINT NOT NULL, + fqdn character varying(255) NOT NULL, + username character varying(64) NOT NULL, + pid integer NOT NULL, + binary_path character varying(128) NOT NULL, + binary_realpath character varying(128) NOT NULL, + php_binary_path character varying(128) NOT NULL, + php_binary_realpath character varying(128) NOT NULL, + php_version character varying(64) NOT NULL, + php_integer_size SMALLINT NOT NULL, + running_with_systemd enum_boolean DEFAULT NULL, + ts_started bigint NOT NULL, + ts_stopped bigint DEFAULT NULL, + ts_last_modification bigint DEFAULT NULL, + ts_last_update bigint NOT NULL, + process_info text NOT NULL, + PRIMARY KEY (instance_uuid_hex) +); + + +CREATE TABLE director_activity_log ( + id bigserial, + object_type character varying(64) NOT NULL, + object_name character varying(255) NOT NULL, + action_name enum_activity_action NOT NULL, + old_properties text DEFAULT NULL, + new_properties text DEFAULT NULL, + author character varying(64) NOT NULL, + change_time timestamp with time zone NOT NULL, + checksum bytea NOT NULL UNIQUE CHECK(LENGTH(checksum) = 20), + parent_checksum bytea DEFAULT NULL CHECK(parent_checksum IS NULL OR LENGTH(checksum) = 20), + PRIMARY KEY (id) +); + +CREATE INDEX activity_log_sort_idx ON director_activity_log (change_time); +CREATE INDEX activity_log_search_idx ON director_activity_log (object_name); +CREATE INDEX activity_log_search_idx2 ON director_activity_log (object_type, object_name, change_time); +CREATE INDEX activity_log_author ON director_activity_log (author); +COMMENT ON COLUMN director_activity_log.old_properties IS 'Property hash, JSON'; +COMMENT ON COLUMN director_activity_log.new_properties IS 'Property hash, JSON'; + +CREATE TABLE director_activity_log_remark ( + first_related_activity bigint NOT NULL, + last_related_activity bigint NOT NULL, + remark TEXT NOT NULL, + PRIMARY KEY (first_related_activity, last_related_activity), + CONSTRAINT activity_log_remark_begin + FOREIGN KEY (first_related_activity) + REFERENCES director_activity_log (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT activity_log_remark_end + FOREIGN KEY (last_related_activity) + REFERENCES director_activity_log (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX first_related_activity ON director_activity_log_remark (first_related_activity); +CREATE INDEX last_related_activity ON director_activity_log_remark (last_related_activity); + + +CREATE TABLE director_basket ( + uuid bytea CHECK(LENGTH(uuid) = 16) NOT NULL, + basket_name VARCHAR(64) NOT NULL, + owner_type enum_owner_type NOT NULL, + owner_value VARCHAR(255) NOT NULL, + objects text NOT NULL, -- json-encoded + PRIMARY KEY (uuid) +); + +CREATE UNIQUE INDEX basket_basket_name ON director_basket (basket_name); + + +CREATE TABLE director_basket_content ( + checksum bytea CHECK(LENGTH(checksum) = 20) NOT NULL, + summary VARCHAR(500) NOT NULL, -- json + content text NOT NULL, -- json + PRIMARY KEY (checksum) +); + + +CREATE TABLE director_basket_snapshot ( + basket_uuid bytea CHECK(LENGTH(basket_uuid) = 16) NOT NULL, + ts_create bigint NOT NULL, + content_checksum bytea CHECK(LENGTH(content_checksum) = 20) NOT NULL, + PRIMARY KEY (basket_uuid, ts_create), + CONSTRAINT basked_snapshot_basket + FOREIGN KEY (basket_uuid) + REFERENCES director_basket (uuid) + ON DELETE CASCADE + ON UPDATE RESTRICT, + CONSTRAINT basked_snapshot_content + FOREIGN KEY (content_checksum) + REFERENCES director_basket_content (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX basket_snapshot_sort_idx ON director_basket_snapshot (ts_create); + + +CREATE TABLE director_generated_config ( + checksum bytea CHECK(LENGTH(checksum) = 20), + director_version character varying(64) DEFAULT NULL, + director_db_version integer DEFAULT NULL, + duration integer DEFAULT NULL, + first_activity_checksum bytea NOT NULL CHECK(LENGTH(first_activity_checksum) = 20), + last_activity_checksum bytea NOT NULL CHECK(LENGTH(last_activity_checksum) = 20), + PRIMARY KEY (checksum), + CONSTRAINT director_generated_config_activity + FOREIGN KEY (last_activity_checksum) + REFERENCES director_activity_log (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX activity_checksum ON director_generated_config (last_activity_checksum); +COMMENT ON COLUMN director_generated_config.checksum IS 'SHA1(last_activity_checksum;file_path=checksum;file_path=checksum;...)'; +COMMENT ON COLUMN director_generated_config.duration IS 'Config generation duration (ms)'; + + +CREATE TABLE director_generated_file ( + checksum bytea CHECK(LENGTH(checksum) = 20), + content text DEFAULT NULL, + cnt_object SMALLINT NOT NULL DEFAULT 0, + cnt_template SMALLINT NOT NULL DEFAULT 0, + cnt_apply SMALLINT NOT NULL DEFAULT 0, + PRIMARY KEY (checksum) +); + +COMMENT ON COLUMN director_generated_file.checksum IS 'SHA1(content)'; + + +CREATE TABLE director_generated_config_file ( + config_checksum bytea CHECK(LENGTH(config_checksum) = 20), + file_checksum bytea CHECK(LENGTH(file_checksum) = 20), + file_path character varying(128) NOT NULL, + PRIMARY KEY (config_checksum, file_path), + CONSTRAINT director_generated_config_file_config + FOREIGN KEY (config_checksum) + REFERENCES director_generated_config (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT director_generated_config_file_file + FOREIGN KEY (file_checksum) + REFERENCES director_generated_file (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX config ON director_generated_config_file (config_checksum); +CREATE INDEX checksum ON director_generated_config_file (file_checksum); +COMMENT ON COLUMN director_generated_config_file.file_path IS 'e.g. zones/nafta/hosts.conf'; + + +CREATE TABLE director_deployment_log ( + id bigserial, + config_checksum bytea CHECK(LENGTH(config_checksum) = 20), + last_activity_checksum bytea CHECK(LENGTH(config_checksum) = 20), + peer_identity character varying(64) NOT NULL, + start_time timestamp with time zone NOT NULL, + end_time timestamp with time zone DEFAULT NULL, + abort_time timestamp with time zone DEFAULT NULL, + duration_connection integer DEFAULT NULL, + duration_dump integer DEFAULT NULL, + stage_name CHARACTER VARYING(96), + stage_collected enum_boolean DEFAULT NULL, + connection_succeeded enum_boolean DEFAULT NULL, + dump_succeeded enum_boolean DEFAULT NULL, + startup_succeeded enum_boolean DEFAULT NULL, + username character varying(64) DEFAULT NULL, + startup_log text DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT config_checksum + FOREIGN KEY (config_checksum) + REFERENCES director_generated_config (checksum) + ON DELETE SET NULL + ON UPDATE RESTRICT +); + +COMMENT ON COLUMN director_deployment_log.duration_connection IS 'The time it took to connect to an Icinga node (ms)'; +COMMENT ON COLUMN director_deployment_log.duration_dump IS 'Time spent dumping the config (ms)'; +COMMENT ON COLUMN director_deployment_log.username IS 'The user that triggered this deployment'; + +CREATE INDEX start_time_idx ON director_deployment_log (start_time); + + +CREATE TABLE director_datalist ( + id serial, + list_name character varying(255) NOT NULL, + owner character varying(255) NOT NULL, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX datalist_list_name ON director_datalist (list_name); + + +CREATE TABLE director_datalist_entry ( + list_id integer NOT NULL, + entry_name character varying(255) NOT NULL, + entry_value text DEFAULT NULL, + format enum_property_format, + allowed_roles character varying(255) DEFAULT NULL, + PRIMARY KEY (list_id, entry_name), + CONSTRAINT director_datalist_entry_datalist + FOREIGN KEY (list_id) + REFERENCES director_datalist (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX datalist_entry_datalist ON director_datalist_entry (list_id); + + +CREATE TABLE director_datafield_category ( + id serial, + category_name character varying(255) NOT NULL, + description text DEFAULT NULL, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX datafield_category_name ON director_datafield_category (category_name); + + +CREATE TABLE director_datafield ( + id serial, + category_id integer DEFAULT NULL, + varname character varying(64) NOT NULL, + caption character varying(255) NOT NULL, + description text DEFAULT NULL, + datatype character varying(255) NOT NULL, +-- datatype_param? multiple ones? + format enum_property_format, + PRIMARY KEY (id), + CONSTRAINT director_datafield_category + FOREIGN KEY (category_id) + REFERENCES director_datafield_category (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE INDEX search_idx ON director_datafield (varname); +CREATE INDEX datafield_category ON director_datafield (category_id); + + +CREATE TABLE director_datafield_setting ( + datafield_id integer NOT NULL, + setting_name character varying(64) NOT NULL, + setting_value text NOT NULL, + PRIMARY KEY (datafield_id, setting_name), + CONSTRAINT datafield_id_settings + FOREIGN KEY (datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX director_datafield_datafield ON director_datafield_setting (datafield_id); + + +CREATE TABLE director_schema_migration ( + schema_version SMALLINT NOT NULL, + migration_time TIMESTAMP WITH TIME ZONE NOT NULL, + PRIMARY KEY(schema_version) +); + + +CREATE TABLE director_setting ( + setting_name character varying(64) NOT NULL, + setting_value character varying(255) NOT NULL, + PRIMARY KEY(setting_name) +); + + +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, + disabled enum_boolean NOT NULL DEFAULT 'n', + is_global enum_boolean NOT NULL DEFAULT 'n', + PRIMARY KEY (id), + CONSTRAINT icinga_zone_parent_zone + FOREIGN KEY (parent_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE INDEX zone_parent ON icinga_zone (parent_id); + + +CREATE TABLE icinga_zone_inheritance ( + zone_id integer NOT NULL, + parent_zone_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (zone_id, parent_zone_id), + CONSTRAINT icinga_zone_inheritance_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_zone_inheritance_parent_zone + FOREIGN KEY (parent_zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX zone_inheritance_unique_order ON icinga_zone_inheritance (zone_id, weight); +CREATE INDEX zone_inheritance_zone ON icinga_zone_inheritance (zone_id); +CREATE INDEX zone_inheritance_zone_parent ON icinga_zone_inheritance (parent_zone_id); + + +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, + zone_id integer DEFAULT NULL, + object_type enum_object_type_all NOT NULL, + disabled enum_boolean NOT NULL DEFAULT 'n', + prefer_includes enum_boolean DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_timeperiod_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +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'; + + +CREATE TABLE icinga_timeperiod_inheritance ( + timeperiod_id integer NOT NULL, + parent_timeperiod_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (timeperiod_id, parent_timeperiod_id), + CONSTRAINT icinga_timeperiod_inheritance_timeperiod + FOREIGN KEY (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_timeperiod_inheritance_parent_timeperiod + FOREIGN KEY (parent_timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX timeperiod_inheritance_unique_order ON icinga_timeperiod_inheritance (timeperiod_id, weight); +CREATE INDEX timeperiod_inheritance_timeperiod ON icinga_timeperiod_inheritance (timeperiod_id); +CREATE INDEX timeperiod_inheritance_timeperiod_parent ON icinga_timeperiod_inheritance (parent_timeperiod_id); + + +CREATE TABLE icinga_timeperiod_range ( + timeperiod_id serial, + range_key character varying(255) NOT NULL, + range_value character varying(255) NOT NULL, + range_type enum_timeperiod_range_type NOT NULL DEFAULT 'include', + merge_behaviour enum_merge_behaviour NOT NULL DEFAULT 'set', + PRIMARY KEY (timeperiod_id, range_type, range_key), + CONSTRAINT icinga_timeperiod_range_timeperiod + FOREIGN KEY (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX timeperiod_range_timeperiod ON icinga_timeperiod_range (timeperiod_id); +COMMENT ON COLUMN icinga_timeperiod_range.range_key IS 'monday, ...'; +COMMENT ON COLUMN icinga_timeperiod_range.range_value IS '00:00-24:00, ...'; +COMMENT ON COLUMN icinga_timeperiod_range.range_type IS 'include -> ranges {}, exclude ranges_ignore {} - not yet'; +COMMENT ON COLUMN icinga_timeperiod_range.merge_behaviour IS 'set -> = {}, add -> += {}, substract -> -= {}'; + + +CREATE TABLE director_job ( + id serial, + job_name character varying(64) NOT NULL, + job_class character varying(72) NOT NULL, + disabled enum_boolean NOT NULL DEFAULT 'n', + run_interval integer NOT NULL, -- seconds + timeperiod_id integer DEFAULT NULL, + last_attempt_succeeded enum_boolean DEFAULT NULL, + ts_last_attempt timestamp with time zone DEFAULT NULL, + ts_last_error timestamp with time zone DEFAULT NULL, + last_error_message text NULL DEFAULT NULL, + CONSTRAINT director_job_period + FOREIGN KEY (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX director_job_unique_job_name ON director_job (job_name); + + +CREATE TABLE director_job_setting ( + job_id integer NOT NULL, + setting_name character varying(64) NOT NULL, + setting_value text DEFAULT NULL, + PRIMARY KEY (job_id, setting_name), + CONSTRAINT director_job_setting_job + FOREIGN KEY (job_id) + REFERENCES director_job (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +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', + methods_execute character varying(64) DEFAULT NULL, + command text DEFAULT NULL, + is_string enum_boolean NULL, +-- env text DEFAULT NULL, + timeout smallint DEFAULT NULL, + zone_id integer DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_command_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +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'; + + +CREATE TABLE icinga_command_inheritance ( + command_id integer NOT NULL, + parent_command_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (command_id, parent_command_id), + CONSTRAINT icinga_command_inheritance_command + FOREIGN KEY (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_command_inheritance_parent_command + FOREIGN KEY (parent_command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX command_inheritance_unique_order ON icinga_command_inheritance (command_id, weight); +CREATE INDEX command_inheritance_command ON icinga_command_inheritance (command_id); +CREATE INDEX command_inheritance_command_parent ON icinga_command_inheritance (parent_command_id); + + +CREATE TABLE icinga_command_argument ( + id serial, + command_id integer NOT NULL, + argument_name character varying(64) NOT NULL, + argument_value text DEFAULT NULL, + argument_format enum_property_format DEFAULT NULL, + key_string character varying(64) DEFAULT NULL, + description text DEFAULT NULL, + skip_key enum_boolean DEFAULT NULL, + set_if character varying(255) DEFAULT NULL, -- (string expression, must resolve to a numeric value) + set_if_format enum_property_format DEFAULT NULL, + sort_order smallint DEFAULT NULL, -- -> order + repeat_key enum_boolean DEFAULT NULL, + required enum_boolean DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_command_argument_command + FOREIGN KEY (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX command_argument_unique_idx ON icinga_command_argument (command_id, argument_name); +CREATE INDEX command_argument_sort_idx ON icinga_command_argument (command_id, sort_order); +CREATE INDEX command_argument_command ON icinga_command_argument (command_id); +COMMENT ON COLUMN icinga_command_argument.argument_name IS '-x, --host'; +COMMENT ON COLUMN icinga_command_argument.key_string IS 'Overrides name'; +COMMENT ON COLUMN icinga_command_argument.repeat_key IS 'Useful with array values'; + + +CREATE TABLE icinga_command_field ( + command_id integer NOT NULL, + datafield_id integer NOT NULL, + is_required enum_boolean NOT NULL, + var_filter TEXT DEFAULT NULL, + PRIMARY KEY (command_id, datafield_id), + CONSTRAINT icinga_command_field_command + FOREIGN KEY (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_command_field_datafield + FOREIGN KEY (datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + + +CREATE TABLE icinga_command_var ( + command_id integer NOT NULL, + checksum bytea DEFAULT NULL UNIQUE CHECK(LENGTH(checksum) = 20), + varname character varying(255) NOT NULL, + varvalue text DEFAULT NULL, + format enum_property_format NOT NULL DEFAULT 'string', + PRIMARY KEY (command_id, varname), + CONSTRAINT icinga_command_var_command + FOREIGN KEY (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX command_var_command ON icinga_command_var (command_id); +CREATE INDEX command_var_search_idx ON icinga_command_var (varname); +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', + password CHARACTER VARYING(255) DEFAULT NULL, + client_dn CHARACTER VARYING(64) DEFAULT NULL, + permissions TEXT DEFAULT NULL, + PRIMARY KEY (id) +); + +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, + disabled enum_boolean NOT NULL DEFAULT 'n', + host character varying(255) DEFAULT NULL, + port d_smallint DEFAULT NULL, + log_duration character varying(32) DEFAULT NULL, + apiuser_id INTEGER DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_endpoint_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_apiuser + FOREIGN KEY (apiuser_id) + REFERENCES icinga_apiuser (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +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'; +COMMENT ON COLUMN icinga_endpoint.port IS '5665 if not set'; +COMMENT ON COLUMN icinga_endpoint.log_duration IS '1d if not set'; + + +CREATE TABLE icinga_endpoint_inheritance ( + endpoint_id integer NOT NULL, + parent_endpoint_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (endpoint_id, parent_endpoint_id), + CONSTRAINT icinga_endpoint_inheritance_endpoint + FOREIGN KEY (endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_endpoint_inheritance_parent_endpoint + FOREIGN KEY (parent_endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX endpoint_inheritance_unique_order ON icinga_endpoint_inheritance (endpoint_id, weight); +CREATE INDEX endpoint_inheritance_endpoint ON icinga_endpoint_inheritance (endpoint_id); +CREATE INDEX endpoint_inheritance_endpoint_parent ON icinga_endpoint_inheritance (parent_endpoint_id); + + +CREATE TABLE icinga_host_template_choice ( + id serial, + object_name character varying(64) NOT NULL, + description text DEFAULT NULL, + min_required smallint NOT NULL DEFAULT 0, + max_allowed smallint NOT NULL DEFAULT 1, + required_template_id integer DEFAULT NULL, + allowed_roles character varying(255) DEFAULT NULL, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX host_template_choice_object_name ON icinga_host_template_choice (object_name); +CREATE INDEX host_template_choice_required_template ON icinga_host_template_choice (required_template_id); + +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', + display_name CHARACTER VARYING(255) DEFAULT NULL, + address character varying(255) DEFAULT NULL, + address6 character varying(45) DEFAULT NULL, + check_command_id integer DEFAULT NULL, + max_check_attempts integer DEFAULT NULL, + check_period_id integer DEFAULT NULL, + check_interval character varying(8) DEFAULT NULL, + retry_interval character varying(8) DEFAULT NULL, + check_timeout smallint DEFAULT NULL, + enable_notifications enum_boolean DEFAULT NULL, + enable_active_checks enum_boolean DEFAULT NULL, + enable_passive_checks enum_boolean DEFAULT NULL, + enable_event_handler enum_boolean DEFAULT NULL, + enable_flapping enum_boolean DEFAULT NULL, + enable_perfdata enum_boolean DEFAULT NULL, + event_command_id integer DEFAULT NULL, + flapping_threshold_high smallint default null, + flapping_threshold_low smallint default null, + volatile enum_boolean DEFAULT NULL, + zone_id integer DEFAULT NULL, + command_endpoint_id integer DEFAULT NULL, + notes text DEFAULT NULL, + notes_url character varying(255) DEFAULT NULL, + action_url character varying(255) DEFAULT NULL, + icon_image character varying(255) DEFAULT NULL, + icon_image_alt character varying(255) DEFAULT NULL, + has_agent enum_boolean DEFAULT NULL, + master_should_connect enum_boolean DEFAULT NULL, + accept_config enum_boolean DEFAULT NULL, + custom_endpoint_name character varying(255) DEFAULT NULL, + api_key character varying(40) DEFAULT NULL, + template_choice_id int DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_host_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_host_check_period + FOREIGN KEY (check_period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_host_check_command + FOREIGN KEY (check_command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_host_event_command + FOREIGN KEY (event_command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_host_command_endpoint + FOREIGN KEY (command_endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_host_template_choice + FOREIGN KEY (template_choice_id) + REFERENCES icinga_host_template_choice (id) + ON DELETE SET NULL + ON UPDATE CASCADE +); + + +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); +CREATE INDEX host_timeperiod ON icinga_host (check_period_id); +CREATE INDEX host_check_command ON icinga_host (check_command_id); +CREATE INDEX host_event_command ON icinga_host (event_command_id); +CREATE INDEX host_command_endpoint ON icinga_host (command_endpoint_id); +CREATE INDEX host_template_choice ON icinga_host (template_choice_id); + + +CREATE TABLE icinga_host_inheritance ( + host_id integer NOT NULL, + parent_host_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (host_id, parent_host_id), + CONSTRAINT icinga_host_inheritance_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_inheritance_parent_host + FOREIGN KEY (parent_host_id) + REFERENCES icinga_host (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX host_inheritance_unique_order ON icinga_host_inheritance (host_id, weight); +CREATE INDEX host_inheritance_host ON icinga_host_inheritance (host_id); +CREATE INDEX host_inheritance_host_parent ON icinga_host_inheritance (parent_host_id); + + +CREATE TABLE icinga_host_field ( + host_id integer NOT NULL, + datafield_id integer NOT NULL, + is_required enum_boolean NOT NULL, + var_filter TEXT DEFAULT NULL, + PRIMARY KEY (host_id, datafield_id), + CONSTRAINT icinga_host_field_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_field_datafield + FOREIGN KEY (datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX host_field_key ON icinga_host_field (host_id, datafield_id); +CREATE INDEX host_field_host ON icinga_host_field (host_id); +CREATE INDEX host_field_datafield ON icinga_host_field (datafield_id); +COMMENT ON COLUMN icinga_host_field.host_id IS 'Makes only sense for templates'; + + +CREATE TABLE icinga_host_var ( + host_id integer NOT NULL, + checksum bytea DEFAULT NULL UNIQUE CHECK(LENGTH(checksum) = 20), + varname character varying(255) NOT NULL, + varvalue text DEFAULT NULL, + format enum_property_format, -- immer string vorerst + PRIMARY KEY (host_id, varname), + CONSTRAINT icinga_host_var_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX host_var_search_idx ON icinga_host_var (varname); +CREATE INDEX host_var_host ON icinga_host_var (host_id); +CREATE INDEX host_var_checksum ON icinga_host_var (checksum); + + +ALTER TABLE icinga_host_template_choice + ADD CONSTRAINT host_template_choice_required_template + FOREIGN KEY (required_template_id) + REFERENCES icinga_host (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + + +CREATE TABLE icinga_service_set ( + id serial, + uuid bytea UNIQUE CHECK(LENGTH(uuid) = 16), + host_id integer DEFAULT NULL, + object_name character varying(128) NOT NULL, + object_type enum_object_type_all NOT NULL, + description text DEFAULT NULL, + assign_filter text DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_service_set_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX service_set_name ON icinga_service_set (object_name, host_id); +CREATE INDEX service_set_host ON icinga_service_set (host_id); + + +CREATE TABLE icinga_service_template_choice ( + id serial, + object_name character varying(64) NOT NULL, + description text DEFAULT NULL, + min_required smallint NOT NULL DEFAULT 0, + max_allowed smallint NOT NULL DEFAULT 1, + required_template_id integer DEFAULT NULL, + allowed_roles character varying(255) DEFAULT NULL, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX service_template_choice_object_name ON icinga_service_template_choice (object_name); +CREATE INDEX service_template_choice_required_template ON icinga_service_template_choice (required_template_id); + + +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', + display_name character varying(255) DEFAULT NULL, + host_id INTEGER DEFAULT NULL, + service_set_id integer DEFAULT NULL, + check_command_id integer DEFAULT NULL, + max_check_attempts integer DEFAULT NULL, + check_period_id integer DEFAULT NULL, + check_interval character varying(8) DEFAULT NULL, + retry_interval character varying(8) DEFAULT NULL, + check_timeout smallint DEFAULT NULL, + enable_notifications enum_boolean DEFAULT NULL, + enable_active_checks enum_boolean DEFAULT NULL, + enable_passive_checks enum_boolean DEFAULT NULL, + enable_event_handler enum_boolean DEFAULT NULL, + enable_flapping enum_boolean DEFAULT NULL, + enable_perfdata enum_boolean DEFAULT NULL, + event_command_id integer DEFAULT NULL, + flapping_threshold_high smallint DEFAULT NULL, + flapping_threshold_low smallint DEFAULT NULL, + volatile enum_boolean DEFAULT NULL, + zone_id integer DEFAULT NULL, + command_endpoint_id integer DEFAULT NULL, + notes text DEFAULT NULL, + notes_url character varying(255) DEFAULT NULL, + action_url character varying(255) DEFAULT NULL, + icon_image character varying(255) DEFAULT NULL, + icon_image_alt character varying(255) DEFAULT NULL, + use_agent enum_boolean DEFAULT NULL, + apply_for character varying(255) DEFAULT NULL, + use_var_overrides enum_boolean DEFAULT NULL, + assign_filter text DEFAULT NULL, + template_choice_id int DEFAULT NULL, + PRIMARY KEY (id), +-- UNIQUE INDEX object_name (object_name, zone_id), + CONSTRAINT icinga_service_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_service_check_period + FOREIGN KEY (check_period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_service_check_command + FOREIGN KEY (check_command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_service_event_command + FOREIGN KEY (event_command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_service_command_endpoint + FOREIGN KEY (command_endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_service_service_set + FOREIGN KEY (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_template_choice + FOREIGN KEY (template_choice_id) + REFERENCES icinga_service_template_choice (id) + ON DELETE SET NULL + ON UPDATE CASCADE +); + +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); +CREATE INDEX service_event_command ON icinga_service (event_command_id); +CREATE INDEX service_command_endpoint ON icinga_service (command_endpoint_id); +CREATE INDEX service_template_choice ON icinga_service (template_choice_id); + + +CREATE TABLE icinga_service_inheritance ( + service_id integer NOT NULL, + parent_service_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (service_id, parent_service_id), + CONSTRAINT icinga_service_inheritance_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_inheritance_parent_service + FOREIGN KEY (parent_service_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX service_inheritance_unique_order ON icinga_service_inheritance (service_id, weight); +CREATE INDEX service_inheritance_service ON icinga_service_inheritance (service_id); +CREATE INDEX service_inheritance_service_parent ON icinga_service_inheritance (parent_service_id); + + +CREATE TABLE icinga_service_var ( + service_id integer NOT NULL, + checksum bytea DEFAULT NULL UNIQUE CHECK(LENGTH(checksum) = 20), + varname character varying(255) NOT NULL, + varvalue text DEFAULT NULL, + format enum_property_format, + PRIMARY KEY (service_id, varname), + CONSTRAINT icinga_service_var_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX service_var_search_idx ON icinga_service_var (varname); +CREATE INDEX service_var_service ON icinga_service_var (service_id); +CREATE INDEX service_var_checksum ON icinga_service_var (checksum); + + +CREATE TABLE icinga_service_field ( + service_id integer NOT NULL, + datafield_id integer NOT NULL, + is_required enum_boolean NOT NULL, + var_filter TEXT DEFAULT NULL, + PRIMARY KEY (service_id, datafield_id), + CONSTRAINT icinga_service_field_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_field_datafield + FOREIGN KEY (datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX service_field_key ON icinga_service_field (service_id, datafield_id); +CREATE INDEX service_field_service ON icinga_service_field (service_id); +CREATE INDEX service_field_datafield ON icinga_service_field (datafield_id); +COMMENT ON COLUMN icinga_service_field.service_id IS 'Makes only sense for templates'; + + +ALTER TABLE icinga_service_template_choice + ADD CONSTRAINT service_template_choice_required_template + FOREIGN KEY (required_template_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + + +CREATE TABLE icinga_host_service ( + host_id integer NOT NULL, + service_id integer NOT NULL, + PRIMARY KEY (host_id, service_id), + CONSTRAINT icinga_host_service_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_service_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX host_service_host ON icinga_host_service (host_id); +CREATE INDEX host_service_service ON icinga_host_service (service_id); + + +CREATE TABLE icinga_host_service_blacklist( + host_id integer NOT NULL, + service_id integer NOT NULL, + PRIMARY KEY (host_id, service_id), + CONSTRAINT icinga_host_service__bl_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_host_service_bl_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX host_service_bl_host ON icinga_host_service_blacklist (host_id); +CREATE INDEX host_service_bl_service ON icinga_host_service_blacklist (service_id); + + +CREATE TABLE icinga_service_set_inheritance ( + service_set_id integer NOT NULL, + parent_service_set_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (service_set_id, parent_service_set_id), + CONSTRAINT icinga_service_set_inheritance_set + FOREIGN KEY (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_service_set_inheritance_parent + FOREIGN KEY (parent_service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX service_set_inheritance_unique_order ON icinga_service_set_inheritance (service_set_id, weight); +CREATE INDEX service_set_inheritance_set ON icinga_service_set_inheritance (service_set_id); +CREATE INDEX service_set_inheritance_parent ON icinga_service_set_inheritance (parent_service_set_id); + + +CREATE TABLE icinga_service_set_var ( + service_set_id integer NOT NULL, + checksum bytea DEFAULT NULL UNIQUE CHECK(LENGTH(checksum) = 20), + varname character varying(255) NOT NULL, + varvalue text DEFAULT NULL, + format enum_property_format NOT NULL DEFAULT 'string', + PRIMARY KEY (service_set_id, varname), + CONSTRAINT icinga_service_set_var_service_set + FOREIGN KEY (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX service_set_var_service_set ON icinga_service_set_var (service_set_id); +CREATE INDEX service_set_var_search_idx ON icinga_service_set_var (varname); +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', + display_name character varying(255) DEFAULT NULL, + assign_filter text DEFAULT NULL, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX hostgroup_object_name ON icinga_hostgroup (object_name); +CREATE INDEX hostgroup_search_idx ON icinga_hostgroup (display_name); + + +-- -- TODO: probably useless +CREATE TABLE icinga_hostgroup_inheritance ( + hostgroup_id integer NOT NULL, + parent_hostgroup_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (hostgroup_id, parent_hostgroup_id), + CONSTRAINT icinga_hostgroup_inheritance_hostgroup + FOREIGN KEY (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_hostgroup_inheritance_parent_hostgroup + FOREIGN KEY (parent_hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX hostgroup_inheritance_unique_order ON icinga_hostgroup_inheritance (hostgroup_id, weight); +CREATE INDEX hostgroup_inheritance_hostgroup ON icinga_hostgroup_inheritance (hostgroup_id); +CREATE INDEX hostgroup_inheritance_hostgroup_parent ON icinga_hostgroup_inheritance (parent_hostgroup_id); + + +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', + display_name character varying(255) DEFAULT NULL, + assign_filter text DEFAULT NULL, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX servicegroup_object_name ON icinga_servicegroup (object_name); +CREATE INDEX servicegroup_search_idx ON icinga_servicegroup (display_name); + +CREATE TABLE icinga_servicegroup_service_resolved ( + servicegroup_id integer NOT NULL, + service_id integer NOT NULL, + PRIMARY KEY (servicegroup_id, service_id), + CONSTRAINT icinga_servicegroup_service_resolved_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_servicegroup_service_resolved_servicegroup + FOREIGN KEY (servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX servicegroup_service_resolved_service ON icinga_servicegroup_service_resolved (service_id); +CREATE INDEX servicegroup_service_resolved_servicegroup ON icinga_servicegroup_service_resolved (servicegroup_id); + + +CREATE TABLE icinga_servicegroup_inheritance ( + servicegroup_id integer NOT NULL, + parent_servicegroup_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (servicegroup_id, parent_servicegroup_id), + CONSTRAINT icinga_servicegroup_inheritance_servicegroup + FOREIGN KEY (servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_servicegroup_inheritance_parent_servicegroup + FOREIGN KEY (parent_servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX servicegroup_inheritance_unique_order ON icinga_servicegroup_inheritance (servicegroup_id, weight); +CREATE INDEX servicegroup_inheritance_servicegroup ON icinga_servicegroup_inheritance (servicegroup_id); +CREATE INDEX servicegroup_inheritance_servicegroup_parent ON icinga_servicegroup_inheritance (parent_servicegroup_id); + + +CREATE TABLE icinga_servicegroup_service ( + servicegroup_id integer NOT NULL, + service_id integer NOT NULL, + PRIMARY KEY (servicegroup_id, service_id), + CONSTRAINT icinga_servicegroup_service_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_servicegroup_service_servicegroup + FOREIGN KEY (servicegroup_id) + REFERENCES icinga_servicegroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX servicegroup_service_service ON icinga_servicegroup_service (service_id); +CREATE INDEX servicegroup_service_servicegroup ON icinga_servicegroup_service (servicegroup_id); + + +CREATE TABLE icinga_hostgroup_host ( + hostgroup_id integer NOT NULL, + host_id integer NOT NULL, + PRIMARY KEY (hostgroup_id, host_id), + CONSTRAINT icinga_hostgroup_host_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_hostgroup_host_hostgroup + FOREIGN KEY (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX hostgroup_host_host ON icinga_hostgroup_host (host_id); +CREATE INDEX hostgroup_host_hostgroup ON icinga_hostgroup_host (hostgroup_id); + + +CREATE TABLE icinga_hostgroup_host_resolved ( + hostgroup_id integer NOT NULL, + host_id integer NOT NULL, + PRIMARY KEY (hostgroup_id, host_id), + CONSTRAINT icinga_hostgroup_host_resolved_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_hostgroup_host_resolved_hostgroup + FOREIGN KEY (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX hostgroup_host_resolved_host ON icinga_hostgroup_host_resolved (host_id); +CREATE INDEX hostgroup_host_resolved_hostgroup ON icinga_hostgroup_host_resolved (hostgroup_id); + + +CREATE TABLE icinga_hostgroup_parent ( + hostgroup_id integer NOT NULL, + parent_hostgroup_id integer NOT NULL, + PRIMARY KEY (hostgroup_id, parent_hostgroup_id), + CONSTRAINT icinga_hostgroup_parent_hostgroup + FOREIGN KEY (hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_hostgroup_parent_parent + FOREIGN KEY (parent_hostgroup_id) + REFERENCES icinga_hostgroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE INDEX hostgroup_parent_hostgroup ON icinga_hostgroup_parent (hostgroup_id); +CREATE INDEX hostgroup_parent_parent ON icinga_hostgroup_parent (parent_hostgroup_id); + + +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', + display_name character varying(255) DEFAULT NULL, + email character varying(255) DEFAULT NULL, + pager character varying(255) DEFAULT NULL, + enable_notifications enum_boolean DEFAULT NULL, + period_id integer DEFAULT NULL, + zone_id integer DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_user_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_user_period + FOREIGN KEY (period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX user_object_name ON icinga_user (object_name, zone_id); +CREATE INDEX user_zone ON icinga_user (zone_id); + + +CREATE TABLE icinga_user_inheritance ( + user_id integer NOT NULL, + parent_user_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (user_id, parent_user_id), + CONSTRAINT icinga_user_inheritance_user + FOREIGN KEY (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_user_inheritance_parent_user + FOREIGN KEY (parent_user_id) + REFERENCES icinga_user (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX user_inheritance_unique_order ON icinga_user_inheritance (user_id, weight); +CREATE INDEX user_inheritance_user ON icinga_user_inheritance (user_id); +CREATE INDEX user_inheritance_user_parent ON icinga_user_inheritance (parent_user_id); + + +CREATE TABLE icinga_user_states_set ( + user_id integer NOT NULL, + property enum_state_name NOT NULL, + merge_behaviour enum_set_merge_behaviour NOT NULL DEFAULT 'override', + PRIMARY KEY (user_id, property, merge_behaviour), + CONSTRAINT icinga_user_filter_state_user + FOREIGN KEY (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX user_states_set_user ON icinga_user_states_set (user_id); +COMMENT ON COLUMN icinga_user_states_set.merge_behaviour IS 'override: = [], extend: += [], blacklist: -= []'; + + +CREATE TABLE icinga_user_types_set ( + user_id integer NOT NULL, + property enum_type_name NOT NULL, + merge_behaviour enum_set_merge_behaviour NOT NULL DEFAULT 'override', + PRIMARY KEY (user_id, property, merge_behaviour), + CONSTRAINT icinga_user_filter_type_user + FOREIGN KEY (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX user_types_set_user ON icinga_user_types_set (user_id); +COMMENT ON COLUMN icinga_user_types_set.merge_behaviour IS 'override: = [], extend: += [], blacklist: -= []'; + + +CREATE TABLE icinga_user_var ( + user_id integer NOT NULL, + checksum bytea DEFAULT NULL UNIQUE CHECK(LENGTH(checksum) = 20), + varname character varying(255) NOT NULL, + varvalue text DEFAULT NULL, + format enum_property_format NOT NULL DEFAULT 'string', + PRIMARY KEY (user_id, varname), + CONSTRAINT icinga_user_var_user + FOREIGN KEY (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX user_var_search_idx ON icinga_user_var (varname); +CREATE INDEX user_var_user ON icinga_user_var (user_id); +CREATE INDEX user_var_checksum ON icinga_user_var (checksum); + + +CREATE TABLE icinga_user_field ( + user_id integer NOT NULL, + datafield_id integer NOT NULL, + is_required enum_boolean NOT NULL, + var_filter TEXT DEFAULT NULL, + PRIMARY KEY (user_id, datafield_id), + CONSTRAINT icinga_user_field_user + FOREIGN KEY (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_user_field_datafield + FOREIGN KEY (datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX user_field_key ON icinga_user_field (user_id, datafield_id); +CREATE INDEX user_field_user ON icinga_user_field (user_id); +CREATE INDEX user_field_datafield ON icinga_user_field (datafield_id); +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', + display_name character varying(255) DEFAULT NULL, + zone_id integer DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_usergroup_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +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); + + +CREATE TABLE icinga_usergroup_inheritance ( + usergroup_id integer NOT NULL, + parent_usergroup_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (usergroup_id, parent_usergroup_id), + CONSTRAINT icinga_usergroup_inheritance_usergroup + FOREIGN KEY (usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_usergroup_inheritance_parent_usergroup + FOREIGN KEY (parent_usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX usergroup_inheritance_unique_order ON icinga_usergroup_inheritance (usergroup_id, weight); +CREATE INDEX usergroup_inheritance_usergroup ON icinga_usergroup_inheritance (usergroup_id); +CREATE INDEX usergroup_inheritance_usergroup_parent ON icinga_usergroup_inheritance (parent_usergroup_id); + + +CREATE TABLE icinga_usergroup_user ( + usergroup_id integer NOT NULL, + user_id integer NOT NULL, + PRIMARY KEY (usergroup_id, user_id), + CONSTRAINT icinga_usergroup_user_user + FOREIGN KEY (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_usergroup_user_usergroup + FOREIGN KEY (usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX usergroup_user_user ON icinga_usergroup_user (user_id); +CREATE INDEX usergroup_user_usergroup ON icinga_usergroup_user (usergroup_id); + + +CREATE TABLE icinga_usergroup_parent ( + usergroup_id integer NOT NULL, + parent_usergroup_id integer NOT NULL, + PRIMARY KEY (usergroup_id, parent_usergroup_id), + CONSTRAINT icinga_usergroup_parent_usergroup + FOREIGN KEY (usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_usergroup_parent_parent + FOREIGN KEY (parent_usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE INDEX usergroup_parent_usergroup ON icinga_usergroup_parent (usergroup_id); +CREATE INDEX usergroup_parent_parent ON icinga_usergroup_parent (parent_usergroup_id); + + +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', + apply_to enum_host_service NULL DEFAULT NULL, + host_id integer DEFAULT NULL, + service_id integer DEFAULT NULL, + times_begin integer DEFAULT NULL, + times_end integer DEFAULT NULL, + notification_interval integer DEFAULT NULL, + command_id integer DEFAULT NULL, + period_id integer DEFAULT NULL, + zone_id integer DEFAULT NULL, + assign_filter text DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_notification_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_command + FOREIGN KEY (command_id) + REFERENCES icinga_command (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_period + FOREIGN KEY (period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + + +CREATE TABLE icinga_notification_user ( + notification_id integer NOT NULL, + user_id integer NOT NULL, + PRIMARY KEY (notification_id, user_id), + CONSTRAINT icinga_notification_user_user + FOREIGN KEY (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_user_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE TABLE icinga_notification_usergroup ( + notification_id integer NOT NULL, + usergroup_id integer NOT NULL, + PRIMARY KEY (notification_id, usergroup_id), + CONSTRAINT icinga_notification_usergroup_usergroup + FOREIGN KEY (usergroup_id) + REFERENCES icinga_usergroup (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_usergroup_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + + +CREATE TABLE import_source ( + id serial, + source_name character varying(64) NOT NULL, + key_column character varying(64) NOT NULL, + provider_class character varying(128) NOT NULL, + import_state enum_sync_state NOT NULL DEFAULT 'unknown', + last_error_message text NULL DEFAULT NULL, + last_attempt timestamp with time zone NULL DEFAULT NULL, + description text DEFAULT NULL, + PRIMARY KEY (id) +); + +CREATE INDEX import_source_search_idx ON import_source (key_column); +CREATE UNIQUE INDEX import_source_name ON import_source (source_name); + + +CREATE TABLE import_source_setting ( + source_id integer NOT NULL, + setting_name character varying(64) NOT NULL, + setting_value text NOT NULL, + PRIMARY KEY (source_id, setting_name), + CONSTRAINT import_source_settings_source + FOREIGN KEY (source_id) + REFERENCES import_source (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX import_source_setting_source ON import_source_setting (source_id); + + +CREATE TABLE import_row_modifier ( + id bigserial, + source_id integer NOT NULL, + property_name character varying(255) NOT NULL, + target_property character varying(255) DEFAULT NULL, + provider_class character varying(128) NOT NULL, + priority integer NOT NULL, + description text DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT row_modifier_import_source + FOREIGN KEY (source_id) + REFERENCES import_source (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX import_row_modifier_search_idx ON import_row_modifier (property_name); +CREATE UNIQUE INDEX import_row_modifier_prio + ON import_row_modifier (source_id, priority); + + +CREATE TABLE import_row_modifier_setting ( + row_modifier_id serial, + setting_name character varying(64) NOT NULL, + setting_value TEXT DEFAULT NULL, + PRIMARY KEY (row_modifier_id, setting_name), + CONSTRAINT row_modifier_settings + FOREIGN KEY (row_modifier_id) + REFERENCES import_row_modifier (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + + +CREATE TABLE imported_rowset ( + checksum bytea CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (checksum) +); + + +CREATE TABLE import_run ( + id serial, + source_id integer NOT NULL, + rowset_checksum bytea CHECK(LENGTH(rowset_checksum) = 20), + start_time timestamp with time zone NOT NULL, + end_time timestamp with time zone DEFAULT NULL, + succeeded enum_boolean DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT import_run_source + FOREIGN KEY (source_id) + REFERENCES import_source (id) + ON DELETE CASCADE + ON UPDATE RESTRICT, + CONSTRAINT import_run_rowset + FOREIGN KEY (rowset_checksum) + REFERENCES imported_rowset (checksum) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE INDEX import_run_import_source ON import_run (source_id); +CREATE INDEX import_run_rowset ON import_run (rowset_checksum); + + +CREATE TABLE imported_row ( + checksum bytea CHECK(LENGTH(checksum) = 20), + object_name character varying(255) NOT NULL, + PRIMARY KEY (checksum) +); + +COMMENT ON COLUMN imported_row.checksum IS 'sha1(object_name;property_checksum;...)'; + + +CREATE TABLE imported_rowset_row ( + rowset_checksum bytea CHECK(LENGTH(rowset_checksum) = 20), + row_checksum bytea CHECK(LENGTH(row_checksum) = 20), + PRIMARY KEY (rowset_checksum, row_checksum), + CONSTRAINT imported_rowset_row_rowset + FOREIGN KEY (rowset_checksum) + REFERENCES imported_rowset (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT imported_rowset_row_row + FOREIGN KEY (row_checksum) + REFERENCES imported_row (checksum) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE INDEX imported_rowset_row_rowset_checksum ON imported_rowset_row (rowset_checksum); +CREATE INDEX imported_rowset_row_row_checksum ON imported_rowset_row (row_checksum); + + +CREATE TABLE imported_property ( + checksum bytea CHECK(LENGTH(checksum) = 20), + property_name character varying(64) NOT NULL, + property_value text NOT NULL, + format enum_property_format, + PRIMARY KEY (checksum) +); + +CREATE INDEX imported_property_search_idx ON imported_property (property_name); + + +CREATE TABLE imported_row_property ( + row_checksum bytea CHECK(LENGTH(row_checksum) = 20), + property_checksum bytea CHECK(LENGTH(property_checksum) = 20), + PRIMARY KEY (row_checksum, property_checksum), + CONSTRAINT imported_row_property_row + FOREIGN KEY (row_checksum) + REFERENCES imported_row (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT imported_row_property_property + FOREIGN KEY (property_checksum) + REFERENCES imported_property (checksum) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE INDEX imported_row_property_row_checksum ON imported_row_property (row_checksum); +CREATE INDEX imported_row_property_property_checksum ON imported_row_property (property_checksum); + + +CREATE TABLE sync_rule ( + id serial, + rule_name character varying(255) NOT NULL, + object_type enum_sync_rule_object_type NOT NULL, + update_policy enum_sync_rule_update_policy NOT NULL, + purge_existing enum_boolean NOT NULL DEFAULT 'n', + purge_action enum_sync_rule_purge_action NULL DEFAULT NULL, + filter_expression text DEFAULT NULL, + sync_state enum_sync_state NOT NULL DEFAULT 'unknown', + last_error_message text NULL DEFAULT NULL, + last_attempt timestamp with time zone NULL DEFAULT NULL, + description text DEFAULT NULL, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX sync_rule_name ON sync_rule (rule_name); + +CREATE TABLE sync_property ( + id serial, + rule_id integer NOT NULL, + source_id integer NOT NULL, + source_expression character varying(255) NOT NULL, + destination_field character varying(64), + priority smallint NOT NULL, + filter_expression text DEFAULT NULL, + merge_policy enum_sync_property_merge_policy DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT sync_property_rule + FOREIGN KEY (rule_id) + REFERENCES sync_rule (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT sync_property_source + FOREIGN KEY (source_id) + REFERENCES import_source (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE INDEX sync_property_rule ON sync_property (rule_id); +CREATE INDEX sync_property_source ON sync_property (source_id); + + +CREATE TABLE sync_run ( + id bigserial, + rule_id integer DEFAULT NULL, + rule_name character varying(255) NOT NULL, + start_time TIMESTAMP WITH TIME ZONE NOT NULL, + duration_ms integer DEFAULT NULL, + objects_deleted integer DEFAULT 0, + objects_created integer DEFAULT 0, + objects_modified integer DEFAULT 0, + last_former_activity bytea DEFAULT NULL CHECK(LENGTH(last_former_activity) = 20), + last_related_activity bytea DEFAULT NULL CHECK(LENGTH(last_related_activity) = 20), + PRIMARY KEY (id), + CONSTRAINT sync_run_rule + FOREIGN KEY (rule_id) + REFERENCES sync_rule (id) + ON DELETE SET NULL + ON UPDATE CASCADE +); + + +CREATE TABLE icinga_notification_states_set ( + notification_id integer NOT NULL, + property enum_state_name NOT NULL, + merge_behaviour enum_set_merge_behaviour NOT NULL DEFAULT 'override', + PRIMARY KEY (notification_id, property, merge_behaviour), + CONSTRAINT icinga_notification_states_set_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +COMMENT ON COLUMN icinga_notification_states_set.merge_behaviour IS 'override: = [], extend: += [], blacklist: -= []'; + + +CREATE TABLE icinga_notification_types_set ( + notification_id integer NOT NULL, + property enum_type_name NOT NULL, + merge_behaviour enum_set_merge_behaviour NOT NULL DEFAULT 'override', + PRIMARY KEY (notification_id, property, merge_behaviour), + CONSTRAINT icinga_notification_types_set_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +COMMENT ON COLUMN icinga_notification_types_set.merge_behaviour IS 'override: = [], extend: += [], blacklist: -= []'; + + +CREATE TABLE icinga_notification_var ( + notification_id integer NOT NULL, + checksum bytea DEFAULT NULL UNIQUE CHECK(LENGTH(checksum) = 20), + varname VARCHAR(255) NOT NULL, + varvalue TEXT DEFAULT NULL, + format enum_property_format, + PRIMARY KEY (notification_id, varname), + CONSTRAINT icinga_notification_var_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX notification_var_command ON icinga_notification_var (notification_id); +CREATE INDEX notification_var_search_idx ON icinga_notification_var (varname); +CREATE INDEX notification_var_checksum ON icinga_notification_var (checksum); + +CREATE TABLE icinga_notification_field ( + notification_id integer NOT NULL, + datafield_id integer NOT NULL, + is_required enum_boolean NOT NULL, + var_filter TEXT DEFAULT NULL, + PRIMARY KEY (notification_id, datafield_id), + CONSTRAINT icinga_notification_field_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_field_datafield + FOREIGN KEY (datafield_id) + REFERENCES director_datafield (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX notification_field_key ON icinga_notification_field (notification_id, datafield_id); +CREATE INDEX notification_field_notification ON icinga_notification_field (notification_id); +CREATE INDEX notification_field_datafield ON icinga_notification_field (datafield_id); +COMMENT ON COLUMN icinga_notification_field.notification_id IS 'Makes only sense for templates'; + + +CREATE TABLE icinga_notification_inheritance ( + notification_id integer NOT NULL, + parent_notification_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (notification_id, parent_notification_id), + CONSTRAINT icinga_notification_inheritance_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_notification_inheritance_parent_notification + FOREIGN KEY (parent_notification_id) + REFERENCES icinga_notification (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX notification_inheritance ON icinga_notification_inheritance (notification_id, weight); + + +CREATE TABLE icinga_var ( + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + rendered_checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + varname character varying(255) NOT NULL, + varvalue TEXT NOT NULL, + rendered TEXT NOT NULL, + PRIMARY KEY (checksum) +); + +CREATE INDEX var_search_idx ON icinga_var (varname); + + +CREATE TABLE icinga_flat_var ( + var_checksum bytea NOT NULL CHECK(LENGTH(var_checksum) = 20), + flatname_checksum bytea NOT NULL CHECK(LENGTH(flatname_checksum) = 20), + flatname character varying(512) NOT NULL, + flatvalue TEXT NOT NULL, + PRIMARY KEY (var_checksum, flatname_checksum), + CONSTRAINT flat_var_var + FOREIGN KEY (var_checksum) + REFERENCES icinga_var (checksum) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX flat_var_var_checksum ON icinga_flat_var (var_checksum); +CREATE INDEX flat_var_search_varname ON icinga_flat_var (flatname); +CREATE INDEX flat_var_search_varvalue ON icinga_flat_var (flatvalue); + + +CREATE TABLE icinga_command_resolved_var ( + command_id integer NOT NULL, + varname character varying(255) NOT NULL, + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (command_id, checksum), + CONSTRAINT command_resolved_var_command + FOREIGN KEY (command_id) + REFERENCES icinga_command (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT command_resolved_var_checksum + FOREIGN KEY (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX command_resolved_var_search_varname ON icinga_command_resolved_var (varname); +CREATE INDEX command_resolved_var_command_id ON icinga_command_resolved_var (command_id); +CREATE INDEX command_resolved_var_schecksum ON icinga_command_resolved_var (checksum); + + +CREATE TABLE icinga_host_resolved_var ( + host_id integer NOT NULL, + varname character varying(255) NOT NULL, + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (host_id, checksum), + CONSTRAINT host_resolved_var_host + FOREIGN KEY (host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT host_resolved_var_checksum + FOREIGN KEY (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX host_resolved_var_search_varname ON icinga_host_resolved_var (varname); +CREATE INDEX host_resolved_var_host_id ON icinga_host_resolved_var (host_id); +CREATE INDEX host_resolved_var_schecksum ON icinga_host_resolved_var (checksum); + + +CREATE TABLE icinga_notification_resolved_var ( + notification_id integer NOT NULL, + varname character varying(255) NOT NULL, + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (notification_id, checksum), + CONSTRAINT notification_resolved_var_notification + FOREIGN KEY (notification_id) + REFERENCES icinga_notification (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT notification_resolved_var_checksum + FOREIGN KEY (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX notification_resolved_var_search_varname ON icinga_notification_resolved_var (varname); +CREATE INDEX notification_resolved_var_notification_id ON icinga_notification_resolved_var (notification_id); +CREATE INDEX notification_resolved_var_schecksum ON icinga_notification_resolved_var (checksum); + + +CREATE TABLE icinga_service_set_resolved_var ( + service_set_id integer NOT NULL, + varname character varying(255) NOT NULL, + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (service_set_id, checksum), + CONSTRAINT service_set_resolved_var_service_set + FOREIGN KEY (service_set_id) + REFERENCES icinga_service_set (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT service_set_resolved_var_checksum + FOREIGN KEY (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX service_set_resolved_var_search_varname ON icinga_service_set_resolved_var (varname); +CREATE INDEX service_set_resolved_var_service_set_id ON icinga_service_set_resolved_var (service_set_id); +CREATE INDEX service_set_resolved_var_schecksum ON icinga_service_set_resolved_var (checksum); + + +CREATE TABLE icinga_service_resolved_var ( + service_id integer NOT NULL, + varname character varying(255) NOT NULL, + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (service_id, checksum), + CONSTRAINT service_resolved_var_service + FOREIGN KEY (service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT service_resolved_var_checksum + FOREIGN KEY (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX service_resolved_var_search_varname ON icinga_service_resolved_var (varname); +CREATE INDEX service_resolved_var_service_id ON icinga_service_resolved_var (service_id); +CREATE INDEX service_resolved_var_schecksum ON icinga_service_resolved_var (checksum); + + +CREATE TABLE icinga_user_resolved_var ( + user_id integer NOT NULL, + varname character varying(255) NOT NULL, + checksum bytea NOT NULL CHECK(LENGTH(checksum) = 20), + PRIMARY KEY (user_id, checksum), + CONSTRAINT user_resolved_var_user + FOREIGN KEY (user_id) + REFERENCES icinga_user (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT user_resolved_var_checksum + FOREIGN KEY (checksum) + REFERENCES icinga_var (checksum) + ON DELETE RESTRICT + ON UPDATE RESTRICT +); + +CREATE INDEX user_resolved_var_search_varname ON icinga_user_resolved_var (varname); +CREATE INDEX user_resolved_var_user_id ON icinga_user_resolved_var (user_id); +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', + apply_to enum_host_service NULL DEFAULT NULL, + parent_host_id integer DEFAULT NULL, + parent_host_var character varying(128) DEFAULT NULL, + parent_service_id integer DEFAULT NULL, + child_host_id integer DEFAULT NULL, + child_service_id integer DEFAULT NULL, + disable_checks enum_boolean DEFAULT NULL, + disable_notifications enum_boolean DEFAULT NULL, + ignore_soft_states enum_boolean DEFAULT NULL, + period_id integer DEFAULT NULL, + zone_id integer DEFAULT NULL, + assign_filter text DEFAULT NULL, + parent_service_by_name character varying(255), + PRIMARY KEY (id), + CONSTRAINT icinga_dependency_parent_host + FOREIGN KEY (parent_host_id) + REFERENCES icinga_host (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_parent_service + FOREIGN KEY (parent_service_id) + REFERENCES icinga_service (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_child_host + FOREIGN KEY (child_host_id) + REFERENCES icinga_host (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_child_service + FOREIGN KEY (child_service_id) + REFERENCES icinga_service (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_period + FOREIGN KEY (period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +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); +CREATE INDEX dependency_child_service ON icinga_dependency (child_service_id); +CREATE INDEX dependency_period ON icinga_dependency (period_id); +CREATE INDEX dependency_zone ON icinga_dependency (zone_id); + + +CREATE TABLE icinga_dependency_inheritance ( + dependency_id integer NOT NULL, + parent_dependency_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (dependency_id, parent_dependency_id), + CONSTRAINT icinga_dependency_inheritance_dependency + FOREIGN KEY (dependency_id) + REFERENCES icinga_dependency (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_dependency_inheritance_parent_dependency + FOREIGN KEY (parent_dependency_id) + REFERENCES icinga_dependency (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX dependency_inheritance_unique_order ON icinga_dependency_inheritance (dependency_id, weight); +CREATE INDEX dependency_inheritance_dependency ON icinga_dependency_inheritance (dependency_id); +CREATE INDEX dependency_inheritance_dependency_parent ON icinga_dependency_inheritance (parent_dependency_id); + + +CREATE TABLE icinga_dependency_states_set ( + dependency_id integer NOT NULL, + property enum_state_name NOT NULL, + merge_behaviour enum_set_merge_behaviour NOT NULL DEFAULT 'override', + PRIMARY KEY (dependency_id, property, merge_behaviour), + CONSTRAINT icinga_dependency_states_set_dependency + FOREIGN KEY (dependency_id) + REFERENCES icinga_dependency (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX dependency_states_set_dependency ON icinga_dependency_states_set (dependency_id); +COMMENT ON COLUMN icinga_dependency_states_set.merge_behaviour IS 'override: = [], extend: += [], blacklist: -= []'; + +CREATE TABLE icinga_timeperiod_include ( + timeperiod_id integer NOT NULL, + include_id integer NOT NULL, + PRIMARY KEY (timeperiod_id, include_id), + CONSTRAINT icinga_timeperiod_timeperiod_include + FOREIGN KEY (include_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_timeperiod_include + FOREIGN KEY (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE TABLE icinga_timeperiod_exclude ( + timeperiod_id integer NOT NULL, + exclude_id integer NOT NULL, + PRIMARY KEY (timeperiod_id, exclude_id), + CONSTRAINT icinga_timeperiod_timeperiod_exclude + FOREIGN KEY (exclude_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_timeperiod_exclude + FOREIGN KEY (timeperiod_id) + REFERENCES icinga_timeperiod (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + + +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, + disabled enum_boolean NOT NULL DEFAULT 'n', + apply_to enum_host_service NULL DEFAULT NULL, + assign_filter text DEFAULT NULL, + author character varying(255) DEFAULT NULL, + comment text DEFAULT NULL, + fixed enum_boolean DEFAULT NULL, + duration int DEFAULT NULL, + with_services enum_boolean NULL DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT icinga_scheduled_downtime_zone + FOREIGN KEY (zone_id) + REFERENCES icinga_zone (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX scheduled_downtime_object_name ON icinga_scheduled_downtime (object_name); +CREATE INDEX scheduled_downtime_zone ON icinga_scheduled_downtime (zone_id); + + +CREATE TABLE icinga_scheduled_downtime_inheritance ( + scheduled_downtime_id integer NOT NULL, + parent_scheduled_downtime_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (scheduled_downtime_id, parent_scheduled_downtime_id), + CONSTRAINT icinga_scheduled_downtime_inheritance_scheduled_downtime + FOREIGN KEY (scheduled_downtime_id) + REFERENCES icinga_scheduled_downtime (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_scheduled_downtime_inheritance_parent_scheduled_downtime + FOREIGN KEY (parent_scheduled_downtime_id) + REFERENCES icinga_scheduled_downtime (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX scheduled_downtime_inheritance_unique_order ON icinga_scheduled_downtime_inheritance (scheduled_downtime_id, weight); +CREATE INDEX scheduled_downtime_inheritance_scheduled_downtime ON icinga_scheduled_downtime_inheritance (scheduled_downtime_id); +CREATE INDEX scheduled_downtime_inheritance_scheduled_downtime_parent ON icinga_scheduled_downtime_inheritance (parent_scheduled_downtime_id); + + +CREATE TABLE icinga_scheduled_downtime_range ( + scheduled_downtime_id serial, + range_key character varying(255) NOT NULL, + range_value character varying(255) NOT NULL, + range_type enum_timeperiod_range_type NOT NULL DEFAULT 'include', + merge_behaviour enum_merge_behaviour NOT NULL DEFAULT 'set', + PRIMARY KEY (scheduled_downtime_id, range_type, range_key), + CONSTRAINT icinga_scheduled_downtime_range_scheduled_downtime + FOREIGN KEY (scheduled_downtime_id) + REFERENCES icinga_scheduled_downtime (id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE INDEX scheduled_downtime_range_scheduled_downtime ON icinga_scheduled_downtime_range (scheduled_downtime_id); +COMMENT ON COLUMN icinga_scheduled_downtime_range.range_key IS 'monday, ...'; +COMMENT ON COLUMN icinga_scheduled_downtime_range.range_value IS '00:00-24:00, ...'; +COMMENT ON COLUMN icinga_scheduled_downtime_range.range_type IS 'include -> ranges {}, exclude ranges_ignore {} - not yet'; +COMMENT ON COLUMN icinga_scheduled_downtime_range.merge_behaviour IS 'set -> = {}, add -> += {}, substract -> -= {}'; + + +CREATE TABLE director_branch ( + uuid bytea NOT NULL UNIQUE CHECK(LENGTH(uuid) = 16), + owner character varying(255) NOT NULL, + branch_name character varying(255) NOT NULL, + description text DEFAULT NULL, + ts_merge_request bigint DEFAULT NULL, + PRIMARY KEY(uuid) +); +CREATE UNIQUE INDEX branch_branch_name ON director_branch (branch_name); + +CREATE TYPE enum_branch_action AS ENUM('create', 'modify', 'delete'); + +CREATE TABLE director_branch_activity ( + timestamp_ns bigint NOT NULL, + object_uuid bytea NOT NULL CHECK(LENGTH(object_uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + action enum_branch_action NOT NULL, + object_table character varying(64) NOT NULL, + author character varying(255) NOT NULL, + former_properties text NOT NULL, + modified_properties text NOT NULL, + PRIMARY KEY (timestamp_ns), + CONSTRAINT branch_activity_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); +CREATE INDEX branch_activity_object_uuid ON director_branch_activity (object_uuid); +CREATE INDEX branch_activity_branch_uuid ON director_branch_activity (branch_uuid); + + +CREATE TABLE branched_icinga_host ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + display_name CHARACTER VARYING(255) DEFAULT NULL, + address character varying(255) DEFAULT NULL, + address6 character varying(45) DEFAULT NULL, + check_command character varying(255) DEFAULT NULL, + max_check_attempts integer DEFAULT NULL, + check_period character varying(255) DEFAULT NULL, + check_interval character varying(8) DEFAULT NULL, + retry_interval character varying(8) DEFAULT NULL, + check_timeout smallint DEFAULT NULL, + enable_notifications enum_boolean DEFAULT NULL, + enable_active_checks enum_boolean DEFAULT NULL, + enable_passive_checks enum_boolean DEFAULT NULL, + enable_event_handler enum_boolean DEFAULT NULL, + enable_flapping enum_boolean DEFAULT NULL, + enable_perfdata enum_boolean DEFAULT NULL, + event_command character varying(255) DEFAULT NULL, + flapping_threshold_high smallint default null, + flapping_threshold_low smallint default null, + volatile enum_boolean DEFAULT NULL, + zone character varying(255) DEFAULT NULL, + command_endpoint character varying(255) DEFAULT NULL, + notes text DEFAULT NULL, + notes_url character varying(255) DEFAULT NULL, + action_url character varying(255) DEFAULT NULL, + icon_image character varying(255) DEFAULT NULL, + icon_image_alt character varying(255) DEFAULT NULL, + has_agent enum_boolean DEFAULT NULL, + master_should_connect enum_boolean DEFAULT NULL, + accept_config enum_boolean DEFAULT NULL, + custom_endpoint_name character varying(255) DEFAULT NULL, + api_key character varying(40) DEFAULT NULL, + -- template_choice character varying(255) DEFAULT NULL, -- TODO: Forbid them! + + imports TEXT DEFAULT NULL, + groups TEXT DEFAULT NULL, + vars TEXT DEFAULT NULL, + + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_host_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX host_branch_object_name ON branched_icinga_host (branch_uuid, object_name); +CREATE INDEX branched_host_search_object_name ON branched_icinga_host (object_name); +CREATE INDEX branched_host_search_display_name ON branched_icinga_host (display_name); + + +CREATE TABLE branched_icinga_hostgroup ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + display_name character varying(255) DEFAULT NULL, + assign_filter text DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_hostgroup_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX hostgroup_branch_object_name ON branched_icinga_hostgroup (branch_uuid, object_name); +CREATE INDEX branched_hostgroup_search_object_name ON branched_icinga_hostgroup (object_name); +CREATE INDEX branched_hostgroup_search_display_name ON branched_icinga_hostgroup (display_name); + + +CREATE TABLE branched_icinga_servicegroup ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + display_name character varying(255) DEFAULT NULL, + assign_filter text DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_servicegroup_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX servicegroup_branch_object_name ON branched_icinga_servicegroup (branch_uuid, object_name); +CREATE INDEX branched_servicegroup_search_object_name ON branched_icinga_servicegroup (object_name); +CREATE INDEX branched_servicegroup_search_display_name ON branched_icinga_servicegroup (display_name); + + +CREATE TABLE branched_icinga_usergroup ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + display_name character varying(255) DEFAULT NULL, + assign_filter text DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_usergroup_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX usergroup_branch_object_name ON branched_icinga_usergroup (branch_uuid, object_name); +CREATE INDEX branched_usergroup_search_object_name ON branched_icinga_usergroup (object_name); +CREATE INDEX branched_usergroup_search_display_name ON branched_icinga_usergroup (display_name); + + +CREATE TABLE branched_icinga_user ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + display_name character varying(255) DEFAULT NULL, + email character varying(255) DEFAULT NULL, + pager character varying(255) DEFAULT NULL, + enable_notifications enum_boolean DEFAULT NULL, + period character varying(255) DEFAULT NULL, + zone character varying(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + groups TEXT DEFAULT NULL, + vars TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_user_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX user_branch_object_name ON branched_icinga_user (branch_uuid, object_name); +CREATE INDEX branched_user_search_object_name ON branched_icinga_user (object_name); +CREATE INDEX branched_user_search_display_name ON branched_icinga_user (display_name); + + +CREATE TABLE branched_icinga_zone ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + parent character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + is_global enum_boolean DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_zone_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX zone_branch_object_name ON branched_icinga_zone (branch_uuid, object_name); +CREATE INDEX branched_zone_search_object_name ON branched_icinga_zone (object_name); + + +CREATE TABLE branched_icinga_timeperiod ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + display_name character varying(255) DEFAULT NULL, + update_method character varying(64) DEFAULT NULL, + zone character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + prefer_includes enum_boolean DEFAULT NULL, + + imports TEXT DEFAULT NULL, + ranges TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_timeperiod_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX timeperiod_branch_object_name ON branched_icinga_timeperiod (branch_uuid, object_name); +CREATE INDEX branched_timeperiod_search_object_name ON branched_icinga_timeperiod (object_name); +CREATE INDEX branched_timeperiod_search_display_name ON branched_icinga_timeperiod (display_name); + + +CREATE TABLE branched_icinga_command ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean NOT NULL DEFAULT NULL, + methods_execute character varying(64) DEFAULT NULL, + command text DEFAULT NULL, + is_string enum_boolean DEFAULT NULL, +-- env text DEFAULT NULL, + timeout smallint DEFAULT NULL, + zone character varying(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + arguments TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_command_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX command_branch_object_name ON branched_icinga_command (branch_uuid, object_name); +CREATE INDEX branched_command_search_object_name ON branched_icinga_command (object_name); + + +CREATE TABLE branched_icinga_apiuser ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name CHARACTER VARYING(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean NOT NULL DEFAULT NULL, + password CHARACTER VARYING(255) DEFAULT NULL, + client_dn CHARACTER VARYING(64) DEFAULT NULL, + permissions TEXT DEFAULT NULL, + + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_apiuser_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX apiuser_branch_object_name ON branched_icinga_apiuser (branch_uuid, object_name); +CREATE INDEX branched_apiuser_search_object_name ON branched_icinga_apiuser (object_name); + + +CREATE TABLE branched_icinga_endpoint ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + zone character varying(255) DEFAULT NULL, + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean NOT NULL DEFAULT NULL, + host character varying(255) DEFAULT NULL, + port d_smallint DEFAULT NULL, + log_duration character varying(32) DEFAULT NULL, + apiuser character varying(255) DEFAULT NULL, + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_endpoint_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX endpoint_branch_object_name ON branched_icinga_endpoint (branch_uuid, object_name); +CREATE INDEX branched_endpoint_search_object_name ON branched_icinga_endpoint (object_name); + + +CREATE TABLE branched_icinga_service ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + display_name character varying(255) DEFAULT NULL, + host character varying(255) DEFAULT NULL, + service_set character varying(255) DEFAULT NULL, + check_command character varying(255) DEFAULT NULL, + max_check_attempts integer DEFAULT NULL, + check_period character varying(255) DEFAULT NULL, + check_interval character varying(8) DEFAULT NULL, + retry_interval character varying(8) DEFAULT NULL, + check_timeout smallint DEFAULT NULL, + enable_notifications enum_boolean DEFAULT NULL, + enable_active_checks enum_boolean DEFAULT NULL, + enable_passive_checks enum_boolean DEFAULT NULL, + enable_event_handler enum_boolean DEFAULT NULL, + enable_flapping enum_boolean DEFAULT NULL, + enable_perfdata enum_boolean DEFAULT NULL, + event_command character varying(255) DEFAULT NULL, + flapping_threshold_high smallint DEFAULT NULL, + flapping_threshold_low smallint DEFAULT NULL, + volatile enum_boolean DEFAULT NULL, + zone character varying(255) DEFAULT NULL, + command_endpoint character varying(255) DEFAULT NULL, + notes text DEFAULT NULL, + notes_url character varying(255) DEFAULT NULL, + action_url character varying(255) DEFAULT NULL, + icon_image character varying(255) DEFAULT NULL, + icon_image_alt character varying(255) DEFAULT NULL, + use_agent enum_boolean DEFAULT NULL, + apply_for character varying(255) DEFAULT NULL, + use_var_overrides enum_boolean DEFAULT NULL, + assign_filter text DEFAULT NULL, + -- template_choice_id int DEFAULT NULL, + + imports TEXT DEFAULT NULL, + groups TEXT DEFAULT NULL, + vars TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_service_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX service_branch_object_name ON branched_icinga_service (branch_uuid, object_name); +CREATE INDEX branched_service_search_object_name ON branched_icinga_service (object_name); +CREATE INDEX branched_service_search_display_name ON branched_icinga_service (display_name); + + +CREATE TABLE branched_icinga_service_set ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + host character varying(255) DEFAULT NULL, + description TEXT DEFAULT NULL, + assign_filter text DEFAULT NULL, + + + imports TEXT DEFAULT NULL, + vars TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_service_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX service_set_branch_object_name ON branched_icinga_service_set (branch_uuid, object_name); +CREATE INDEX branched_service_set_search_object_name ON branched_icinga_service_set (object_name); + + +CREATE TABLE branched_icinga_notification ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name CHARACTER VARYING(255) DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + apply_to enum_host_service DEFAULT NULL, + host character varying(255) DEFAULT NULL, + service character varying(255) DEFAULT NULL, + times_begin integer DEFAULT NULL, + times_end integer DEFAULT NULL, + notification_interval integer DEFAULT NULL, + command character varying(255) DEFAULT NULL, + period character varying(255) DEFAULT NULL, + zone character varying(255) DEFAULT NULL, + assign_filter text DEFAULT NULL, + + states TEXT DEFAULT NULL, + types TEXT DEFAULT NULL, + users TEXT DEFAULT NULL, + usergroups TEXT DEFAULT NULL, + + imports TEXT DEFAULT NULL, + vars TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_notification_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX notification_branch_object_name ON branched_icinga_notification (branch_uuid, object_name); +CREATE INDEX branched_notification_search_object_name ON branched_icinga_notification (object_name); + + +CREATE TABLE branched_icinga_scheduled_downtime ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) DEFAULT NULL, + zone_id integer DEFAULT NULL, + object_type enum_object_type_all DEFAULT NULL, + disabled enum_boolean DEFAULT NULL, + apply_to enum_host_service DEFAULT NULL, + assign_filter text DEFAULT NULL, + author character varying(255) DEFAULT NULL, + comment text DEFAULT NULL, + fixed enum_boolean DEFAULT NULL, + duration int DEFAULT NULL, + with_services enum_boolean DEFAULT NULL, + + imports TEXT DEFAULT NULL, + ranges TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_scheduled_downtime_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX scheduled_downtime_branch_object_name ON branched_icinga_scheduled_downtime (branch_uuid, object_name); +CREATE INDEX branched_scheduled_downtime_search_object_name ON branched_icinga_scheduled_downtime (object_name); + + +CREATE TABLE branched_icinga_dependency ( + uuid bytea NOT NULL CHECK(LENGTH(uuid) = 16), + branch_uuid bytea NOT NULL CHECK(LENGTH(branch_uuid) = 16), + branch_created enum_boolean NOT NULL DEFAULT 'n', + branch_deleted enum_boolean NOT NULL DEFAULT 'n', + + object_name character varying(255) NOT NULL, + object_type enum_object_type_all NOT NULL, + disabled enum_boolean DEFAULT 'n', + apply_to enum_host_service NULL DEFAULT NULL, + parent_host character varying(255) DEFAULT NULL, + parent_host_var character varying(128) DEFAULT NULL, + parent_service character varying(255) DEFAULT NULL, + child_host character varying(255) DEFAULT NULL, + child_service character varying(255) DEFAULT NULL, + disable_checks enum_boolean DEFAULT NULL, + disable_notifications enum_boolean DEFAULT NULL, + ignore_soft_states enum_boolean DEFAULT NULL, + period_id integer DEFAULT NULL, + zone_id integer DEFAULT NULL, + assign_filter text DEFAULT NULL, + parent_service_by_name character varying(255), + + imports TEXT DEFAULT NULL, + set_null TEXT DEFAULT NULL, + PRIMARY KEY (branch_uuid, uuid), + CONSTRAINT icinga_dependency_branch + FOREIGN KEY (branch_uuid) + REFERENCES director_branch (uuid) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX dependency_branch_object_name ON branched_icinga_dependency (branch_uuid, object_name); +CREATE INDEX branched_dependency_search_object_name ON branched_icinga_dependency (object_name); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (182, NOW()); |