Enhance database models with comments and table descriptions
- Added comments to various fields in the database models for better clarity and understanding. - Implemented TableComment methods for several models to provide descriptive information about their purpose. - Updated the AutoMigrate function to support setting table comments in the database. - Improved overall documentation within the code to facilitate future maintenance and development.
This commit is contained in:
+16
-12
@@ -7,23 +7,27 @@ import (
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
ID uint `gorm:"primarykey;comment:用户ID" json:"id"`
|
||||
CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
|
||||
|
||||
MiniProgramID uint `gorm:"index:idx_mini_open,priority:1" json:"mini_program_id"`
|
||||
MiniProgramID uint `gorm:"index:idx_mini_open,priority:1;comment:小程序ID" json:"mini_program_id"`
|
||||
MiniProgram MiniProgram `gorm:"foreignKey:MiniProgramID" json:"mini_program,omitempty"`
|
||||
OpenID string `gorm:"size:100;index:idx_mini_open,priority:2" json:"open_id"`
|
||||
UnionID string `gorm:"size:100" json:"union_id,omitempty"`
|
||||
NickName string `gorm:"size:100" json:"nickname"`
|
||||
AvatarURL string `gorm:"size:500" json:"avatar_url"`
|
||||
Gender int `gorm:"default:0" json:"gender"`
|
||||
Phone string `gorm:"size:20" json:"phone,omitempty"`
|
||||
OpenID string `gorm:"size:100;index:idx_mini_open,priority:2;comment:微信OpenID" json:"open_id"`
|
||||
UnionID string `gorm:"size:100;comment:微信UnionID" json:"union_id,omitempty"`
|
||||
NickName string `gorm:"size:100;comment:昵称" json:"nickname"`
|
||||
AvatarURL string `gorm:"size:500;comment:头像URL" json:"avatar_url"`
|
||||
Gender int `gorm:"default:0;comment:性别(0未知/1男/2女)" json:"gender"`
|
||||
Phone string `gorm:"size:20;comment:手机号" json:"phone,omitempty"`
|
||||
|
||||
SessionKey string `gorm:"size:100" json:"-"`
|
||||
SessionKey string `gorm:"size:100;comment:会话key(用于Bearer Token)" json:"-"`
|
||||
}
|
||||
|
||||
func (User) TableName() string {
|
||||
return "users"
|
||||
}
|
||||
|
||||
func (User) TableComment() string {
|
||||
return "用户"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user