From f66ab8dae2f3d0418759f81a3a64dc9517a62449 Mon Sep 17 00:00:00 2001
From: Daniel Baumann <daniel.baumann@progress-linux.org>
Date: Sun, 14 Apr 2024 15:17:31 +0200
Subject: Adding upstream version 1.10.2.

Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
---
 schema/mysql-migrations/upgrade_123.sql | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 schema/mysql-migrations/upgrade_123.sql

(limited to 'schema/mysql-migrations/upgrade_123.sql')

diff --git a/schema/mysql-migrations/upgrade_123.sql b/schema/mysql-migrations/upgrade_123.sql
new file mode 100644
index 0000000..024ed72
--- /dev/null
+++ b/schema/mysql-migrations/upgrade_123.sql
@@ -0,0 +1,30 @@
+-- cleanup dangling service_set before we add foreign key
+DELETE ss FROM icinga_service_set AS ss
+  LEFT JOIN icinga_host AS h ON h.id = ss.host_id
+  WHERE ss.object_type = 'object'
+        AND ss.host_id IS NOT NULL
+        AND h.id IS NULL;
+
+-- cleanup dangling services to service_set
+DELETE s FROM icinga_service AS s
+  LEFT JOIN icinga_service_set AS ss ON ss.id = s.service_set_id
+  WHERE s.object_type IN ('object', 'apply')
+        AND s.service_set_id IS NOT NULL
+        AND ss.id IS NULL;
+
+
+ALTER TABLE icinga_service_set
+  ADD FOREIGN KEY icinga_service_set_host (host_id)
+  REFERENCES icinga_host (id)
+  ON DELETE RESTRICT
+  ON UPDATE CASCADE;
+
+ALTER TABLE icinga_service
+  ADD FOREIGN KEY icinga_service_service_set (service_set_id)
+  REFERENCES icinga_service_set (id)
+  ON DELETE RESTRICT
+  ON UPDATE CASCADE;
+
+INSERT INTO director_schema_migration
+(schema_version, migration_time)
+VALUES (123, NOW());
-- 
cgit v1.2.3

