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,25 +8,29 @@ import "time"
|
||||
// 因此这里不使用 gorm.Model 的 created_at/updated_at/deleted_at。
|
||||
type SmokeLog struct {
|
||||
// 复合主键(id, uid),其中 id 自增。
|
||||
ID int `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
ID int `gorm:"column:id;primaryKey;autoIncrement;comment:记录ID" json:"id"`
|
||||
UID int `gorm:"column:uid;primaryKey" json:"-"`
|
||||
|
||||
// smoke_time 在库里是 date 类型(只包含日期,不包含时分秒)。
|
||||
SmokeTime *time.Time `gorm:"column:smoke_time;type:date" json:"smoke_time,omitempty"`
|
||||
SmokeTime *time.Time `gorm:"column:smoke_time;type:date;comment:抽烟日期" json:"smoke_time,omitempty"`
|
||||
// smoke_at:真实抽烟时间(可补录,精确到时分秒)
|
||||
SmokeAt *time.Time `gorm:"column:smoke_at;type:datetime" json:"smoke_at,omitempty"`
|
||||
SmokeAt *time.Time `gorm:"column:smoke_at;type:datetime;comment:真实抽烟时间(精确到秒)" json:"smoke_at,omitempty"`
|
||||
|
||||
Remark string `gorm:"column:remark;type:text" json:"remark,omitempty"`
|
||||
Remark string `gorm:"column:remark;type:text;comment:原因/备注" json:"remark,omitempty"`
|
||||
|
||||
// createtime/updatetime/deletetime:秒级 Unix 时间戳(与 gorm 默认字段不同)
|
||||
CreateTime *int64 `gorm:"column:createtime" json:"createtime,omitempty"`
|
||||
UpdateTime *int64 `gorm:"column:updatetime" json:"updatetime,omitempty"`
|
||||
DeleteTime *int64 `gorm:"column:deletetime" json:"deletetime,omitempty"`
|
||||
CreateTime *int64 `gorm:"column:createtime;comment:创建时间(秒)" json:"createtime,omitempty"`
|
||||
UpdateTime *int64 `gorm:"column:updatetime;comment:更新时间(秒)" json:"updatetime,omitempty"`
|
||||
DeleteTime *int64 `gorm:"column:deletetime;comment:删除时间(秒)" json:"deletetime,omitempty"`
|
||||
|
||||
Level int64 `gorm:"column:level;default:1" json:"level"`
|
||||
Num int `gorm:"column:num;default:1" json:"num"`
|
||||
Level int64 `gorm:"column:level;default:1;comment:烟瘾程度" json:"level"`
|
||||
Num int `gorm:"column:num;default:1;comment:抽烟数量" json:"num"`
|
||||
}
|
||||
|
||||
func (SmokeLog) TableName() string {
|
||||
return "fa_smoke_log"
|
||||
}
|
||||
|
||||
func (SmokeLog) TableComment() string {
|
||||
return "抽烟记录"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user