mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 00:09:16 +08:00
fix: 解决计划任务备份远程数据库详情显示错误的问题 (#1886)
This commit is contained in:
parent
87e9662af4
commit
25ccadea9e
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
||||
@ -54,6 +55,14 @@ func (u *CronjobService) SearchWithPage(search dto.SearchWithPage) (int64, inter
|
||||
} else {
|
||||
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)
|
||||
if record.ID != 0 {
|
||||
item.LastRecordTime = record.StartTime.Format("2006-01-02 15:04:05")
|
||||
|
@ -37,6 +37,7 @@ func Init() {
|
||||
migrations.EncryptHostPassword,
|
||||
migrations.AddRemoteDB,
|
||||
migrations.UpdateRedisParam,
|
||||
migrations.UpdateCronjobWithDb,
|
||||
})
|
||||
if err := m.Migrate(); err != nil {
|
||||
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…
x
Reference in New Issue
Block a user