[icinga-checkins] icinga.org: icingaweb2-module-director/feature/nested-apply-rules-12033: schema/mysql: simplify apply rules

git at icinga.org git at icinga.org
Fri Oct 21 10:08:08 CEST 2016


Module: icingaweb2-module-director
Branch: feature/nested-apply-rules-12033
Commit: be571c6033e894a6ca4c1ae3014650187340631f
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=be571c6033e894a6ca4c1ae3014650187340631f

Author: Thomas Gelf <thomas at gelf.net>
Date:   Fri Oct 21 06:50:05 2016 +0000

schema/mysql: simplify apply rules

---

 schema/mysql-migrations/upgrade_118.sql |   47 +++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/schema/mysql-migrations/upgrade_118.sql b/schema/mysql-migrations/upgrade_118.sql
new file mode 100644
index 0000000..85ad7b5
--- /dev/null
+++ b/schema/mysql-migrations/upgrade_118.sql
@@ -0,0 +1,47 @@
+ALTER TABLE icinga_service ADD COLUMN assign_filter TEXT;
+
+UPDATE icinga_service s JOIN (
+
+    SELECT 
+        service_id,
+          CASE WHEN COUNT(*) = 0 THEN NULL
+               WHEN COUNT(*) = 1 THEN sa.filter_string
+               ELSE GROUP_CONCAT(sa.filter_string SEPARATOR '&') END AS filter_string
+    FROM (
+        SELECT
+          sa_not.service_id,
+          CASE WHEN COUNT(*) = 0 THEN NULL
+               WHEN COUNT(*) = 1 THEN sa_not.filter_string
+               ELSE '(' || GROUP_CONCAT(sa_not.filter_string SEPARATOR '&') || ')' END AS filter_string
+          FROM ( SELECT
+            sa.service_id,
+            '!' || sa.filter_string AS filter_string
+            FROM icinga_service_assignment sa
+            WHERE assign_type = 'ignore'
+          ) sa_not
+          GROUP BY service_id
+
+        UNION ALL
+
+        SELECT
+          sa_yes.service_id,
+          CASE WHEN COUNT(*) = 0 THEN NULL
+               WHEN COUNT(*) = 1 THEN sa_yes.filter_string
+               ELSE '(' || GROUP_CONCAT(sa_yes.filter_string SEPARATOR '|') || ')' END AS filter_string
+          FROM ( SELECT
+            sa.service_id,
+            sa.filter_string AS filter_string
+            FROM icinga_service_assignment sa
+            WHERE assign_type = 'assign'
+          ) sa_yes
+          GROUP BY service_id
+
+    ) sa GROUP BY service_id
+
+) flat_assign ON s.id = flat_assign.service_id SET s.assign_filter = flat_assign.filter_string;
+
+DROP TABLE icigna_service_assignment;
+
+INSERT INTO director_schema_migration
+  (schema_version, migration_time)
+  VALUES (118, NOW());



More information about the icinga-checkins mailing list