升级数据库时同时升级edgeClientAgentIPs中的countIPs字段值

This commit is contained in:
GoEdgeLab
2023-01-07 10:29:08 +08:00
parent 4ee8a50b06
commit f96ff94264
3 changed files with 55 additions and 4 deletions

View File

@@ -124,6 +124,12 @@ func (this *SQLExecutor) checkData(db *dbs.DB) error {
return err
}
// 更新Agents
err = this.checkClientAgents(db)
if err != nil {
return err
}
// 更新版本号
err = this.updateVersion(db, ComposeSQLVersion())
if err != nil {
@@ -471,6 +477,29 @@ func (this *SQLExecutor) checkMetricItems(db *dbs.DB) error {
return nil
}
// 更新Agents表
func (this *SQLExecutor) checkClientAgents(db *dbs.DB) error {
ones, _, err := db.FindOnes("SELECT id FROM edgeClientAgents")
if err != nil {
return err
}
for _, one := range ones {
var agentId = one.GetInt64("id")
countIPs, err := db.FindCol(0, "SELECT COUNT(*) FROM edgeClientAgentIPs WHERE agentId=?", agentId)
if err != nil {
return err
}
_, err = db.Exec("UPDATE edgeClientAgents SET countIPs=? WHERE id=?", countIPs, agentId)
if err != nil {
return err
}
}
return nil
}
// 更新版本号
func (this *SQLExecutor) updateVersion(db *dbs.DB, version string) error {
stmt, err := db.Prepare("SELECT COUNT(*) FROM edgeVersions")