check / check (push) Successful in 3m32s
Brings `prod`, which upaas deploys, up to `main` at `9cf9cdd`, the merge of #321. `prod` was cut from `main` at `251cb3d` (1.0.0b1). What it deploys is everything listed in #321. For running it: - With `WEBHOOKER_ENVIRONMENT` unset, the instance runs as `prod` and sends no `Access-Control-Allow-Origin: *`. - Each event database gains its new indexes the first time it is opened after the upgrade. - `webhooker_delivery_retries_total` no longer counts a circuit breaker holding back a delivery that is already `retrying`. Not in this PR yet: #340, in which the container sets its own data directory owner and mode before start. It is in progress on `next`. Once it reaches `main`, this PR carries it, because the PR follows `main`. Model: opus-5-5 Co-authored-by: Jeffrey Paul <1+sneak@noreply.example.org> Reviewed-on: #343
47 lines
1.8 KiB
Go
47 lines
1.8 KiB
Go
package database
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Event represents a captured webhook event
|
|
//
|
|
//nolint:lll // a struct tag cannot wrap
|
|
type Event struct {
|
|
BaseModel
|
|
|
|
// CreatedAt and DeletedAt repeat the BaseModel fields only to index
|
|
// them for retention, which finds events by age. Its lookups carry
|
|
// GORM's "deleted_at IS NULL" (see DeliveryResult) and compare
|
|
// created_at with <, so their index has deleted_at first: SQLite
|
|
// narrows by a < only on the last column it uses. Its final delete
|
|
// has no deleted_at condition and uses the index on created_at
|
|
// alone. The other tables keep the unindexed BaseModel created_at.
|
|
CreatedAt time.Time `gorm:"index;index:idx_events_deleted_at_created_at,priority:2" json:"createdAt"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index:idx_events_deleted_at_created_at,priority:1" json:"deletedAt,omitzero"`
|
|
|
|
WebhookID string `gorm:"type:uuid;not null" json:"webhookId"`
|
|
EntrypointID string `gorm:"type:uuid;not null" json:"entrypointId"`
|
|
|
|
// Request data
|
|
Method string `gorm:"not null" json:"method"`
|
|
Headers string `gorm:"type:text" json:"headers"` // JSON
|
|
Body string `gorm:"type:text" json:"body"`
|
|
ContentType string `json:"contentType"`
|
|
|
|
// ResubmittedFromID names the event this one was copied from by
|
|
// an operator resubmit. It is nil for an event that arrived on
|
|
// the receiver, which is every event created before the column
|
|
// existed. It is not a foreign key: the source event can be
|
|
// reaped by retention while its copies remain, and the id is
|
|
// kept as the record of where the copy came from either way.
|
|
ResubmittedFromID *string `gorm:"type:uuid;index" json:"resubmittedFromId,omitempty"`
|
|
|
|
// Relations
|
|
Webhook Webhook `json:"webhook,omitzero"`
|
|
Entrypoint Entrypoint `json:"entrypoint,omitzero"`
|
|
Deliveries []Delivery `json:"deliveries,omitempty"`
|
|
}
|