From 3efbf9cce15bf0e2a25d47377a7950ab294f9a08 Mon Sep 17 00:00:00 2001 From: UUBulb <35923940+uubulb@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:41:21 +0800 Subject: [PATCH] disable soft deletion in group api (#10) * disable soft deletion in group api * remove DeleteAt * remove DeleteAt service --- .../controller/notification_group.go | 2 +- cmd/dashboard/controller/server_group.go | 2 +- model/common.go | 11 +++++----- model/service_history.go | 21 ++++++++----------- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/cmd/dashboard/controller/notification_group.go b/cmd/dashboard/controller/notification_group.go index f2e20a2..1b24355 100644 --- a/cmd/dashboard/controller/notification_group.go +++ b/cmd/dashboard/controller/notification_group.go @@ -146,7 +146,7 @@ func updateNotificationGroup(c *gin.Context) (any, error) { if err := tx.Save(&ngDB).Error; err != nil { return err } - if err := tx.Delete(&model.NotificationGroupNotification{}, "notification_group_id = ?", id).Error; err != nil { + if err := tx.Unscoped().Delete(&model.NotificationGroupNotification{}, "notification_group_id = ?", id).Error; err != nil { return err } diff --git a/cmd/dashboard/controller/server_group.go b/cmd/dashboard/controller/server_group.go index 2503761..1cfff9c 100644 --- a/cmd/dashboard/controller/server_group.go +++ b/cmd/dashboard/controller/server_group.go @@ -143,7 +143,7 @@ func updateServerGroup(c *gin.Context) (any, error) { if err := tx.Save(&sgDB).Error; err != nil { return err } - if err := tx.Delete(&model.ServerGroupServer{}, "server_group_id = ?", id).Error; err != nil { + if err := tx.Unscoped().Delete(&model.ServerGroupServer{}, "server_group_id = ?", id).Error; err != nil { return err } diff --git a/model/common.go b/model/common.go index 62f5cd2..0d0cbf4 100644 --- a/model/common.go +++ b/model/common.go @@ -2,17 +2,16 @@ package model import ( "time" - - "gorm.io/gorm" ) const CtxKeyAuthorizedUser = "ckau" type Common struct { - ID uint64 `gorm:"primaryKey" json:"id,omitempty"` - CreatedAt time.Time `gorm:"index;<-:create" json:"created_at,omitempty"` - UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at,omitempty"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"` + ID uint64 `gorm:"primaryKey" json:"id,omitempty"` + CreatedAt time.Time `gorm:"index;<-:create" json:"created_at,omitempty"` + UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at,omitempty"` + // Do not use soft deletion + // DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"` } type Response struct { diff --git a/model/service_history.go b/model/service_history.go index 1ebc155..a607c94 100644 --- a/model/service_history.go +++ b/model/service_history.go @@ -2,19 +2,16 @@ package model import ( "time" - - "gorm.io/gorm" ) type ServiceHistory struct { - ID uint64 `gorm:"primaryKey" json:"id,omitempty"` - CreatedAt time.Time `gorm:"index;<-:create;index:idx_server_id_created_at_service_id_avg_delay" json:"created_at,omitempty"` - UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at,omitempty"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"` - ServiceID uint64 `gorm:"index:idx_server_id_created_at_service_id_avg_delay" json:"service_id,omitempty"` - ServerID uint64 `gorm:"index:idx_server_id_created_at_service_id_avg_delay" json:"server_id,omitempty"` - AvgDelay float32 `gorm:"index:idx_server_id_created_at_service_id_avg_delay" json:"avg_delay,omitempty"` // 平均延迟,毫秒 - Up uint64 `json:"up,omitempty"` // 检查状态良好计数 - Down uint64 `json:"down,omitempty"` // 检查状态异常计数 - Data string `json:"data,omitempty"` + ID uint64 `gorm:"primaryKey" json:"id,omitempty"` + CreatedAt time.Time `gorm:"index;<-:create;index:idx_server_id_created_at_service_id_avg_delay" json:"created_at,omitempty"` + UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at,omitempty"` + ServiceID uint64 `gorm:"index:idx_server_id_created_at_service_id_avg_delay" json:"service_id,omitempty"` + ServerID uint64 `gorm:"index:idx_server_id_created_at_service_id_avg_delay" json:"server_id,omitempty"` + AvgDelay float32 `gorm:"index:idx_server_id_created_at_service_id_avg_delay" json:"avg_delay,omitempty"` // 平均延迟,毫秒 + Up uint64 `json:"up,omitempty"` // 检查状态良好计数 + Down uint64 `json:"down,omitempty"` // 检查状态异常计数 + Data string `json:"data,omitempty"` }