From d61b7fd04747816fd5f17b8c617c7e293fae107b Mon Sep 17 00:00:00 2001 From: fusikai Date: Thu, 20 Oct 2022 17:45:05 +0800 Subject: [PATCH] fix gorm deleted_at invalid problem --- pkg/model/db/config_resource.go | 16 ++++++---- pkg/model/db/configuration.go | 56 +++++++++++++++++---------------- pkg/model/view/confgov2.go | 24 +++++++------- 3 files changed, 52 insertions(+), 44 deletions(-) diff --git a/pkg/model/db/config_resource.go b/pkg/model/db/config_resource.go index f38349e8b..b82c08cfd 100644 --- a/pkg/model/db/config_resource.go +++ b/pkg/model/db/config_resource.go @@ -2,7 +2,11 @@ package db -import "time" +import ( + "time" + + "gorm.io/gorm" +) type ( ConfigResource struct { @@ -22,11 +26,11 @@ type ( } ConfigResourceValue struct { - ID uint `gorm:"column:id;primary_key;auto_increment"` - ConfigResourceID uint `gorm:"column:config_resource_id;"` - Value string `gorm:"column:value;type:text;"` - CreatedAt time.Time `gorm:"column:created_at;"` - DeletedAt *time.Time `gorm:"column:deleted_at;"` + ID uint `gorm:"column:id;primary_key;auto_increment"` + ConfigResourceID uint `gorm:"column:config_resource_id;"` + Value string `gorm:"column:value;type:text;"` + CreatedAt time.Time `gorm:"column:created_at;"` + DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;"` } //ConfigResourceTag 资源标签 diff --git a/pkg/model/db/configuration.go b/pkg/model/db/configuration.go index 3c022ca9b..430d5e948 100644 --- a/pkg/model/db/configuration.go +++ b/pkg/model/db/configuration.go @@ -5,42 +5,44 @@ package db import ( "fmt" "time" + + "gorm.io/gorm" ) type ( // Configuration Application configuration Configuration struct { - ID uint `gorm:"column:id;primary_key" json:"id"` - AID uint `gorm:"column:aid" json:"aid"` - Name string `gorm:"column:name;type:varchar(32)" json:"name"` - Content string `gorm:"column:content;type:longtext" json:"content"` - Format string `gorm:"column:format;type:varchar(20)" json:"format"` // Yaml/Toml - Env string `gorm:"column:env;type:varchar(20)" json:"env"` // 环境 - Zone string `gorm:"column:zone;type:varchar(50)" json:"zone"` // 机房Zone - Version string `gorm:"column:version;type:varchar(50)" json:"version"` - CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` - AccessTokenID uint `gorm:"access_token_id" json:"access_token_id"` // AccessToken 授权ID - UID uint `gorm:"column:uid" json:"uid"` // 操作用户ID - UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` - DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"` - PublishedAt *time.Time `gorm:"column:published_at" json:"published_at"` // 未发布/发布时间 - LockUid uint `gorm:"column:lock_uid" json:"lock_uid"` // 正在编辑用户 - LockAt *time.Time `gorm:"column:lock_at" json:"lock_at"` + ID uint `gorm:"column:id;primary_key" json:"id"` + AID uint `gorm:"column:aid" json:"aid"` + Name string `gorm:"column:name;type:varchar(32)" json:"name"` + Content string `gorm:"column:content;type:longtext" json:"content"` + Format string `gorm:"column:format;type:varchar(20)" json:"format"` // Yaml/Toml + Env string `gorm:"column:env;type:varchar(20)" json:"env"` // 环境 + Zone string `gorm:"column:zone;type:varchar(50)" json:"zone"` // 机房Zone + Version string `gorm:"column:version;type:varchar(50)" json:"version"` + CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` + AccessTokenID uint `gorm:"access_token_id" json:"access_token_id"` // AccessToken 授权ID + UID uint `gorm:"column:uid" json:"uid"` // 操作用户ID + UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"` + PublishedAt *time.Time `gorm:"column:published_at" json:"published_at"` // 未发布/发布时间 + LockUid uint `gorm:"column:lock_uid" json:"lock_uid"` // 正在编辑用户 + LockAt *time.Time `gorm:"column:lock_at" json:"lock_at"` App AppInfo `gorm:"foreignKey:AID" json:"-"` } // ConfigurationHistory Application configuration release history version ConfigurationHistory struct { - ID uint `gorm:"column:id;primary_key" json:"id"` - AccessTokenID uint `gorm:"access_token_id" json:"access_token_id"` // AccessToken 授权ID - UID uint `gorm:"column:uid" json:"uid"` // 操作用户ID - ConfigurationID uint `gorm:"column:configuration_id" json:"configuration_id"` - ChangeLog string `gorm:"column:change_log;type:longtext" json:"change_log"` // 变更说明文字 - Content string `gorm:"column:content;type:longtext" json:"content"` // 配置内容 - Version string `gorm:"column:version;type:varchar(50)" json:"version"` // 版本号 - CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` - DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"` + ID uint `gorm:"column:id;primary_key" json:"id"` + AccessTokenID uint `gorm:"access_token_id" json:"access_token_id"` // AccessToken 授权ID + UID uint `gorm:"column:uid" json:"uid"` // 操作用户ID + ConfigurationID uint `gorm:"column:configuration_id" json:"configuration_id"` + ChangeLog string `gorm:"column:change_log;type:longtext" json:"change_log"` // 变更说明文字 + Content string `gorm:"column:content;type:longtext" json:"content"` // 配置内容 + Version string `gorm:"column:version;type:varchar(50)" json:"version"` // 版本号 + CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` + DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"` User *User `json:"-" gorm:"foreignKey:UID;association_foreignkey:Uid"` AccessToken *AccessToken `json:"-" gorm:"foreignKey:AccessTokenID;association_foreignkey:ID"` @@ -127,12 +129,12 @@ func (ConfigurationStatus) TableName() string { return "configuration_status" } -//TableName .. +// TableName .. func (ConfigurationResourceRelation) TableName() string { return "configuration_resource_relation" } -//TableName .. +// TableName .. func (ConfigurationClusterStatus) TableName() string { return "configuration_cluster_status" } diff --git a/pkg/model/view/confgov2.go b/pkg/model/view/confgov2.go index bf26f81b4..c5b29f125 100644 --- a/pkg/model/view/confgov2.go +++ b/pkg/model/view/confgov2.go @@ -2,6 +2,8 @@ package view import ( "time" + + "gorm.io/gorm" ) const ( @@ -34,17 +36,17 @@ type ( // RespListConfigItem Does not contain configuration content to prevent configuration from being too long RespListConfigItem struct { - ID uint `json:"id"` - AID uint `json:"aid"` - Name string `json:"name"` - Format string `json:"format"` // Yaml/Toml - Env string `json:"env"` // 环境 - Zone string `json:"zone"` // 机房Zone - CreatedAt time.Time `json:"created_time"` - UpdatedAt time.Time `json:"update_time"` - DeletedAt *time.Time `json:"deleted_at"` - PublishedAt *time.Time `json:"published"` // 未发布/发布时间 - ConfigStatus uint32 `json:"config_status"` // 配置发布状态,0:未知 1:已发布 2:未发布 + ID uint `json:"id"` + AID uint `json:"aid"` + Name string `json:"name"` + Format string `json:"format"` // Yaml/Toml + Env string `json:"env"` // 环境 + Zone string `json:"zone"` // 机房Zone + CreatedAt time.Time `json:"created_time"` + UpdatedAt time.Time `json:"update_time"` + DeletedAt gorm.DeletedAt `json:"deleted_at"` + PublishedAt *time.Time `json:"published"` // 未发布/发布时间 + ConfigStatus uint32 `json:"config_status"` // 配置发布状态,0:未知 1:已发布 2:未发布 } // ReqDetailConfig ..