00e032f577
AutoMigrate 只按名字判断索引是否存在,P2 时代库升级后同名 uq_delivery 仍停在 2 列,store.EnqueueDelivery 的 3 列 ON CONFLICT 每次调用(含普通 payment webhook)都报 "ON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint"(reviewer 在 glebarez/sqlite 上实测复现)。新增 model.UpgradeWebhookDeliveryIndex,AutoMigrate 后显式检测/加宽索引 + backfill refund_id,main.go 与 OpenTestDB 两处调用点接入;RefundID 补 not null;default:'' 补上 NULL/"" 语义缺口。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nMthbVEmQquxBRKb9Fj8u
16 lines
946 B
Go
16 lines
946 B
Go
package model
|
|
|
|
// WebhookDelivery 是 pay→业务方 webhook 的 outbox(v2)。unique(out_trade_no,event_type,refund_id)
|
|
// 保证同一订单同一事件(同一退款单)只入队一次(幂等);后台 Notifier 扫 Delivered=false 重试兜底。
|
|
type WebhookDelivery struct {
|
|
Base
|
|
OutTradeNo string `gorm:"size:64;not null;uniqueIndex:uq_delivery" json:"out_trade_no"`
|
|
EventType string `gorm:"size:32;not null;uniqueIndex:uq_delivery" json:"event_type"`
|
|
RefundID string `gorm:"size:64;not null;default:'';uniqueIndex:uq_delivery" json:"refund_id,omitempty"` // 退款事件的幂等维度;payment 事件为空
|
|
BizSystem string `gorm:"index;size:32" json:"biz_system"`
|
|
Payload string `gorm:"type:text" json:"payload"` // 已序列化的领域 JSON(含 event_type)
|
|
Delivered bool `gorm:"index;default:false" json:"delivered"`
|
|
Attempts int `json:"attempts"`
|
|
LastError string `gorm:"size:255" json:"last_error,omitempty"`
|
|
}
|