From 08a45e9723a28d5dc413b01155e5ef56197d4a5a Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 31 Jan 2024 18:47:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E6=81=A2=E5=A4=8D=E5=AF=BC=E8=87=B4=E8=AE=A1=E5=88=92=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=89=A7=E8=A1=8C=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#3769)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/repo/cronjob.go | 7 +++++++ backend/app/service/backup_app.go | 4 ++++ 2 files changed, 11 insertions(+) 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 }