From 3b34799667c68da5c0bc279de6de45a3a99efd1e Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Wed, 11 Sep 2024 10:06:33 +0545 Subject: [PATCH] fix: set default value for notification silence ID for gorm --- models/notifications.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/models/notifications.go b/models/notifications.go index 4ab775ca..9b307671 100644 --- a/models/notifications.go +++ b/models/notifications.go @@ -1,7 +1,6 @@ package models import ( - "fmt" "time" "github.com/flanksource/duty/types" @@ -119,15 +118,18 @@ type NotificationSilenceResource struct { CheckID *string `json:"check_id,omitempty"` } -func (t NotificationSilenceResource) Key() string { - return fmt.Sprintf("%s:%s:%s:%s", lo.FromPtr(t.ConfigID), lo.FromPtr(t.CanaryID), lo.FromPtr(t.ComponentID), lo.FromPtr(t.CheckID)) +func (t NotificationSilenceResource) Empty() bool { + return lo.FromPtr(t.ConfigID) == "" && + lo.FromPtr(t.CanaryID) == "" && + lo.FromPtr(t.ComponentID) == "" && + lo.FromPtr(t.CheckID) == "" } type NotificationSilence struct { NotificationSilenceResource `json:",inline" yaml:",inline"` - ID uuid.UUID `json:"id"` - Namespace string `json:"namespace"` + ID uuid.UUID `json:"id" gorm:"default:generate_ulid()"` + Namespace string `json:"namespace,omitempty"` From time.Time `json:"from"` Until time.Time `json:"until"` Source string `json:"source"`