diff options
Diffstat (limited to 'schema/pgsql-migrations')
95 files changed, 2566 insertions, 0 deletions
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()); |