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:
nepiedg
2026-01-03 02:35:11 +00:00
parent 16844d4a42
commit 1ad775be63
9 changed files with 182 additions and 108 deletions
+27 -19
View File
@@ -8,37 +8,45 @@ import (
type VideoParseLog 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_video_parse_user_date,priority:1" json:"mini_program_id"`
UserID uint `gorm:"index:idx_video_parse_user_date,priority:2" json:"user_id"`
RequestContent string `gorm:"type:text" json:"request_content"`
ParsedURL string `gorm:"size:500" json:"parsed_url"`
ThirdPartyStatus int `json:"third_party_status"`
ThirdPartyPayload []byte `gorm:"type:json" json:"third_party_payload"`
FreeQuotaUsed bool `gorm:"default:1" json:"free_quota_used"`
DurationMs int `json:"duration_ms"`
ErrorMessage string `gorm:"size:500" json:"error_message"`
MiniProgramID uint `gorm:"index:idx_video_parse_user_date,priority:1;comment:小程序ID" json:"mini_program_id"`
UserID uint `gorm:"index:idx_video_parse_user_date,priority:2;comment:用户ID" json:"user_id"`
RequestContent string `gorm:"type:text;comment:用户提交原文" json:"request_content"`
ParsedURL string `gorm:"size:500;comment:解析得到的链接" json:"parsed_url"`
ThirdPartyStatus int `gorm:"comment:第三方HTTP状态或业务码" json:"third_party_status"`
ThirdPartyPayload []byte `gorm:"type:json;comment:第三方响应原文" json:"third_party_payload"`
FreeQuotaUsed bool `gorm:"default:1;comment:是否计入免费次数" json:"free_quota_used"`
DurationMs int `gorm:"comment:耗时毫秒" json:"duration_ms"`
ErrorMessage string `gorm:"size:500;comment:错误信息" json:"error_message"`
}
func (VideoParseLog) TableName() string {
return "video_parse_logs"
}
func (VideoParseLog) TableComment() string {
return "短视频去水印调用日志"
}
type VideoParseUnlock 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_video_unlock_user_date,priority:1" json:"mini_program_id"`
UserID uint `gorm:"index:idx_video_unlock_user_date,priority:2" json:"user_id"`
UnlockDate time.Time `gorm:"type:date;index:idx_video_unlock_user_date,priority:3" json:"unlock_date"`
AdWatchedAt time.Time `json:"ad_watched_at"`
MiniProgramID uint `gorm:"index:idx_video_unlock_user_date,priority:1;comment:小程序ID" json:"mini_program_id"`
UserID uint `gorm:"index:idx_video_unlock_user_date,priority:2;comment:用户ID" json:"user_id"`
UnlockDate time.Time `gorm:"type:date;index:idx_video_unlock_user_date,priority:3;comment:解锁日期" json:"unlock_date"`
AdWatchedAt time.Time `gorm:"comment:广告完成时间" json:"ad_watched_at"`
}
func (VideoParseUnlock) TableName() string {
return "video_parse_unlocks"
}
func (VideoParseUnlock) TableComment() string {
return "短视频去水印-每日广告解锁"
}