From 0bc662735aa6c16edbd659f1b691038e386644f8 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Fri, 26 Aug 2022 19:10:35 +0100 Subject: [PATCH] feat(DB): changed alerts behaviour to support UI --- api/chalicelib/core/alerts.py | 7 ++++--- api/schemas.py | 5 ----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/api/chalicelib/core/alerts.py b/api/chalicelib/core/alerts.py index f851751ba..da6211687 100644 --- a/api/chalicelib/core/alerts.py +++ b/api/chalicelib/core/alerts.py @@ -52,8 +52,8 @@ def create(project_id, data: schemas.AlertSchema): with pg_client.PostgresClient() as cur: cur.execute( cur.mogrify("""\ - INSERT INTO public.alerts(project_id, name, description, detection_method, query, options, series_id) - VALUES (%(project_id)s, %(name)s, %(description)s, %(detection_method)s, %(query)s, %(options)s::jsonb, %(series_id)s) + INSERT INTO public.alerts(project_id, name, description, detection_method, query, options, series_id, change) + VALUES (%(project_id)s, %(name)s, %(description)s, %(detection_method)s, %(query)s, %(options)s::jsonb, %(series_id)s, %(change)s) RETURNING *;""", {"project_id": project_id, **data}) ) @@ -75,7 +75,8 @@ def update(id, data: schemas.AlertSchema): detection_method = %(detection_method)s, query = %(query)s, options = %(options)s, - series_id = %(series_id)s + series_id = %(series_id)s, + change = %(change)s WHERE alert_id =%(id)s AND deleted_at ISNULL RETURNING *;""", {"id": id, **data}) diff --git a/api/schemas.py b/api/schemas.py index d215459f9..42787c9e5 100644 --- a/api/schemas.py +++ b/api/schemas.py @@ -356,11 +356,6 @@ class AlertSchema(BaseModel): def alert_validator(cls, values): if values.get("query") is not None and values["query"].left == AlertColumn.custom: assert values.get("series_id") is not None, "series_id should not be null for CUSTOM alert" - if values.get("detectionMethod") is not None \ - and values["detectionMethod"] == AlertDetectionMethod.change \ - and values.get("options") is not None: - assert values["options"].change is not None, \ - "options.change should not be null for detection method 'change'" return values class Config: