fix: 监控数据迁移增加数据长度判断 (#4454)

pull/4460/head
ssongliu 8 months ago committed by GitHub
parent 45f6a415de
commit 0cd06803e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -55,54 +55,54 @@ var NewMonitorDB = &gormigrate.Migration{
ios []model.MonitorIO
networks []model.MonitorNetwork
)
if err := tx.Find(&bases).Error; err != nil {
return err
}
if err := tx.Find(&ios).Error; err != nil {
return err
}
if err := tx.Find(&networks).Error; err != nil {
return err
}
_ = tx.Find(&bases).Error
_ = tx.Find(&ios).Error
_ = tx.Find(&networks).Error
if err := global.MonitorDB.AutoMigrate(&model.MonitorBase{}, &model.MonitorIO{}, &model.MonitorNetwork{}); err != nil {
return err
}
_ = global.MonitorDB.Exec("DELETE FROM monitor_bases").Error
_ = global.MonitorDB.Exec("DELETE FROM monitor_ios").Error
_ = global.MonitorDB.Exec("DELETE FROM monitor_networks").Error
for i := 0; i <= len(bases)/200; i++ {
var itemData []model.MonitorBase
if 200*(i+1) <= len(bases) {
itemData = bases[200*i : 200*(i+1)]
} else {
itemData = bases[200*i:]
}
if err := global.MonitorDB.Create(&itemData).Error; err != nil {
return err
if len(bases) != 0 {
for i := 0; i <= len(bases)/200; i++ {
var itemData []model.MonitorBase
if 200*(i+1) <= len(bases) {
itemData = bases[200*i : 200*(i+1)]
} else {
itemData = bases[200*i:]
}
if err := global.MonitorDB.Create(&itemData).Error; err != nil {
return err
}
}
}
for i := 0; i <= len(ios)/200; i++ {
var itemData []model.MonitorIO
if 200*(i+1) <= len(ios) {
itemData = ios[200*i : 200*(i+1)]
} else {
itemData = ios[200*i:]
}
if err := global.MonitorDB.Create(&itemData).Error; err != nil {
return err
if len(ios) != 0 {
for i := 0; i <= len(ios)/200; i++ {
var itemData []model.MonitorIO
if 200*(i+1) <= len(ios) {
itemData = ios[200*i : 200*(i+1)]
} else {
itemData = ios[200*i:]
}
if err := global.MonitorDB.Create(&itemData).Error; err != nil {
return err
}
}
}
for i := 0; i <= len(networks)/200; i++ {
var itemData []model.MonitorNetwork
if 200*(i+1) <= len(networks) {
itemData = networks[200*i : 200*(i+1)]
} else {
itemData = networks[200*i:]
}
if err := global.MonitorDB.Create(&itemData).Error; err != nil {
return err
if len(networks) != 0 {
for i := 0; i <= len(networks)/200; i++ {
var itemData []model.MonitorNetwork
if 200*(i+1) <= len(networks) {
itemData = networks[200*i : 200*(i+1)]
} else {
itemData = networks[200*i:]
}
if err := global.MonitorDB.Create(&itemData).Error; err != nil {
return err
}
}
}
return nil

Loading…
Cancel
Save