Skip to content

Commit

Permalink
feat: add more columns to notification send history
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Sep 18, 2023
1 parent 6ca8ada commit 1743f7b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
13 changes: 11 additions & 2 deletions models/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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(),
Expand Down
20 changes: 20 additions & 0 deletions schema/notifications.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}

0 comments on commit 1743f7b

Please sign in to comment.