diff --git a/models/notifications.go b/models/notifications.go index b663c740c..3a276fa40 100644 --- a/models/notifications.go +++ b/models/notifications.go @@ -1,6 +1,7 @@ package models import ( + "fmt" "time" "github.com/flanksource/duty/types" @@ -111,12 +112,24 @@ func (t *NotificationSendHistory) End() *NotificationSendHistory { return t } +type NotificationSilenceResource struct { + ConfigID *string `json:"config_id,omitempty"` + CanaryID *string `json:"canary_id,omitempty"` + ComponentID *string `json:"component_id,omitempty"` + 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)) +} + type NotificationSilence struct { + NotificationSilenceResource `json:",inline" yaml:",inline"` + ID uuid.UUID `json:"id"` Namespace string `json:"namespace"` From time.Time `json:"from"` Until time.Time `json:"until"` - Matcher *string `json:"matcher,omitempty"` Source string `json:"source"` CreatedBy *uuid.UUID `json:"created_by,omitempty"` CreatedAt time.Time `json:"created_at" time_format:"postgres_timestamp" gorm:"<-:false"` diff --git a/query/getters.go b/query/getters.go index 25a87e318..c608460ae 100644 --- a/query/getters.go +++ b/query/getters.go @@ -173,22 +173,3 @@ func FindTeam(ctx context.Context, identifier string, opts ...GetterOption) (*mo return team, nil } - -func GetAllNotificationSilences(ctx context.Context) ([]models.NotificationSilence, error) { - var silences []models.NotificationSilence - - cacheKey := "allNotificationSilences" - if value, ok := getterCache.Get(cacheKey); ok { - if cache, ok := value.([]models.NotificationSilence); ok { - return cache, nil - } - } - - err := ctx.DB().Where("deleted_at is NULL ").Find(&silences).Error - if err != nil { - return nil, err - } - - getterCache.SetDefault(cacheKey, silences) - return silences, err -} diff --git a/schema/notifications.hcl b/schema/notifications.hcl index 5203c6d5b..1ca1a7697 100644 --- a/schema/notifications.hcl +++ b/schema/notifications.hcl @@ -178,20 +178,32 @@ table "notification_silences" { type = text } column "from" { - null = false - type = timestamptz + null = false + type = timestamptz } column "until" { - null = false - type = timestamptz + null = false + type = timestamptz } - column "matcher" { + column "config_id" { null = true - type = text + type = uuid + } + column "check_id" { + null = true + type = uuid + } + column "canary_id" { + null = true + type = uuid + } + column "component_id" { + null = true + type = uuid } column "source" { - null = true - type = enum.source + null = true + type = enum.source } column "created_by" { null = true @@ -202,7 +214,7 @@ table "notification_silences" { type = timestamptz default = sql("now()") } - column "updated_at" { + column "updated_at" { null = false type = timestamptz default = sql("now()")