check / check (push) Waiting to run
Every reference from a model to the record it belongs to (a target's or entrypoint's webhook, a webhook's or API key's user, an event's webhook and entrypoint, a delivery's event and target, a delivery result's delivery) is now tagged json:"-", so a preloaded model can be marshalled without the encoder recursing between parent and child. References to child records stay. Tests marshal each of the nine references set, preloaded where it matters, and check the parent's id is absent, so deleting or restoring any one tag fails a test; preloading still fills each reference. Model: opus-5-5
30 lines
1.3 KiB
Go
30 lines
1.3 KiB
Go
package database
|
|
|
|
import "gorm.io/gorm"
|
|
|
|
// DeliveryResult represents the result of a delivery attempt
|
|
//
|
|
//nolint:lll // a struct tag cannot wrap
|
|
type DeliveryResult struct {
|
|
BaseModel
|
|
|
|
// DeliveryID and DeletedAt make up one index, in that order.
|
|
// DeletedAt repeats the BaseModel field only to join it: GORM adds
|
|
// "deleted_at IS NULL" to almost every query, and where a column is
|
|
// matched against several values SQLite otherwise reads through the
|
|
// deleted_at index, which every live row matches.
|
|
DeliveryID string `gorm:"type:uuid;not null;index:idx_delivery_results_delivery_id,priority:1" json:"deliveryId"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index:idx_delivery_results_delivery_id,priority:2" json:"deletedAt,omitzero"`
|
|
|
|
AttemptNum int `gorm:"not null" json:"attemptNum"`
|
|
Success bool `json:"success"`
|
|
StatusCode int `json:"statusCode,omitempty"`
|
|
ResponseBody string `gorm:"type:text" json:"responseBody,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
Duration int64 `json:"durationMs"` // Duration in milliseconds
|
|
|
|
// Relations. No model marshals the record it belongs to:
|
|
// Delivery.DeliveryResults leads back here, and the JSON could loop.
|
|
Delivery Delivery `json:"-"`
|
|
}
|