schema/pgsql: add choices

This commit is contained in:
Thomas Gelf 2017-07-04 06:45:22 +02:00
parent 67d802d39a
commit 69579bcaf9
3 changed files with 89 additions and 1 deletions

View file

@ -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());

View file

@ -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());

View file

@ -544,6 +544,17 @@ CREATE INDEX endpoint_inheritance_endpoint ON icinga_endpoint_inheritance (endpo
CREATE INDEX endpoint_inheritance_endpoint_parent ON icinga_endpoint_inheritance (parent_endpoint_id);
CREATE TABLE icinga_host_template_choice (
id serial,
object_name character varying(64) NOT NULL,
description text DEFAULT NULL,
min_required smallint NOT NULL DEFAULT 0,
max_allowed smallint NOT NULL DEFAULT 1,
PRIMARY KEY (id)
);
CREATE UNIQUE INDEX host_template_choice_object_name ON icinga_host_template_choice (object_name);
CREATE TABLE icinga_host (
id serial,
object_name character varying(255) NOT NULL,
@ -577,6 +588,7 @@ CREATE TABLE icinga_host (
master_should_connect enum_boolean DEFAULT NULL,
accept_config enum_boolean DEFAULT NULL,
api_key character varying(40) DEFAULT NULL,
template_choice_id int DEFAULT NULL,
PRIMARY KEY (id),
CONSTRAINT icinga_host_zone
FOREIGN KEY (zone_id)
@ -602,9 +614,15 @@ CREATE TABLE icinga_host (
FOREIGN KEY (command_endpoint_id)
REFERENCES icinga_endpoint (id)
ON DELETE RESTRICT
ON UPDATE CASCADE,
CONSTRAINT icinga_host_template_choice
FOREIGN KEY (template_choice_id)
REFERENCES icinga_host_template_choice (id)
ON DELETE RESTRICT
ON UPDATE CASCADE
);
CREATE UNIQUE INDEX object_name_host ON icinga_host (object_name, zone_id);
CREATE UNIQUE INDEX host_api_key ON icinga_host (api_key);
CREATE INDEX host_zone ON icinga_host (zone_id);
@ -612,6 +630,7 @@ CREATE INDEX host_timeperiod ON icinga_host (check_period_id);
CREATE INDEX host_check_command ON icinga_host (check_command_id);
CREATE INDEX host_event_command ON icinga_host (event_command_id);
CREATE INDEX host_command_endpoint ON icinga_host (command_endpoint_id);
CREATE INDEX host_template_choice ON icinga_host (template_choice_id);
CREATE TABLE icinga_host_inheritance (
@ -698,6 +717,18 @@ CREATE UNIQUE INDEX service_set_name ON icinga_service_set (object_name, host_id
CREATE INDEX service_set_host ON icinga_service_set (host_id);
CREATE TABLE icinga_service_template_choice (
id serial,
object_name character varying(64) NOT NULL,
description text DEFAULT NULL,
min_required smallint NOT NULL DEFAULT 0,
max_allowed smallint NOT NULL DEFAULT 1,
PRIMARY KEY (id)
);
CREATE UNIQUE INDEX service_template_choice_object_name ON icinga_service_template_choice (object_name);
CREATE TABLE icinga_service (
id serial,
object_name character varying(255) NOT NULL,
@ -731,6 +762,7 @@ CREATE TABLE icinga_service (
apply_for character varying(255) DEFAULT NULL,
use_var_overrides enum_boolean DEFAULT NULL,
assign_filter text DEFAULT NULL,
template_choice_id int DEFAULT NULL,
PRIMARY KEY (id),
-- UNIQUE INDEX object_name (object_name, zone_id),
CONSTRAINT icinga_service_host
@ -767,6 +799,11 @@ CREATE TABLE icinga_service (
FOREIGN KEY (service_set_id)
REFERENCES icinga_service_set (id)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT icinga_service_template_choice
FOREIGN KEY (template_choice_id)
REFERENCES icinga_service_template_choice (id)
ON DELETE RESTRICT
ON UPDATE CASCADE
);
@ -775,6 +812,7 @@ CREATE INDEX service_timeperiod ON icinga_service (check_period_id);
CREATE INDEX service_check_command ON icinga_service (check_command_id);
CREATE INDEX service_event_command ON icinga_service (event_command_id);
CREATE INDEX service_command_endpoint ON icinga_service (command_endpoint_id);
CREATE INDEX service_template_choice ON icinga_service (template_choice_id);
CREATE TABLE icinga_service_inheritance (
@ -1795,4 +1833,4 @@ CREATE INDEX user_resolved_var_schecksum ON icinga_user_resolved_var (checksum);
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (131, NOW());
VALUES (133, NOW());