package model import ( "time" "gorm.io/gorm" "github.com/sundynix/pets-be/pkg/idgen" ) // Base 所有模型的公共字段。主键为雪花算法字符串 ID(非自增)。 type Base struct { ID string `gorm:"primaryKey;size:24" json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } // BeforeCreate 未显式赋值时自动生成雪花 ID(通过嵌入对所有模型生效)。 func (b *Base) BeforeCreate(tx *gorm.DB) error { if b.ID == "" { b.ID = idgen.Next() } return nil } // AllModels 需要 AutoMigrate 的模型清单(按依赖顺序) func AllModels() []any { return []any{ &User{}, &Pet{}, &HealthRecord{}, &DailyTask{}, &Plan{}, &PlanTask{}, &Reminder{}, &Post{}, &Comment{}, &PostLike{}, &Article{}, &AIMessage{}, &ProMembership{}, &Admin{}, &DailyAdvice{}, &CareTemplate{}, &CareTemplateItem{}, &CommunityBotConfig{}, &File{}, &Feedback{}, &Follow{}, &RefreshToken{}, &AIQuotaConfig{}, &AIUsage{}, } }