check / check (push) Waiting to run
Every reference from a model to the record it belongs to is now json:"-", so the webhook and target models (and the other parent and child pairs in internal/database) can no longer marshal each other in a loop. Preloading maps associations without reading json tags, so it still fills these references. One test preloads a webhook with its targets and entrypoints and a target with its webhook, checks the references are filled, and checks the JSON leaves them out; another builds each other model with its parent set and checks the parent's id is absent from its JSON. 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:"-"`
|
|
}
|