fix(force-recharge): 补充强充配置缺失的接口和数据库字段
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m19s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m19s
- 订单管理:增加 payment_method 字段支持,合并代购订单逻辑 - 套餐系列分配:增加强充配置字段(enable_force_recharge、force_recharge_amount、force_recharge_trigger_type) - 数据库迁移:添加 force_recharge_trigger_type 字段 - 测试:更新订单服务测试用例 - OpenSpec:归档 fix-force-recharge-missing-interfaces 变更
This commit is contained in:
@@ -91,16 +91,23 @@ func GetTestDB(t *testing.T) *gorm.DB {
|
||||
&model.AssetAllocationRecord{},
|
||||
&model.CommissionWithdrawalRequest{},
|
||||
&model.CommissionWithdrawalSetting{},
|
||||
&model.Order{},
|
||||
&model.OrderItem{},
|
||||
&model.PackageUsage{},
|
||||
&model.Wallet{},
|
||||
)
|
||||
if err != nil {
|
||||
errMsg := err.Error()
|
||||
if strings.Contains(errMsg, "does not exist") && strings.Contains(errMsg, "constraint") {
|
||||
// 忽略约束不存在的错误,这是由于约束名变更导致的
|
||||
if strings.Contains(errMsg, "does not exist") && (strings.Contains(errMsg, "constraint") || strings.Contains(errMsg, "column")) {
|
||||
// 忽略约束和列不存在的错误,这是由于约束名变更或迁移未应用导致的
|
||||
} else {
|
||||
testDBInitErr = fmt.Errorf("数据库迁移失败: %w", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 确保所有必要的列都存在(处理迁移未应用的情况)
|
||||
ensureTestDBColumns(testDB)
|
||||
})
|
||||
|
||||
if testDBInitErr != nil {
|
||||
@@ -170,6 +177,9 @@ func NewTestTransaction(t *testing.T) *gorm.DB {
|
||||
t.Helper()
|
||||
|
||||
db := GetTestDB(t)
|
||||
// 确保所有必要的列都存在
|
||||
ensureTestDBColumns(db)
|
||||
|
||||
tx := db.Begin()
|
||||
if tx.Error != nil {
|
||||
t.Fatalf("开启测试事务失败: %v", tx.Error)
|
||||
@@ -245,3 +255,12 @@ func cleanKeys(ctx context.Context, rdb *redis.Client, prefix string) {
|
||||
rdb.Del(ctx, keys...)
|
||||
}
|
||||
}
|
||||
|
||||
// ensureTestDBColumns 确保测试数据库中所有必要的列都存在
|
||||
// 处理迁移未应用导致的列缺失问题
|
||||
func ensureTestDBColumns(db *gorm.DB) {
|
||||
// 添加 force_recharge_trigger_type 列到 tb_shop_series_allocation 表
|
||||
if !db.Migrator().HasColumn("tb_shop_series_allocation", "force_recharge_trigger_type") {
|
||||
db.Exec("ALTER TABLE tb_shop_series_allocation ADD COLUMN force_recharge_trigger_type int DEFAULT 2")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user