Bulk update PostgreSQL schema to 76

refs #11110
This commit is contained in:
Markus Frosch 2016-02-29 23:51:34 +01:00
parent c2347b6b97
commit e0b44e3f01
1 changed files with 269 additions and 84 deletions

View File

@ -1,22 +1,27 @@
-- TODO:
-- --
-- - SEE mysql.sql TODOs -- PostgreSQL schema
-- - FOREIGN KEYS (INDEXES), TIMESTAMPs overview -- =================
-- - SET sql_mode = ???
-- --
-- NOTES: -- You should normally not be required to care about schema handling.
-- Director does all the migrations for you and guides you either in
-- the frontend or provides everything you need for automated migration
-- handling. Please find more related information in our documentation.
-- --
-- INSERT INTO director_activity_log (object_type, object_name, action_name, author, change_time, checksum) VALUES('object', 'foo', 'create', 'alex', CURRENT_TIMESTAMP, decode('cf23df2207d99a74fbe169e3eba035e633b65d94', 'hex')); -- Please note: PostgreSQL has not all migrations as MySQL have them
--
-- If you have used PostgreSQL prior the first release of director,
-- you might have to recreate the schema.
-- --
CREATE TYPE enum_activity_action AS ENUM('create', 'delete', 'modify'); CREATE TYPE enum_activity_action AS ENUM('create', 'delete', 'modify');
CREATE TYPE enum_boolean AS ENUM('y', 'n'); CREATE TYPE enum_boolean AS ENUM('y', 'n');
CREATE TYPE enum_property_format AS ENUM('string', 'expression', 'json'); CREATE TYPE enum_property_format AS ENUM('string', 'expression', 'json');
CREATE TYPE enum_object_type AS ENUM('object', 'template'); CREATE TYPE enum_object_type_all AS ENUM('object', 'template', 'apply', 'external_object'); -- TODO: can we check for an invalid
CREATE TYPE enum_object_type AS ENUM('object', 'template', 'external_object');
CREATE TYPE enum_timeperiod_range_type AS ENUM('include', 'exclude'); CREATE TYPE enum_timeperiod_range_type AS ENUM('include', 'exclude');
CREATE TYPE enum_merge_behaviour AS ENUM('set', 'add', 'substract'); CREATE TYPE enum_merge_behaviour AS ENUM('set', 'add', 'substract');
CREATE TYPE enum_command_object_type AS ENUM('object', 'template', 'external_object'); CREATE TYPE enum_command_object_type AS ENUM('object', 'template', 'external_object');
CREATE TYPE enum_apply_object_type AS ENUM('object', 'template', 'apply'); CREATE TYPE enum_apply_object_type AS ENUM('object', 'template', 'apply', 'external_object');
CREATE TYPE enum_state_name AS ENUM('OK', 'Warning', 'Critical', 'Unknown', 'Up', 'Down'); CREATE TYPE enum_state_name AS ENUM('OK', 'Warning', 'Critical', 'Unknown', 'Up', 'Down');
CREATE TYPE enum_type_name AS ENUM('DowntimeStart', 'DowntimeEnd', 'DowntimeRemoved', 'Custom', 'Acknowledgement', 'Problem', 'Recovery', 'FlappingStart', 'FlappingEnd'); CREATE TYPE enum_type_name AS ENUM('DowntimeStart', 'DowntimeEnd', 'DowntimeRemoved', 'Custom', 'Acknowledgement', 'Problem', 'Recovery', 'FlappingStart', 'FlappingEnd');
CREATE TYPE enum_sync_rule_object_type AS ENUM('host', 'user'); CREATE TYPE enum_sync_rule_object_type AS ENUM('host', 'user');
@ -24,11 +29,6 @@ CREATE TYPE enum_sync_rule_update_policy AS ENUM('merge', 'override', 'ignore');
CREATE TYPE enum_sync_property_merge_policy AS ENUM('override', 'merge'); CREATE TYPE enum_sync_property_merge_policy AS ENUM('override', 'merge');
CREATE TABLE director_dbversion (
schema_version INTEGER NOT NULL
);
CREATE TABLE director_activity_log ( CREATE TABLE director_activity_log (
id bigserial, id bigserial,
object_type character varying(64) NOT NULL, object_type character varying(64) NOT NULL,
@ -55,6 +55,7 @@ CREATE TABLE director_generated_config (
director_version character varying(64) DEFAULT NULL, director_version character varying(64) DEFAULT NULL,
director_db_version integer DEFAULT NULL, director_db_version integer DEFAULT NULL,
duration integer DEFAULT NULL, duration integer DEFAULT NULL,
first_activity_checksum bytea NOT NULL CHECK(LENGTH(first_activity_checksum) = 20),
last_activity_checksum bytea NOT NULL CHECK(LENGTH(last_activity_checksum) = 20), last_activity_checksum bytea NOT NULL CHECK(LENGTH(last_activity_checksum) = 20),
PRIMARY KEY (checksum), PRIMARY KEY (checksum),
CONSTRAINT director_generated_config_activity CONSTRAINT director_generated_config_activity
@ -72,6 +73,8 @@ COMMENT ON COLUMN director_generated_config.duration IS 'Config generation durat
CREATE TABLE director_generated_file ( CREATE TABLE director_generated_file (
checksum bytea CHECK(LENGTH(checksum) = 20), checksum bytea CHECK(LENGTH(checksum) = 20),
content text DEFAULT NULL, content text DEFAULT NULL,
cnt_object SMALLINT NOT NULL DEFAULT 0,
cnt_template SMALLINT NOT NULL DEFAULT 0,
PRIMARY KEY (checksum) PRIMARY KEY (checksum)
); );
@ -102,19 +105,27 @@ COMMENT ON COLUMN director_generated_config_file.file_path IS 'e.g. zones/nafta/
CREATE TABLE director_deployment_log ( CREATE TABLE director_deployment_log (
id bigserial, id bigserial,
config_id bigint NOT NULL, config_checksum bytea CHECK(LENGTH(config_checksum) = 20),
last_activity_checksum bytea CHECK(LENGTH(config_checksum) = 20),
peer_identity character varying(64) NOT NULL, peer_identity character varying(64) NOT NULL,
start_time timestamp with time zone NOT NULL, start_time timestamp with time zone NOT NULL,
end_time timestamp with time zone DEFAULT NULL, end_time timestamp with time zone DEFAULT NULL,
abort_time timestamp with time zone DEFAULT NULL, abort_time timestamp with time zone DEFAULT NULL,
duration_connection integer DEFAULT NULL, duration_connection integer DEFAULT NULL,
duration_dump integer DEFAULT NULL, duration_dump integer DEFAULT NULL,
stage_name CHARACTER VARYING(96),
stage_collected enum_boolean DEFAULT NULL,
connection_succeeded enum_boolean DEFAULT NULL, connection_succeeded enum_boolean DEFAULT NULL,
dump_succeeded enum_boolean DEFAULT NULL, dump_succeeded enum_boolean DEFAULT NULL,
startup_succeeded enum_boolean DEFAULT NULL, startup_succeeded enum_boolean DEFAULT NULL,
username character varying(64) DEFAULT NULL, username character varying(64) DEFAULT NULL,
startup_log text DEFAULT NULL, startup_log text DEFAULT NULL,
PRIMARY KEY (id) PRIMARY KEY (id),
CONSTRAINT config_checksum
FOREIGN KEY (config_checksum)
REFERENCES director_generated_config (checksum)
ON DELETE SET NULL
ON UPDATE RESTRICT
); );
COMMENT ON COLUMN director_deployment_log.duration_connection IS 'The time it took to connect to an Icinga node (ms)'; COMMENT ON COLUMN director_deployment_log.duration_connection IS 'The time it took to connect to an Icinga node (ms)';
@ -150,7 +161,7 @@ CREATE INDEX datalist_entry_datalist ON director_datalist_entry (list_id);
CREATE TABLE director_datafield ( CREATE TABLE director_datafield (
id serial, id serial,
varname character varying(255) NOT NULL, varname character varying(64) NOT NULL,
caption character varying(255) NOT NULL, caption character varying(255) NOT NULL,
description text DEFAULT NULL, description text DEFAULT NULL,
datatype character varying(255) NOT NULL, datatype character varying(255) NOT NULL,
@ -159,11 +170,44 @@ CREATE TABLE director_datafield (
PRIMARY KEY (id) PRIMARY KEY (id)
); );
CREATE INDEX search_idx ON director_datafield (varname);
CREATE TABLE director_datafield_setting (
datafield_id integer NOT NULL,
setting_name character varying(64) NOT NULL,
setting_value text NOT NULL,
PRIMARY KEY (datafield_id, setting_name),
CONSTRAINT datafield_id_settings
FOREIGN KEY (datafield_id)
REFERENCES director_datafield (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE INDEX director_datafield_datafield ON director_datafield_setting (datafield_id);
CREATE TABLE director_schema_migration (
schema_version SMALLINT NOT NULL,
migration_time TIMESTAMP WITH TIME ZONE NOT NULL,
PRIMARY KEY(schema_version)
);
CREATE TABLE director_setting (
setting_name character varying(64) NOT NULL,
setting_value character varying(255) NOT NULL,
PRIMARY KEY(setting_name)
);
CREATE TABLE icinga_zone ( CREATE TABLE icinga_zone (
id serial, id serial,
parent_zone_id integer DEFAULT NULL, parent_zone_id integer DEFAULT NULL,
object_name character varying(255) NOT NULL UNIQUE, object_name character varying(255) NOT NULL UNIQUE,
object_type enum_object_type NOT NULL, object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
is_global enum_boolean NOT NULL DEFAULT 'n', is_global enum_boolean NOT NULL DEFAULT 'n',
PRIMARY KEY (id), PRIMARY KEY (id),
CONSTRAINT icinga_zone_parent_zone CONSTRAINT icinga_zone_parent_zone
@ -204,7 +248,8 @@ CREATE TABLE icinga_timeperiod (
display_name character varying(255) DEFAULT NULL, display_name character varying(255) DEFAULT NULL,
update_method character varying(64) DEFAULT NULL, update_method character varying(64) DEFAULT NULL,
zone_id integer DEFAULT NULL, zone_id integer DEFAULT NULL,
object_type enum_object_type NOT NULL, object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
PRIMARY KEY (id), PRIMARY KEY (id),
CONSTRAINT icinga_timeperiod_zone CONSTRAINT icinga_timeperiod_zone
FOREIGN KEY (zone_id) FOREIGN KEY (zone_id)
@ -264,13 +309,14 @@ COMMENT ON COLUMN icinga_timeperiod_range.merge_behaviour IS 'set -> = {}, add -
CREATE TABLE icinga_command ( CREATE TABLE icinga_command (
id serial, id serial,
object_name character varying(255) NOT NULL, object_name character varying(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
methods_execute character varying(64) DEFAULT NULL, methods_execute character varying(64) DEFAULT NULL,
command character varying(255) DEFAULT NULL, command character varying(255) DEFAULT NULL,
-- env text DEFAULT NULL, -- env text DEFAULT NULL,
-- vars text DEFAULT NULL, -- vars text DEFAULT NULL,
timeout smallint DEFAULT NULL, timeout smallint DEFAULT NULL,
zone_id integer DEFAULT NULL, zone_id integer DEFAULT NULL,
object_type enum_command_object_type NOT NULL,
PRIMARY KEY (id), PRIMARY KEY (id),
CONSTRAINT icinga_command_zone CONSTRAINT icinga_command_zone
FOREIGN KEY (zone_id) FOREIGN KEY (zone_id)
@ -335,6 +381,24 @@ COMMENT ON COLUMN icinga_command_argument.key_string IS 'Overrides name';
COMMENT ON COLUMN icinga_command_argument.repeat_key IS 'Useful with array values'; COMMENT ON COLUMN icinga_command_argument.repeat_key IS 'Useful with array values';
CREATE TABLE icinga_command_field (
command_id integer NOT NULL,
datafield_id integer NOT NULL,
is_required enum_boolean NOT NULL,
PRIMARY KEY (command_id, datafield_id),
CONSTRAINT icinga_command_field_command
FOREIGN KEY (command_id)
REFERENCES icinga_command (id)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT icinga_command_field_datafield
FOREIGN KEY (datafield_id)
REFERENCES director_datafield (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE icinga_command_var ( CREATE TABLE icinga_command_var (
command_id integer NOT NULL, command_id integer NOT NULL,
varname character varying(255) DEFAULT NULL, varname character varying(255) DEFAULT NULL,
@ -351,25 +415,46 @@ CREATE TABLE icinga_command_var (
CREATE INDEX command_var_command ON icinga_command_var (command_id); CREATE INDEX command_var_command ON icinga_command_var (command_id);
CREATE TABLE icinga_apiuser (
id BIGSERIAL,
object_name CHARACTER VARYING(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
password CHARACTER VARYING(255) DEFAULT NULL,
client_dn CHARACTER VARYING(64) DEFAULT NULL,
permissions TEXT DEFAULT NULL,
PRIMARY KEY (id)
);
COMMENT ON COLUMN icinga_apiuser.permissions IS 'JSON-encoded permissions';
CREATE TABLE icinga_endpoint ( CREATE TABLE icinga_endpoint (
id serial, id serial,
zone_id integer DEFAULT NULL, zone_id integer DEFAULT NULL,
object_name character varying(255) NOT NULL, object_name character varying(255) NOT NULL,
address character varying(255) DEFAULT NULL, object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
host character varying(255) DEFAULT NULL,
port smallint DEFAULT NULL, port smallint DEFAULT NULL,
log_duration character varying(32) DEFAULT NULL, log_duration character varying(32) DEFAULT NULL,
object_type enum_object_type NOT NULL, apiuser_id INTEGER DEFAULT NULL,
PRIMARY KEY (id), PRIMARY KEY (id),
CONSTRAINT icinga_endpoint_zone CONSTRAINT icinga_endpoint_zone
FOREIGN KEY (zone_id) FOREIGN KEY (zone_id)
REFERENCES icinga_zone (id) REFERENCES icinga_zone (id)
ON DELETE RESTRICT ON DELETE RESTRICT
ON UPDATE CASCADE,
CONSTRAINT icinga_apiuser
FOREIGN KEY (apiuser_id)
REFERENCES icinga_apiuser (id)
ON DELETE RESTRICT
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE UNIQUE INDEX endpoint_object_name ON icinga_endpoint (object_name); CREATE UNIQUE INDEX endpoint_object_name ON icinga_endpoint (object_name);
CREATE INDEX endpoint_zone ON icinga_endpoint (zone_id); CREATE INDEX endpoint_zone ON icinga_endpoint (zone_id);
COMMENT ON COLUMN icinga_endpoint.address IS 'IP address / hostname of remote node'; COMMENT ON COLUMN icinga_endpoint.host IS 'IP address / hostname of remote node';
COMMENT ON COLUMN icinga_endpoint.port IS '5665 if not set'; COMMENT ON COLUMN icinga_endpoint.port IS '5665 if not set';
COMMENT ON COLUMN icinga_endpoint.log_duration IS '1d if not set'; COMMENT ON COLUMN icinga_endpoint.log_duration IS '1d if not set';
@ -399,6 +484,9 @@ CREATE INDEX endpoint_inheritance_endpoint_parent ON icinga_endpoint_inheritance
CREATE TABLE icinga_host ( CREATE TABLE icinga_host (
id serial, id serial,
object_name character varying(255) NOT NULL, object_name character varying(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
display_name CHARACTER VARYING(255) DEFAULT NULL,
address character varying(64) DEFAULT NULL, address character varying(64) DEFAULT NULL,
address6 character varying(45) DEFAULT NULL, address6 character varying(45) DEFAULT NULL,
check_command_id integer DEFAULT NULL, check_command_id integer DEFAULT NULL,
@ -422,7 +510,9 @@ CREATE TABLE icinga_host (
action_url character varying(255) DEFAULT NULL, action_url character varying(255) DEFAULT NULL,
icon_image character varying(255) DEFAULT NULL, icon_image character varying(255) DEFAULT NULL,
icon_image_alt character varying(255) DEFAULT NULL, icon_image_alt character varying(255) DEFAULT NULL,
object_type enum_object_type NOT NULL, has_agent enum_boolean NOT NULL DEFAULT NULL,
master_should_connect enum_boolean NOT NULL DEFAULT NULL,
accept_config enum_boolean NOT NULL DEFAULT NULL,
PRIMARY KEY (id), PRIMARY KEY (id),
CONSTRAINT icinga_host_zone CONSTRAINT icinga_host_zone
FOREIGN KEY (zone_id) FOREIGN KEY (zone_id)
@ -524,7 +614,10 @@ CREATE INDEX host_var_host ON icinga_host_var (host_id);
CREATE TABLE icinga_service ( CREATE TABLE icinga_service (
id serial, id serial,
object_name character varying(255) NOT NULL, object_name character varying(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean DEFAULT 'n',
display_name character varying(255) DEFAULT NULL, display_name character varying(255) DEFAULT NULL,
host_id INTEGER DEFAULT NULL,
check_command_id integer DEFAULT NULL, check_command_id integer DEFAULT NULL,
max_check_attempts integer DEFAULT NULL, max_check_attempts integer DEFAULT NULL,
check_period_id integer DEFAULT NULL, check_period_id integer DEFAULT NULL,
@ -546,9 +639,14 @@ CREATE TABLE icinga_service (
action_url character varying(255) DEFAULT NULL, action_url character varying(255) DEFAULT NULL,
icon_image character varying(255) DEFAULT NULL, icon_image character varying(255) DEFAULT NULL,
icon_image_alt character varying(255) DEFAULT NULL, icon_image_alt character varying(255) DEFAULT NULL,
object_type enum_apply_object_type NOT NULL, use_agent enum_boolean DEFAULT NULL,
PRIMARY KEY (id), PRIMARY KEY (id),
-- UNIQUE INDEX object_name (object_name, zone_id), -- UNIQUE INDEX object_name (object_name, zone_id),
CONSTRAINT icinga_service_host
FOREIGN KEY (host_id)
REFERENCES icinga_host (id)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT icinga_service_zone CONSTRAINT icinga_service_zone
FOREIGN KEY (zone_id) FOREIGN KEY (zone_id)
REFERENCES icinga_zone (id) REFERENCES icinga_zone (id)
@ -605,6 +703,23 @@ CREATE INDEX service_inheritance_service ON icinga_service_inheritance (service_
CREATE INDEX service_inheritance_service_parent ON icinga_service_inheritance (parent_service_id); CREATE INDEX service_inheritance_service_parent ON icinga_service_inheritance (parent_service_id);
CREATE TABLE icinga_service_var (
service_id integer NOT NULL,
varname character varying(255) DEFAULT NULL,
varvalue text DEFAULT NULL,
format enum_property_format,
PRIMARY KEY (service_id, varname),
CONSTRAINT icinga_service_var_service
FOREIGN KEY (service_id)
REFERENCES icinga_service (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE INDEX service_var_search_idx ON icinga_service_var (varname);
CREATE INDEX service_var_service ON icinga_service_var (service_id);
CREATE TABLE icinga_service_field ( CREATE TABLE icinga_service_field (
service_id integer NOT NULL, service_id integer NOT NULL,
datafield_id integer NOT NULL, datafield_id integer NOT NULL,
@ -628,22 +743,18 @@ CREATE INDEX service_field_datafield ON icinga_service_field (datafield_id);
COMMENT ON COLUMN icinga_service_field.service_id IS 'Makes only sense for templates'; COMMENT ON COLUMN icinga_service_field.service_id IS 'Makes only sense for templates';
CREATE TABLE icinga_service_var ( CREATE TABLE icinga_service_assignment (
id bigserial,
service_id integer NOT NULL, service_id integer NOT NULL,
varname character varying(255) DEFAULT NULL, filter_string TEXT NOT NULL,
varvalue text DEFAULT NULL, PRIMARY KEY (id),
format enum_property_format, CONSTRAINT icinga_service_assignment
PRIMARY KEY (service_id, varname), FOREIGN KEY (service_id)
CONSTRAINT icinga_service_var_service
FOREIGN KEY (service_id)
REFERENCES icinga_service (id) REFERENCES icinga_service (id)
ON DELETE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE INDEX service_var_search_idx ON icinga_service_var (varname);
CREATE INDEX service_var_service ON icinga_service_var (service_id);
CREATE TABLE icinga_host_service ( CREATE TABLE icinga_host_service (
host_id integer NOT NULL, host_id integer NOT NULL,
@ -668,8 +779,9 @@ CREATE INDEX host_service_service ON icinga_host_service (service_id);
CREATE TABLE icinga_hostgroup ( CREATE TABLE icinga_hostgroup (
id serial, id serial,
object_name character varying(255) NOT NULL, object_name character varying(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
display_name character varying(255) DEFAULT NULL, display_name character varying(255) DEFAULT NULL,
object_type enum_object_type NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
); );
@ -703,8 +815,9 @@ CREATE INDEX hostgroup_inheritance_hostgroup_parent ON icinga_hostgroup_inherita
CREATE TABLE icinga_servicegroup ( CREATE TABLE icinga_servicegroup (
id serial, id serial,
object_name character varying(255) DEFAULT NULL, object_name character varying(255) DEFAULT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
display_name character varying(255) DEFAULT NULL, display_name character varying(255) DEFAULT NULL,
object_type enum_object_type NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
); );
@ -797,13 +910,14 @@ CREATE INDEX hostgroup_parent_parent ON icinga_hostgroup_parent (parent_hostgrou
CREATE TABLE icinga_user ( CREATE TABLE icinga_user (
id serial, id serial,
object_name character varying(255) DEFAULT NULL, object_name character varying(255) DEFAULT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
display_name character varying(255) DEFAULT NULL, display_name character varying(255) DEFAULT NULL,
email character varying(255) DEFAULT NULL, email character varying(255) DEFAULT NULL,
pager character varying(255) DEFAULT NULL, pager character varying(255) DEFAULT NULL,
enable_notifications enum_boolean DEFAULT NULL, enable_notifications enum_boolean DEFAULT NULL,
period_id integer DEFAULT NULL, period_id integer DEFAULT NULL,
zone_id integer DEFAULT NULL, zone_id integer DEFAULT NULL,
object_type enum_object_type NOT NULL,
PRIMARY KEY (id), PRIMARY KEY (id),
CONSTRAINT icinga_user_zone CONSTRAINT icinga_user_zone
FOREIGN KEY (zone_id) FOREIGN KEY (zone_id)
@ -838,11 +952,11 @@ CREATE INDEX user_inheritance_user ON icinga_user_inheritance (user_id);
CREATE INDEX user_inheritance_user_parent ON icinga_user_inheritance (parent_user_id); CREATE INDEX user_inheritance_user_parent ON icinga_user_inheritance (parent_user_id);
CREATE TABLE icinga_user_filter_state ( CREATE TABLE icinga_user_states_set (
user_id integer NOT NULL, user_id integer NOT NULL,
state_name enum_state_name NOT NULL, property enum_state_name NOT NULL,
merge_behaviour enum_merge_behaviour NOT NULL DEFAULT 'set', merge_behaviour enum_merge_behaviour NOT NULL DEFAULT 'set',
PRIMARY KEY (user_id, state_name), PRIMARY KEY (user_id, property),
CONSTRAINT icinga_user_filter_state_user CONSTRAINT icinga_user_filter_state_user
FOREIGN KEY (user_id) FOREIGN KEY (user_id)
REFERENCES icinga_user (id) REFERENCES icinga_user (id)
@ -850,15 +964,15 @@ CREATE TABLE icinga_user_filter_state (
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE INDEX user_filter_state_user ON icinga_user_filter_state (user_id); CREATE INDEX user_states_set_user ON icinga_user_states_set (user_id);
COMMENT ON COLUMN icinga_user_filter_state.merge_behaviour IS 'set: = [], add: += [], substract: -= []'; COMMENT ON COLUMN icinga_user_states_set.merge_behaviour IS 'set: = [], add: += [], substract: -= []';
CREATE TABLE icinga_user_filter_type ( CREATE TABLE icinga_user_types_set (
user_id integer NOT NULL, user_id integer NOT NULL,
type_name enum_type_name NOT NULL, property enum_type_name NOT NULL,
merge_behaviour enum_merge_behaviour NOT NULL DEFAULT 'set', merge_behaviour enum_merge_behaviour NOT NULL DEFAULT 'set',
PRIMARY KEY (user_id, type_name), PRIMARY KEY (user_id, property),
CONSTRAINT icinga_user_filter_type_user CONSTRAINT icinga_user_filter_type_user
FOREIGN KEY (user_id) FOREIGN KEY (user_id)
REFERENCES icinga_user (id) REFERENCES icinga_user (id)
@ -866,8 +980,8 @@ CREATE TABLE icinga_user_filter_type (
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE INDEX user_filter_type_user ON icinga_user_filter_type (user_id); CREATE INDEX user_types_set_user ON icinga_user_types_set (user_id);
COMMENT ON COLUMN icinga_user_filter_type.merge_behaviour IS 'set: = [], add: += [], substract: -= []'; COMMENT ON COLUMN icinga_user_types_set.merge_behaviour IS 'set: = [], add: += [], substract: -= []';
CREATE TABLE icinga_user_var ( CREATE TABLE icinga_user_var (
@ -890,9 +1004,10 @@ CREATE INDEX user_var_user ON icinga_user_var (user_id);
CREATE TABLE icinga_usergroup ( CREATE TABLE icinga_usergroup (
id serial, id serial,
object_name character varying(255) NOT NULL, object_name character varying(255) NOT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
display_name character varying(255) DEFAULT NULL, display_name character varying(255) DEFAULT NULL,
zone_id integer DEFAULT NULL, zone_id integer DEFAULT NULL,
object_type enum_object_type NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
); );
@ -962,6 +1077,48 @@ CREATE INDEX usergroup_parent_usergroup ON icinga_usergroup_parent (usergroup_id
CREATE INDEX usergroup_parent_parent ON icinga_usergroup_parent (parent_usergroup_id); CREATE INDEX usergroup_parent_parent ON icinga_usergroup_parent (parent_usergroup_id);
CREATE TABLE icinga_notification (
id serial,
object_name CHARACTER VARYING(255) DEFAULT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
host_id integer DEFAULT NULL,
service_id integer DEFAULT NULL,
times_begin integer DEFAULT NULL,
times_end integer DEFAULT NULL,
notification_interval integer DEFAULT NULL,
command_id integer DEFAULT NULL,
period_id integer DEFAULT NULL,
zone_id integer DEFAULT NULL,
PRIMARY KEY (id),
CONSTRAINT icinga_notification_host
FOREIGN KEY (host_id)
REFERENCES icinga_host (id)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT icinga_notification_service
FOREIGN KEY (service_id)
REFERENCES icinga_service (id)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT icinga_notification_command
FOREIGN KEY (command_id)
REFERENCES icinga_command (id)
ON DELETE RESTRICT
ON UPDATE CASCADE,
CONSTRAINT icinga_notification_period
FOREIGN KEY (period_id)
REFERENCES icinga_timeperiod (id)
ON DELETE RESTRICT
ON UPDATE CASCADE,
CONSTRAINT icinga_notification_zone
FOREIGN KEY (zone_id)
REFERENCES icinga_zone (id)
ON DELETE RESTRICT
ON UPDATE CASCADE
);
CREATE TABLE import_source ( CREATE TABLE import_source (
id serial, id serial,
source_name character varying(64) NOT NULL, source_name character varying(64) NOT NULL,
@ -988,6 +1145,36 @@ CREATE TABLE import_source_setting (
CREATE INDEX import_source_setting_source ON import_source_setting (source_id); CREATE INDEX import_source_setting_source ON import_source_setting (source_id);
CREATE TABLE import_row_modifier (
id bigserial,
source_id integer NOT NULL,
property_name character varying(255) NOT NULL,
provider_class character varying(72) NOT NULL,
priority integer NOT NULL,
PRIMARY KEY (id),
CONSTRAINT row_modifier_import_source
FOREIGN KEY (source_id)
REFERENCES import_source (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE INDEX import_row_modifier_search_idx ON import_row_modifier (property_name);
CREATE TABLE import_row_modifier_setting (
row_modifier_id serial,
setting_name character varying(64) NOT NULL,
setting_value TEXT DEFAULT NULL,
PRIMARY KEY (row_modifier_id, setting_name),
CONSTRAINT row_modifier_settings
FOREIGN KEY (row_modifier_id)
REFERENCES import_row_modifier (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE imported_rowset ( CREATE TABLE imported_rowset (
checksum bytea CHECK(LENGTH(checksum) = 20), checksum bytea CHECK(LENGTH(checksum) = 20),
PRIMARY KEY (checksum) PRIMARY KEY (checksum)
@ -1028,24 +1215,25 @@ COMMENT ON COLUMN imported_row.checksum IS 'sha1(object_name;property_checksum;.
CREATE TABLE imported_rowset_row ( CREATE TABLE imported_rowset_row (
rowset_checksum bytea CHECK(LENGTH(checksum) = 20), rowset_checksum bytea CHECK(LENGTH(rowset_checksum) = 20),
row_checksum bytea CHECK(LENGTH(checksum) = 20), row_checksum bytea CHECK(LENGTH(row_checksum) = 20),
PRIMARY KEY (rowset_checksum, row_checksum), PRIMARY KEY (rowset_checksum, row_checksum),
CONSTRAINT imported_rowset_row_rowset CONSTRAINT imported_rowset_row_rowset
FOREIGN KEY (rowset_checksum) FOREIGN KEY (rowset_checksum)
REFERENCES imported_rowset (checksum) REFERENCES imported_rowset (checksum)
ON DELETE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE, ON UPDATE CASCADE,
CONSTRAINT imported_rowset_row_row CONSTRAINT imported_rowset_row_row
FOREIGN KEY (row_checksum) FOREIGN KEY (row_checksum)
REFERENCES imported_row (checksum) REFERENCES imported_row (checksum)
ON DELETE RESTRICT ON DELETE RESTRICT
ON UPDATE CASCADE ON UPDATE CASCADE
); );
CREATE INDEX imported_rowset_row_rowset_checksum ON imported_rowset_row (rowset_checksum); CREATE INDEX imported_rowset_row_rowset_checksum ON imported_rowset_row (rowset_checksum);
CREATE INDEX imported_rowset_row_row_checksum ON imported_rowset_row (row_checksum); CREATE INDEX imported_rowset_row_row_checksum ON imported_rowset_row (row_checksum);
CREATE TABLE imported_property ( CREATE TABLE imported_property (
checksum bytea CHECK(LENGTH(checksum) = 20), checksum bytea CHECK(LENGTH(checksum) = 20),
property_name character varying(64) NOT NULL, property_name character varying(64) NOT NULL,
@ -1056,6 +1244,7 @@ CREATE TABLE imported_property (
CREATE INDEX imported_property_search_idx ON imported_property (property_name); CREATE INDEX imported_property_search_idx ON imported_property (property_name);
CREATE TABLE imported_row_property ( CREATE TABLE imported_row_property (
row_checksum bytea CHECK(LENGTH(row_checksum) = 20), row_checksum bytea CHECK(LENGTH(row_checksum) = 20),
property_checksum bytea CHECK(LENGTH(property_checksum) = 20), property_checksum bytea CHECK(LENGTH(property_checksum) = 20),
@ -1075,6 +1264,7 @@ CREATE TABLE imported_row_property (
CREATE INDEX imported_row_property_row_checksum ON imported_row_property (row_checksum); CREATE INDEX imported_row_property_row_checksum ON imported_row_property (row_checksum);
CREATE INDEX imported_row_property_property_checksum ON imported_row_property (property_checksum); CREATE INDEX imported_row_property_property_checksum ON imported_row_property (property_checksum);
CREATE TABLE sync_rule ( CREATE TABLE sync_rule (
id serial, id serial,
rule_name character varying(255) NOT NULL, rule_name character varying(255) NOT NULL,
@ -1112,32 +1302,27 @@ CREATE INDEX sync_property_rule ON sync_property (rule_id);
CREATE INDEX sync_property_source ON sync_property (source_id); CREATE INDEX sync_property_source ON sync_property (source_id);
CREATE TABLE import_row_modifier ( CREATE TABLE sync_run (
id serial, id bigserial,
property_id integer NOT NULL, rule_id integer NOT NULL,
provider_class character varying(72) NOT NULL, rule_name character varying(255) NOT NULL,
PRIMARY KEY (id) start_time TIMESTAMP WITH TIME ZONE NOT NULL,
duration_ms integer DEFAULT NULL,
objects_deleted integer DEFAULT 0,
objects_created integer DEFAULT 0,
objects_modified integer DEFAULT 0,
last_former_activity bytea DEFAULT NULL CHECK(LENGTH(last_former_activity) = 20),
last_related_activity bytea DEFAULT NULL CHECK(LENGTH(last_related_activity) = 20),
PRIMARY KEY (id),
CONSTRAINT sync_run_rule
FOREIGN KEY (rule_id)
REFERENCES sync_rule (id)
ON DELETE SET NULL
ON UPDATE CASCADE
); );
CREATE TABLE import_row_modifier_setting ( -- set current schema version
modifier_id integer NOT NULL, INSERT INTO director_schema_migration
setting_name character varying(64) NOT NULL, (schema_version, migration_time)
setting_value text DEFAULT NULL, VALUES (76, NOW());
PRIMARY KEY (modifier_id)
);
CREATE TABLE director_datafield_setting (
datafield_id integer NOT NULL,
setting_name character varying(64) NOT NULL,
setting_value text NOT NULL,
PRIMARY KEY (datafield_id, setting_name),
CONSTRAINT datafield_id_settings
FOREIGN KEY (datafield_id)
REFERENCES director_datafield (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE INDEX director_datafield_datafield ON director_datafield_setting (datafield_id);