fix: 补齐不完整的 v9 商品约束 (#144)

This commit is contained in:
chengma
2026-08-11 11:30:08 +08:00
parent edb835a9ed
commit 9671202f4e
4 changed files with 17 additions and 9 deletions
+5 -2
View File
@@ -547,13 +547,16 @@ func MigrateMySQL(db *sql.DB) error {
return CheckMySQLSchema(db)
}
// migrateMySQLV10 修复曾在 v8 开发中间状态记录过版本的数据库。
// v8 迁移本身逐项检查列和索引且回填只处理空值,因此可安全重放;
// migrateMySQLV10 修复曾在 v8/v9 开发中间状态记录过版本的数据库。
// 两版迁移均逐项检查结构,v8 回填只处理空值,因此可安全重放;
// 历史 v8/v9 版本记录保持不变,完整自检通过后再追加 v10。
func migrateMySQLV10(db *sql.DB) error {
if err := migrateMySQLV8(db); err != nil {
return fmt.Errorf("修复商品目录 SKU v8 结构失败: %w", err)
}
if err := migrateMySQLV9(db); err != nil {
return fmt.Errorf("修复蝦皮商品 v9 结构失败: %w", err)
}
return nil
}
@@ -468,7 +468,7 @@ func TestMySQLMigrate_V9形状错误不记版本(t *testing.T) {
}
}
func TestMySQLMigrate_已记录V9但缺少SKU来源字段时由V10修复(t *testing.T) {
func TestMySQLMigrate_已记录V9但缺少V8V9结构时由V10修复(t *testing.T) {
db := openMySQLMigrationTestDB(t)
defer db.Close()
cleanMySQLTestSchema(t, db)
@@ -486,6 +486,9 @@ func TestMySQLMigrate_已记录V9但缺少SKU来源字段时由V10修复(t *test
if err := migrateMySQLV9(db); err != nil {
t.Fatal(err)
}
// 同时模拟 v9 已记录但两个图片/店铺人工标记约束尚未建立。
mustExec(t, db, `ALTER TABLE shopee_products DROP CHECK chk_shopee_products_image_manual`)
mustExec(t, db, `ALTER TABLE shopee_products DROP CHECK chk_shopee_products_shop_manual`)
mustExec(t, db, `INSERT INTO schema_migrations(version,applied_at) VALUES
(8,'2026-08-11T00:00:00Z'),(9,'2026-08-11T00:00:00Z')`)