[icinga-checkins] icinga.org: icingaweb2-module-director/master: schema/mysql: delete services on host deletion

git at icinga.org git at icinga.org
Mon Feb 29 20:39:04 CET 2016


Module: icingaweb2-module-director
Branch: master
Commit: 83d2047a23fe56a57bdde1d3573a793ab3339e8f
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=83d2047a23fe56a57bdde1d3573a793ab3339e8f

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon Feb 29 15:41:55 2016 +0100

schema/mysql: delete services on host deletion

We would otherwise create host-less service-aliens

---

 schema/mysql-migrations/upgrade_74.sql |   14 ++++++++++++++
 schema/mysql.sql                       |    6 +++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/schema/mysql-migrations/upgrade_74.sql b/schema/mysql-migrations/upgrade_74.sql
new file mode 100644
index 0000000..382f937
--- /dev/null
+++ b/schema/mysql-migrations/upgrade_74.sql
@@ -0,0 +1,14 @@
+
+ALTER TABLE icinga_service
+  DROP FOREIGN KEY icinga_host;
+
+ALTER TABLE icinga_service
+  ADD CONSTRAINT icinga_service_host
+    FOREIGN KEY host (host_id)
+    REFERENCES icinga_host (id)
+    ON DELETE CASCADE
+    ON UPDATE CASCADE;
+
+INSERT INTO director_schema_migration
+  SET migration_time = NOW(),
+      schema_version = 74;
diff --git a/schema/mysql.sql b/schema/mysql.sql
index b08a398..e0f4126 100644
--- a/schema/mysql.sql
+++ b/schema/mysql.sql
@@ -525,10 +525,10 @@ CREATE TABLE icinga_service (
   PRIMARY KEY (id),
   -- UNIQUE INDEX object_name (object_name, zone_id),
   UNIQUE KEY object_key (object_name, host_id),
-  CONSTRAINT icinga_host
+  CONSTRAINT icinga_service_host
     FOREIGN KEY host (host_id)
     REFERENCES icinga_host (id)
-    ON DELETE SET NULL
+    ON DELETE CASCADE
     ON UPDATE CASCADE,
   CONSTRAINT icinga_service_zone
     FOREIGN KEY zone (zone_id)
@@ -1112,4 +1112,4 @@ CREATE TABLE sync_run (
 
 INSERT INTO director_schema_migration
   SET migration_time = NOW(),
-      schema_version = 73;
+      schema_version = 74;



More information about the icinga-checkins mailing list