fix(v2): uq_delivery 索引显式升级迁移(AutoMigrate 不改同名索引)+ refund_id NOT NULL DEFAULT ''

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
This commit is contained in:
wangjia
2026-07-10 16:42:29 +08:00
parent ed5ec5c894
commit 00e032f577
5 changed files with 255 additions and 1 deletions
+5
View File
@@ -110,6 +110,11 @@ func autoMigrate(db *gorm.DB) {
); err != nil {
log.Fatalf("自动迁移失败: %v", err)
}
// AutoMigrate 只按名字判断索引是否存在,不会把老库同名的 2 列 uq_delivery
// 加宽到当前模型的 3 列(out_trade_no,event_type,refund_id);显式补一刀。
if err := model.UpgradeWebhookDeliveryIndex(db); err != nil {
log.Fatalf("升级 uq_delivery 索引失败: %v", err)
}
log.Println("AutoMigrate 完成")
}