fix(db): 修复 db migration 报错过多可能卡住的隐患

This commit is contained in:
Xyfacai
2025-07-20 10:11:35 +08:00
parent a3059597fb
commit 986558fea7

View File

@@ -260,7 +260,6 @@ func migrateDB() error {
func migrateDBFast() error { func migrateDBFast() error {
var wg sync.WaitGroup var wg sync.WaitGroup
errChan := make(chan error, 12) // Buffer size matches number of migrations
migrations := []struct { migrations := []struct {
model interface{} model interface{}
@@ -279,6 +278,8 @@ func migrateDBFast() error {
{&Task{}, "Task"}, {&Task{}, "Task"},
{&Setup{}, "Setup"}, {&Setup{}, "Setup"},
} }
// 动态计算migration数量确保errChan缓冲区足够大
errChan := make(chan error, len(migrations))
for _, m := range migrations { for _, m := range migrations {
wg.Add(1) wg.Add(1)