check / check (push) Successful in 3m4s
The per-webhook event databases had no secondary indexes, so startup recovery, the retry and pending sweeps, the queue-depth sampler, the event log and retention each read whole tables. Indexes declared in the GORM model tags now serve them, and AutoMigrate adds them to new and existing databases alike. Each index also covers deleted_at: GORM adds deleted_at IS NULL to these queries, and SQLite, with no table statistics, otherwise prefers the existing deleted_at index. A test checks SQLite's plan for each statement as GORM builds it. Rule suppressed: lll on the three event-tier model structs, whose struct tags cannot wrap. The resubmitted_from_id scan is left to #325. Model: opus-4-8 (implementation); opus-5-5 (rework)
29 lines
1.2 KiB
Go
29 lines
1.2 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
|
|
Delivery Delivery `json:"delivery,omitzero"`
|
|
}
|