fix: Fix the problem of initializing planned task groups (#9870)

This commit is contained in:
ssongliu
2025-08-05 23:15:03 +08:00
committed by GitHub
parent da7968d364
commit 305eff048c
3 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ type Cronjob struct {
Name string `gorm:"not null" json:"name"`
Type string `gorm:"not null" json:"type"`
GroupID uint `gorm:"not null;default:0" json:"groupID"`
GroupID uint `json:"groupID"`
SpecCustom bool `json:"specCustom"`
Spec string `gorm:"not null" json:"spec"`
+1
View File
@@ -34,6 +34,7 @@ func InitAgentDB() {
migrations.AddMethodToAlertLog,
migrations.AddMethodToAlertTask,
migrations.UpdateMcpServer,
migrations.InitCronjobGroup,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)
+13
View File
@@ -433,3 +433,16 @@ var UpdateMcpServer = &gormigrate.Migration{
return nil
},
}
var InitCronjobGroup = &gormigrate.Migration{
ID: "20250805-init-cronjob-group",
Migrate: func(tx *gorm.DB) error {
if err := tx.AutoMigrate(&model.Cronjob{}); err != nil {
return err
}
if err := tx.Model(&model.Cronjob{}).Where("1=1").Updates(map[string]interface{}{"group_id": 0}).Error; err != nil {
return err
}
return nil
},
}