Skip to content

Commit

Permalink
bug: fix gorm deleted_at invalid problem (#201)
Browse files Browse the repository at this point in the history
Co-authored-by: fusikai <fusikai@douyu.tv>
  • Loading branch information
linthan and fusikai authored Oct 20, 2022
1 parent b4d7de2 commit bb61962
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 44 deletions.
16 changes: 10 additions & 6 deletions pkg/model/db/config_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

package db

import "time"
import (
"time"

"gorm.io/gorm"
)

type (
ConfigResource struct {
Expand All @@ -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 资源标签
Expand Down
56 changes: 29 additions & 27 deletions pkg/model/db/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"
}
24 changes: 13 additions & 11 deletions pkg/model/view/confgov2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package view

import (
"time"

"gorm.io/gorm"
)

const (
Expand Down Expand Up @@ -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 ..
Expand Down

0 comments on commit bb61962

Please sign in to comment.