diff --git a/backend/app/repo/cronjob.go b/backend/app/repo/cronjob.go index 684164661..867fc6283 100644 --- a/backend/app/repo/cronjob.go +++ b/backend/app/repo/cronjob.go @@ -20,6 +20,7 @@ type ICronjobRepo interface { Page(limit, offset int, opts ...DBOption) (int64, []model.Cronjob, error) Create(cronjob *model.Cronjob) error WithByJobID(id int) DBOption + WithByDbName(name string) DBOption WithByDefaultDownload(account string) DBOption WithByRecordDropID(id int) DBOption WithByRecordFile(file string) DBOption @@ -117,6 +118,12 @@ func (c *CronjobRepo) WithByJobID(id int) DBOption { } } +func (c *CronjobRepo) WithByDbName(name string) DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("db_name = ?", name) + } +} + func (c *CronjobRepo) WithByDefaultDownload(account string) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("default_download = ?", account) diff --git a/backend/app/service/backup_app.go b/backend/app/service/backup_app.go index 5f2073643..1ba23a656 100644 --- a/backend/app/service/backup_app.go +++ b/backend/app/service/backup_app.go @@ -303,6 +303,10 @@ func reCreateDB(dbID uint, database model.Database, oldEnv string) (*model.Datab Password: oldPassword, Permission: "%", }) + cronjobs, _ := cronjobRepo.List(cronjobRepo.WithByDbName(fmt.Sprintf("%v", dbID))) + for _, job := range cronjobs { + _ = cronjobRepo.Update(job.ID, map[string]interface{}{"db_name": fmt.Sprintf("%v", createDB.ID)}) + } if err != nil { return nil, envMap, err }