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:
@@ -8,16 +8,20 @@ import (
|
||||
|
||||
type MiniProgram 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:"-"`
|
||||
CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
|
||||
|
||||
Name string `gorm:"size:100;not null" json:"name"`
|
||||
AppID string `gorm:"size:100;uniqueIndex" json:"app_id"`
|
||||
AppSecret string `gorm:"size:200;not null" json:"-"`
|
||||
Description string `gorm:"size:255" json:"description"`
|
||||
Name string `gorm:"size:100;not null;comment:小程序名称" json:"name"`
|
||||
AppID string `gorm:"size:100;uniqueIndex;comment:小程序AppID" json:"app_id"`
|
||||
AppSecret string `gorm:"size:200;not null;comment:小程序AppSecret" json:"-"`
|
||||
Description string `gorm:"size:255;comment:描述" json:"description"`
|
||||
}
|
||||
|
||||
func (MiniProgram) TableName() string {
|
||||
return "mini_programs"
|
||||
}
|
||||
|
||||
func (MiniProgram) TableComment() string {
|
||||
return "小程序配置"
|
||||
}
|
||||
|
||||
+15
-11
@@ -7,20 +7,24 @@ import (
|
||||
)
|
||||
|
||||
type Product 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:"-"`
|
||||
|
||||
Name string `gorm:"size:200;not null" json:"name"`
|
||||
Description string `gorm:"type:text" json:"description"`
|
||||
Price float64 `gorm:"type:decimal(10,2);not null" json:"price"`
|
||||
Stock int `gorm:"default:0" json:"stock"`
|
||||
ImageURL string `gorm:"size:500" json:"image_url"`
|
||||
Category string `gorm:"size:50" json:"category"`
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
Name string `gorm:"size:200;not null;comment:商品名" json:"name"`
|
||||
Description string `gorm:"type:text;comment:商品描述" json:"description"`
|
||||
Price float64 `gorm:"type:decimal(10,2);not null;comment:价格" json:"price"`
|
||||
Stock int `gorm:"default:0;comment:库存" json:"stock"`
|
||||
ImageURL string `gorm:"size:500;comment:图片URL" json:"image_url"`
|
||||
Category string `gorm:"size:50;comment:分类" json:"category"`
|
||||
Status int `gorm:"default:1;comment:状态(1上架/0下架)" json:"status"`
|
||||
}
|
||||
|
||||
func (Product) TableName() string {
|
||||
return "products"
|
||||
}
|
||||
|
||||
func (Product) TableComment() string {
|
||||
return "商品"
|
||||
}
|
||||
|
||||
+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 "用户"
|
||||
}
|
||||
|
||||
@@ -9,21 +9,24 @@ import (
|
||||
// UserMembership 表示会员订阅记录(DDL 见 docs/sql/users.sql)。
|
||||
type UserMembership 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:"-"`
|
||||
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_membership_user,priority:1;index:idx_membership_status,priority:1" json:"mini_program_id"`
|
||||
UserID uint `gorm:"index:idx_membership_user,priority:2;index:idx_membership_status,priority:2" json:"user_id"`
|
||||
MiniProgramID uint `gorm:"index:idx_membership_user,priority:1;index:idx_membership_status,priority:1;comment:小程序ID" json:"mini_program_id"`
|
||||
UserID uint `gorm:"index:idx_membership_user,priority:2;index:idx_membership_status,priority:2;comment:用户ID" json:"user_id"`
|
||||
|
||||
Plan string `gorm:"size:30" json:"plan"`
|
||||
Status string `gorm:"size:20;index:idx_membership_status,priority:3" json:"status"`
|
||||
Plan string `gorm:"size:30;comment:会员套餐" json:"plan"`
|
||||
Status string `gorm:"size:20;index:idx_membership_status,priority:3;comment:状态(active/canceled/expired)" json:"status"`
|
||||
|
||||
StartsAt time.Time `json:"starts_at"`
|
||||
EndsAt time.Time `gorm:"index:idx_membership_user,priority:3;index:idx_membership_status,priority:4" json:"ends_at"`
|
||||
StartsAt time.Time `gorm:"comment:开始时间" json:"starts_at"`
|
||||
EndsAt time.Time `gorm:"index:idx_membership_user,priority:3;index:idx_membership_status,priority:4;comment:结束时间" json:"ends_at"`
|
||||
}
|
||||
|
||||
func (UserMembership) TableName() string {
|
||||
return "user_memberships"
|
||||
}
|
||||
|
||||
func (UserMembership) TableComment() string {
|
||||
return "用户会员订阅"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user