Skip to content

Commit

Permalink
feat(backend): dbha api的datetime类型需要兼容5.7的NO_ZERO_DATE sql_mode close #…
Browse files Browse the repository at this point in the history
  • Loading branch information
xjxia committed Nov 10, 2023
1 parent 46d5f7c commit e475d2b
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 60 deletions.
16 changes: 8 additions & 8 deletions dbm-services/common/dbha/hadb-api/model/DBStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (

// DbStatus TODO
type DbStatus struct {
Uid uint `gorm:"column:uid;primary_key;AUTO_INCREMENT" json:"uid"`
AgentIP string `gorm:"column:agent_ip;NOT NULL" json:"agent_ip"`
IP string `gorm:"column:ip;NOT NULL" json:"ip"`
Port uint `gorm:"column:port;NOT NULL" json:"port"`
DbType string `gorm:"column:db_type;NOT NULL" json:"db_type"`
Status string `gorm:"column:status;NOT NULL" json:"status"`
Cloud string `gorm:"column:cloud;NOT NULL" json:"cloud"`
LastTime time.Time `gorm:"column:last_time;type:datetime;default:CURRENT_TIMESTAMP;NOT NULL"`
Uid uint `gorm:"column:uid;primary_key;AUTO_INCREMENT" json:"uid"`
AgentIP string `gorm:"column:agent_ip;NOT NULL" json:"agent_ip"`
IP string `gorm:"column:ip;NOT NULL" json:"ip"`
Port uint `gorm:"column:port;NOT NULL" json:"port"`
DbType string `gorm:"column:db_type;NOT NULL" json:"db_type"`
Status string `gorm:"column:status;NOT NULL" json:"status"`
Cloud string `gorm:"column:cloud;NOT NULL" json:"cloud"`
LastTime *time.Time `gorm:"column:last_time;type:datetime;default:CURRENT_TIMESTAMP;NOT NULL" json:"last_time,omitempty"`
}

// TableName TODO
Expand Down
18 changes: 10 additions & 8 deletions dbm-services/common/dbha/hadb-api/model/HALogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import (
"time"
)

// HaLogs gm logs
type HaLogs struct {
Uid uint `gorm:"column:uid;primary_key;AUTO_INCREMENT" json:"uid"`
IP string `gorm:"column:ip;NOT NULL" json:"ip"`
Port uint `gorm:"column:port;NOT NULL" json:"port"`
MonIP string `gorm:"column:mon_ip;NOT NULL" json:"mon_ip"`
Module string `gorm:"column:module;NOT NULL" json:"module"`
Cloud string `gorm:"column:cloud;NOT NULL" json:"cloud"`
DateTime time.Time `gorm:"column:date_time;type:datetime;default:CURRENT_TIMESTAMP;NOT NULL" json:"date_time"`
Comment string `gorm:"column:comment;NOT NULL" json:"comment"`
Uid uint `gorm:"column:uid;primary_key;AUTO_INCREMENT" json:"uid"`
IP string `gorm:"column:ip;NOT NULL" json:"ip"`
Port uint `gorm:"column:port;NOT NULL" json:"port"`
MonIP string `gorm:"column:mon_ip;NOT NULL" json:"mon_ip"`
Module string `gorm:"column:module;NOT NULL" json:"module"`
Cloud string `gorm:"column:cloud;NOT NULL" json:"cloud"`
DateTime *time.Time `gorm:"column:date_time;type:datetime;default:CURRENT_TIMESTAMP;NOT NULL" json:"date_time,omitempty"`
Comment string `gorm:"column:comment;NOT NULL" json:"comment"`
}

// TableName table name
func (m *HaLogs) TableName() string {
return "ha_logs"
}
26 changes: 13 additions & 13 deletions dbm-services/common/dbha/hadb-api/model/HAStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import (

// HaStatus struct generate by https://sql2gorm.mccode.info/
type HaStatus struct {
Uid uint `gorm:"column:uid;primary_key;AUTO_INCREMENT" json:"uid"`
IP string `gorm:"column:ip;NOT NULL" json:"ip"`
Port int `gorm:"column:port" json:"port"`
Module string `gorm:"column:module;NOT NULL" json:"module"`
City string `gorm:"column:city;NOT NULL" json:"city"`
Campus string `gorm:"column:campus;NOT NULL" json:"campus"`
Cloud string `gorm:"column:cloud;NOT NULL" json:"cloud"`
DbType string `gorm:"column:db_type" json:"db_type"`
StartTime time.Time `gorm:"column:start_time;type:datetime;default:CURRENT_TIMESTAMP;NOT NULL" json:"start_time"`
LastTime time.Time `gorm:"column:last_time;type:datetime;default:CURRENT_TIMESTAMP;NOT NULL" json:"last_time"`
Status string `gorm:"column:status;NOT NULL" json:"status"`
TakeOverGm string `gorm:"column:take_over_gm" json:"take_over_gm"`
ReportInterval int `gorm:"column:report_interval" json:"report_interval"`
Uid uint `gorm:"column:uid;primary_key;AUTO_INCREMENT" json:"uid"`
IP string `gorm:"column:ip;NOT NULL" json:"ip"`
Port int `gorm:"column:port" json:"port"`
Module string `gorm:"column:module;NOT NULL" json:"module"`
City string `gorm:"column:city;NOT NULL" json:"city"`
Campus string `gorm:"column:campus;NOT NULL" json:"campus"`
Cloud string `gorm:"column:cloud;NOT NULL" json:"cloud"`
DbType string `gorm:"column:db_type" json:"db_type"`
StartTime *time.Time `gorm:"column:start_time;type:datetime;default:CURRENT_TIMESTAMP;NOT NULL" json:"start_time,omitempty"`
LastTime *time.Time `gorm:"column:last_time;type:datetime;default:CURRENT_TIMESTAMP;NOT NULL" json:"last_time,omitempty"`
Status string `gorm:"column:status;NOT NULL" json:"status"`
TakeOverGm string `gorm:"column:take_over_gm" json:"take_over_gm"`
ReportInterval int `gorm:"column:report_interval" json:"report_interval"`
}

// TableName TODO
Expand Down
14 changes: 7 additions & 7 deletions dbm-services/common/dbha/hadb-api/model/SwitchLogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import "time"

// SwitchLogs TODO
type SwitchLogs struct {
UID int `gorm:"column:uid;primaryKey;autoIncrement" json:"uid"`
SwitchID int `gorm:"column:sw_id" json:"sw_id"`
IP string `gorm:"column:ip" json:"ip"`
Result string `gorm:"column:result" json:"result"`
Datetime time.Time `gorm:"column:datetime" json:"datetime"`
Comment string `gorm:"column:comment" json:"comment"`
Port int `gorm:"column:port" json:"port"`
UID int `gorm:"column:uid;primaryKey;autoIncrement" json:"uid"`
SwitchID int `gorm:"column:sw_id" json:"sw_id"`
IP string `gorm:"column:ip" json:"ip"`
Result string `gorm:"column:result" json:"result"`
Datetime *time.Time `gorm:"column:datetime" json:"datetime,omitempty"`
Comment string `gorm:"column:comment" json:"comment"`
Port int `gorm:"column:port" json:"port"`
}

// TableName TODO
Expand Down
36 changes: 18 additions & 18 deletions dbm-services/common/dbha/hadb-api/model/TbMonSwitchQueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ import (

// TbMonSwitchQueue TODO
type TbMonSwitchQueue struct {
Uid uint `gorm:"column:uid;primary_key;AUTO_INCREMENT" json:"uid"`
IP string `gorm:"column:ip;NOT NULL" json:"ip"`
Port int `gorm:"column:port;NOT NULL" json:"port"`
ConfirmCheckTime time.Time `gorm:"column:confirm_check_time;type:datetime;default:CURRENT_TIMESTAMP" json:"confirm_check_time"`
DbRole string `gorm:"column:db_role;NOT NULL" json:"db_role"`
SlaveIP string `gorm:"column:slave_ip" json:"slave_ip"`
SlavePort int `gorm:"column:slave_port" json:"slave_port"`
Status string `gorm:"column:status" json:"status"`
ConfirmResult string `gorm:"column:confirm_result" json:"confirm_result"`
SwitchStartTime time.Time `gorm:"column:switch_start_time" json:"switch_start_time"`
SwitchFinishedTime time.Time `gorm:"column:switch_finished_time" json:"switch_finished_time"`
SwitchResult string `gorm:"column:switch_result" json:"switch_result"`
Remark string `gorm:"column:remark" json:"remark"`
App string `gorm:"column:app" json:"app"`
DbType string `gorm:"column:db_type" json:"db_type"`
Idc string `gorm:"column:idc" json:"idc"`
Cloud string `gorm:"column:cloud" json:"cloud"`
Cluster string `gorm:"column:cluster" json:"cluster"`
Uid uint `gorm:"column:uid;primary_key;AUTO_INCREMENT" json:"uid"`
IP string `gorm:"column:ip;NOT NULL" json:"ip"`
Port int `gorm:"column:port;NOT NULL" json:"port"`
ConfirmCheckTime *time.Time `gorm:"column:confirm_check_time;type:datetime;default:CURRENT_TIMESTAMP" json:"confirm_check_time,omitempty"`
DbRole string `gorm:"column:db_role;NOT NULL" json:"db_role"`
SlaveIP string `gorm:"column:slave_ip" json:"slave_ip"`
SlavePort int `gorm:"column:slave_port" json:"slave_port"`
Status string `gorm:"column:status" json:"status"`
ConfirmResult string `gorm:"column:confirm_result" json:"confirm_result"`
SwitchStartTime *time.Time `gorm:"column:switch_start_time" json:"switch_start_time,omitempty"`
SwitchFinishedTime *time.Time `gorm:"column:switch_finished_time" json:"switch_finished_time,omitempty"`
SwitchResult string `gorm:"column:switch_result" json:"switch_result"`
Remark string `gorm:"column:remark" json:"remark"`
App string `gorm:"column:app" json:"app"`
DbType string `gorm:"column:db_type" json:"db_type"`
Idc string `gorm:"column:idc" json:"idc"`
Cloud string `gorm:"column:cloud" json:"cloud"`
Cluster string `gorm:"column:cluster" json:"cluster"`
}

// TableName TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ func UpdateDBStatus(ctx *fasthttp.RequestCtx, queryParam interface{}, setParam i
return
}
}
whereCond.set.LastTime = time.Now()
currentTime := time.Now()
whereCond.set.LastTime = &currentTime
log.Logger.Debugf("%+v", whereCond)

db := model.HADB.Self.Table(whereCond.query.TableName()).Where(whereCond.query).Updates(whereCond.set)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ func ReplaceHaInfo(ctx *fasthttp.RequestCtx, queryParam interface{}, setParam in
return
}
}
whereCond.set.LastTime = time.Now()
currentTime := time.Now()
whereCond.set.LastTime = &currentTime

log.Logger.Debugf("%+v", whereCond)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type SwitchLogsApi struct {
SwitchID int `json:"sw_id"`
IP string `json:"ip"`
Result string `json:"result"`
Datetime string `json:"datetime"`
Datetime string `json:"datetime,omitempty"`
Comment string `json:"comment"`
Port int `json:"port"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ type TbMonSwitchQueueApi struct {
Uid uint `json:"uid"`
IP string `json:"ip"`
Port int `json:"port"`
ConfirmCheckTime string `json:"confirm_check_time"`
ConfirmCheckTime string `json:"confirm_check_time,omitempty"`
DbRole string `json:"db_role"`
SlaveIP string `json:"slave_ip"`
SlavePort int `json:"slave_port"`
Status string `json:"status"`
ConfirmResult string `json:"confirm_result"`
SwitchStartTime string `json:"switch_start_time"`
SwitchFinishedTime string `json:"switch_finished_time"`
SwitchStartTime string `json:"switch_start_time,omitempty"`
SwitchFinishedTime string `json:"switch_finished_time,omitempty"`
SwitchResult string `json:"switch_result"`
Remark string `json:"remark"`
App string `json:"app"`
Expand Down

0 comments on commit e475d2b

Please sign in to comment.