schema/150: Add constraint from user to period

This commit is contained in:
Markus Frosch 2018-09-05 17:09:45 +02:00
parent fbef8866ce
commit 4df7e8a23f
4 changed files with 46 additions and 2 deletions

View File

@ -0,0 +1,17 @@
UPDATE icinga_user u
SET period_id = NULL
WHERE NOT EXISTS (
SELECT id FROM icinga_timeperiod
WHERE id = u.period_id
) AND u.period_id IS NOT NULL;
ALTER TABLE icinga_user
ADD CONSTRAINT icinga_user_period
FOREIGN KEY period (period_id)
REFERENCES icinga_timeperiod (id)
ON DELETE RESTRICT
ON UPDATE CASCADE;
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (150, NOW());

View File

@ -940,6 +940,11 @@ CREATE TABLE icinga_user (
FOREIGN KEY zone (zone_id)
REFERENCES icinga_zone (id)
ON DELETE RESTRICT
ON UPDATE CASCADE,
CONSTRAINT icinga_user_period
FOREIGN KEY period (period_id)
REFERENCES icinga_timeperiod (id)
ON DELETE RESTRICT
ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -1692,4 +1697,4 @@ CREATE TABLE icinga_dependency_states_set (
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (149, NOW());
VALUES (150, NOW());

View File

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

View File

@ -1157,6 +1157,11 @@ CREATE TABLE icinga_user (
FOREIGN KEY (zone_id)
REFERENCES icinga_zone (id)
ON DELETE RESTRICT
ON UPDATE CASCADE,
CONSTRAINT icinga_user_period
FOREIGN KEY (period_id)
REFERENCES icinga_timeperiod (id)
ON DELETE RESTRICT
ON UPDATE CASCADE
);
@ -1988,4 +1993,4 @@ COMMENT ON COLUMN icinga_dependency_states_set.merge_behaviour IS 'override: = [
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (149, NOW());
VALUES (150, NOW());