From af843d76e1aff287af3d07dd5890f814991e662a Mon Sep 17 00:00:00 2001
From: Gibheer <gibheer+git@zero-knowledge.org>
Date: Tue, 11 Dec 2018 20:21:14 +0100
Subject: moncheck - move notifications to dedicated table

It would be nice to support multiple notification mechanisms with a way
to disable all or part of them. So for now, this is bound to the check
but may change again in the future.

Apart from that, all notifications get written to the notification
table, so that the notifiers can do their job and ACK their own
notifications.
---
 schema/20181210.sql | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

(limited to 'schema/20181210.sql')

diff --git a/schema/20181210.sql b/schema/20181210.sql
index e6be91d..c807863 100644
--- a/schema/20181210.sql
+++ b/schema/20181210.sql
@@ -15,7 +15,8 @@ create table public.mapping_level(
 
 CREATE TABLE public.notifier (
     id serial NOT NULL primary key,
-    name text NOT NULL
+    name text NOT NULL,
+    settings jsonb not null '{}'::jsonb,
 );
 
 CREATE TABLE public.groups (
@@ -57,8 +58,6 @@ CREATE TABLE public.checks (
     updated timestamp with time zone DEFAULT now() NOT NULL,
     last_refresh timestamp with time zone,
     enabled boolean DEFAULT true NOT NULL,
-    notifier_id integer NOT NULL,
-    notify boolean DEFAULT true NOT NULL,
     message text NOT NULL,
     unique(node_id, command_id, options)
 );
@@ -71,20 +70,27 @@ CREATE TABLE public.active_checks (
     states integer[] DEFAULT ARRAY[0] NOT NULL,
     intval interval NOT NULL,
     enabled boolean NOT NULL,
-    notify boolean NOT NULL,
     notice text,
     msg text NOT NULL,
     acknowledged boolean DEFAULT false NOT NULL
 );
 
+create table checks_notify(
+  check_id bigint not null references checks(id),
+  notifier_id bigint not null references notifier(id),
+  enabled bool not null default true,
+  unique(check_id, notifier_id)
+);
+
 CREATE TABLE public.notifications (
     id bigserial NOT NULL primary key,
     check_id bigint NOT NULL references checks(id) on delete cascade,
+    mapping_id integer not null references mappings(id),
+    notifier_id integer not null references notifier(id),
     states integer[] NOT NULL,
     output text,
     inserted timestamp with time zone DEFAULT now() NOT NULL,
     sent timestamp with time zone,
-    mapping_id integer not null references mappings(id),
 );
 
 
-- 
cgit v1.2.3-70-g09d2

