添加callback,迁移文件

This commit is contained in:
2025-12-15 14:37:34 +08:00
parent ad946af5ee
commit 478e37903b
16 changed files with 52 additions and 367 deletions

View File

@@ -1,17 +1,9 @@
package model
import "gorm.io/gorm"
// atlas:ignore
//
// BaseModel 基础模型,包含通用字段
type BaseModel struct {
Creator uint `gorm:"not null" json:"creator"`
Updater uint `gorm:"not null" json:"updater"`
}
func (b *BaseModel) BeforeCreate(tx *gorm.DB) error {
if userID, ok := tx.Statement.Context.Value("current_user_id").(uint); ok {
b.Creator = userID
b.Updater = userID
}
return nil
}