Skip to content

Commit

Permalink
feat: new notification send history table
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Sep 15, 2023
1 parent 130a36b commit 6ca8ada
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
31 changes: 31 additions & 0 deletions models/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,34 @@ func (n *Notification) HasRecipients() bool {
func (n Notification) AsMap(removeFields ...string) map[string]any {
return asMap(n, removeFields...)
}

type NotificationSendHistory struct {
ID uuid.UUID `json:"id,omitempty" gorm:"default:generate_ulid()"`
NotificationID string `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"`

timeStart time.Time
}

func (n NotificationSendHistory) AsMap(removeFields ...string) map[string]any {
return asMap(n, removeFields...)
}

func (t *NotificationSendHistory) TableName() string {
return "notification_send_history"
}

func NewNotificationSendHistory(notificationID string) *NotificationSendHistory {
return &NotificationSendHistory{
NotificationID: notificationID,
timeStart: time.Now(),
}
}

func (t *NotificationSendHistory) End() *NotificationSendHistory {
t.DurationMs = time.Since(t.timeStart).Milliseconds()
return t
}
39 changes: 39 additions & 0 deletions schema/notifications.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,43 @@ table "notifications" {
on_update = NO_ACTION
on_delete = CASCADE
}
}

table "notification_send_history" {
schema = schema.public
column "id" {
null = false
type = uuid
default = sql("generate_ulid()")
}
column "notification_id" {
null = false
type = uuid
}
column "body" {
null = false
type = text
}
column "error" {
null = true
type = text
}
column "duration_millis" {
null = true
type = integer
}
column "created_at" {
null = false
type = timestamptz
default = sql("now()")
}
primary_key {
columns = [column.id]
}
foreign_key "notification_id_fkey" {
columns = [column.notification_id]
ref_columns = [table.notifications.column.id]
on_update = NO_ACTION
on_delete = NO_ACTION
}
}

0 comments on commit 6ca8ada

Please sign in to comment.