From 4df7e8a23f31d91950b762c65d9db851e9bfd975 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Wed, 5 Sep 2018 17:09:45 +0200 Subject: [PATCH] schema/150: Add constraint from user to period --- schema/mysql-migrations/upgrade_150.sql | 17 +++++++++++++++++ schema/mysql.sql | 7 ++++++- schema/pgsql-migrations/upgrade_150.sql | 17 +++++++++++++++++ schema/pgsql.sql | 7 ++++++- 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 schema/mysql-migrations/upgrade_150.sql create mode 100644 schema/pgsql-migrations/upgrade_150.sql diff --git a/schema/mysql-migrations/upgrade_150.sql b/schema/mysql-migrations/upgrade_150.sql new file mode 100644 index 00000000..92a7a6d5 --- /dev/null +++ b/schema/mysql-migrations/upgrade_150.sql @@ -0,0 +1,17 @@ +UPDATE icinga_user u +SET period_id = NULL +WHERE NOT EXISTS ( + SELECT id FROM icinga_timeperiod + WHERE id = u.period_id +) AND u.period_id IS NOT NULL; + +ALTER TABLE icinga_user + ADD CONSTRAINT icinga_user_period + FOREIGN KEY period (period_id) + REFERENCES icinga_timeperiod (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (150, NOW()); diff --git a/schema/mysql.sql b/schema/mysql.sql index b3c76b81..b85b2a80 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -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()); diff --git a/schema/pgsql-migrations/upgrade_150.sql b/schema/pgsql-migrations/upgrade_150.sql new file mode 100644 index 00000000..ca838bb0 --- /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.sql b/schema/pgsql.sql index 18c0a900..5a1762f2 100644 --- a/schema/pgsql.sql +++ b/schema/pgsql.sql @@ -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());