fix: 解决计划任务备份远程数据库详情显示错误的问题 (#1886)

pull/1890/head
ssongliu 1 year ago committed by GitHub
parent 87e9662af4
commit 25ccadea9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"path" "path"
"strconv"
"time" "time"
"github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
@ -54,6 +55,14 @@ func (u *CronjobService) SearchWithPage(search dto.SearchWithPage) (int64, inter
} else { } else {
item.TargetDir = "-" item.TargetDir = "-"
} }
if item.Type == "database" && item.DBName != "all" {
itemID, _ := strconv.Atoi(item.DBName)
dbItem, err := mysqlRepo.Get(commonRepo.WithByID(uint(itemID)))
if err != nil {
return 0, nil, err
}
item.DBName = dbItem.Name
}
record, _ := cronjobRepo.RecordFirst(cronjob.ID) record, _ := cronjobRepo.RecordFirst(cronjob.ID)
if record.ID != 0 { if record.ID != 0 {
item.LastRecordTime = record.StartTime.Format("2006-01-02 15:04:05") item.LastRecordTime = record.StartTime.Format("2006-01-02 15:04:05")

@ -37,6 +37,7 @@ func Init() {
migrations.EncryptHostPassword, migrations.EncryptHostPassword,
migrations.AddRemoteDB, migrations.AddRemoteDB,
migrations.UpdateRedisParam, migrations.UpdateRedisParam,
migrations.UpdateCronjobWithDb,
}) })
if err := m.Migrate(); err != nil { if err := m.Migrate(); err != nil {
global.LOG.Error(err) global.LOG.Error(err)

@ -547,3 +547,26 @@ var UpdateRedisParam = &gormigrate.Migration{
}, },
} }
var UpdateCronjobWithDb = &gormigrate.Migration{
ID: "20230809-update-cronjob-with-db",
Migrate: func(tx *gorm.DB) error {
var cronjobs []model.Cronjob
if err := global.DB.Where("type = ? AND db_name != ?", "database", "all").Find(&cronjobs).Error; err != nil {
return nil
}
for _, job := range cronjobs {
var db model.DatabaseMysql
if err := global.DB.Where("name = ?", job.DBName).First(&db).Error; err != nil {
continue
}
if err := tx.Model(&model.Cronjob{}).
Where("id = ?", job.ID).
Updates(map[string]interface{}{"db_name": db.ID}).Error; err != nil {
continue
}
}
return nil
},
}

Loading…
Cancel
Save