From 1743f7b0faf9f37d96d11aba05a9dd5cf4e46a35 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Mon, 18 Sep 2023 13:18:07 +0545 Subject: [PATCH] feat: add more columns to notification send history --- models/notifications.go | 13 +++++++++++-- schema/notifications.hcl | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/models/notifications.go b/models/notifications.go index 7e5cc261..d24143b2 100644 --- a/models/notifications.go +++ b/models/notifications.go @@ -35,12 +35,21 @@ func (n Notification) AsMap(removeFields ...string) map[string]any { type NotificationSendHistory struct { ID uuid.UUID `json:"id,omitempty" gorm:"default:generate_ulid()"` - NotificationID string `json:"notification_id"` + NotificationID uuid.UUID `json:"notification_id"` Body string `json:"body,omitempty"` Error *string `json:"error,omitempty"` DurationMs int64 `json:"duration_ms,omitempty" gorm:"column:duration_millis"` CreatedAt time.Time `json:"created_at" time_format:"postgres_timestamp"` + // Name of the original event that caused this notification + SourceEvent string `json:"source_event"` + + // ID of the resource this notification is for + ResourceID uuid.UUID `json:"resource_id"` + + // ID of the person this notification is for. + PersonID *uuid.UUID `json:"person_id"` + timeStart time.Time } @@ -52,7 +61,7 @@ func (t *NotificationSendHistory) TableName() string { return "notification_send_history" } -func NewNotificationSendHistory(notificationID string) *NotificationSendHistory { +func NewNotificationSendHistory(notificationID uuid.UUID) *NotificationSendHistory { return &NotificationSendHistory{ NotificationID: notificationID, timeStart: time.Now(), diff --git a/schema/notifications.hcl b/schema/notifications.hcl index 073ac9de..abac0075 100644 --- a/schema/notifications.hcl +++ b/schema/notifications.hcl @@ -98,6 +98,20 @@ table "notification_send_history" { null = false type = text } + column "source_event" { + null = false + type = text + comment = "The event that caused this notification" + } + column "resource_id" { + null = false + type = uuid + comment = "The resource this notification is for" + } + column "person_id" { + null = true + type = uuid + } column "error" { null = true type = text @@ -120,4 +134,10 @@ table "notification_send_history" { on_update = NO_ACTION on_delete = NO_ACTION } + foreign_key "notification_recipient_person_id_fkey" { + columns = [column.person_id] + ref_columns = [table.people.column.id] + on_update = NO_ACTION + on_delete = NO_ACTION + } } \ No newline at end of file