From 046507438bc1f6c434676c6bb1329397f385f55c Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Fri, 13 Sep 2024 18:56:35 +0545 Subject: [PATCH] feat: notification name & namespace --- models/notifications.go | 4 +++- schema/notifications.hcl | 14 ++++++++++++++ views/015_job_history.sql | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/models/notifications.go b/models/notifications.go index 3532dbb5..8596b257 100644 --- a/models/notifications.go +++ b/models/notifications.go @@ -12,6 +12,8 @@ import ( // Notification represents the notifications table type Notification struct { ID uuid.UUID `json:"id"` + Name string `json:"name"` + Namespace string `json:"namespace,omitempty"` Events pq.StringArray `json:"events" gorm:"type:[]text"` Title string `json:"title,omitempty"` Template string `json:"template,omitempty"` @@ -20,7 +22,7 @@ type Notification struct { TeamID *uuid.UUID `json:"team_id,omitempty"` Properties types.JSONStringMap `json:"properties,omitempty"` Source string `json:"source"` - RepeatInterval string `json:"repeat_interval"` + RepeatInterval string `json:"repeat_interval,omitempty"` GroupBy pq.StringArray `json:"group_by" gorm:"type:[]text"` CustomServices types.JSON `json:"custom_services,omitempty" gorm:"column:custom_services"` CreatedBy *uuid.UUID `json:"created_by,omitempty"` diff --git a/schema/notifications.hcl b/schema/notifications.hcl index c21eb690..fb3021bc 100644 --- a/schema/notifications.hcl +++ b/schema/notifications.hcl @@ -5,6 +5,15 @@ table "notifications" { type = uuid default = sql("generate_ulid()") } + column "name" { + null = false + type = text + default = sql("generate_ulid()") # temporary default value to make the migration possible. we can remove this later. + } + column "namespace" { + null = true + type = text + } column "events" { null = false type = sql("text[]") @@ -99,6 +108,11 @@ table "notifications" { on_update = NO_ACTION on_delete = CASCADE } + index "notifications_name_namespace_key" { + unique = true + columns = [column.name, column.namespace] + where = "deleted_at IS NULL" + } } table "notification_send_history" { diff --git a/views/015_job_history.sql b/views/015_job_history.sql index 72f6b8a3..cd45b568 100644 --- a/views/015_job_history.sql +++ b/views/015_job_history.sql @@ -214,6 +214,8 @@ WITH notification_send_summary AS ( ) SELECT notifications.id, + notifications.name, + notifications.namespace, notifications.title, notifications.events, notifications.filter,