package models import ( "github.com/gin-gonic/gin" "gorm.io/gorm" "product/backend/moo/db" "product/backend/moo/log" "time" ) type Model struct { ID uint `gorm:"primarykey" json:"id"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `gorm:"index" json:"updatedAt"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` } type Pager struct { PageIndex int `form:"pageIndex"` PageSize int `form:"pageSize"` SortField string `form:"sortField"` SortOrder string `form:"sortOrder"` } func Init() { // Migrate if gin.Mode() == gin.DebugMode { if err := db.DB.AutoMigrate( &Subject{}, &Label{}, &LabelValue{}, &Role{}, &User{}, ); err != nil { log.Error(err) } } // Seed if gin.Mode() == gin.DebugMode { // Role roleAdmin := Role{ Title: "管理员", Key: "administrator", State: true, } roleAdmin.ID = 1 db.DB.FirstOrCreate(&roleAdmin, roleAdmin.ID) roleManager := Role{ Title: "管理者", Key: "manager", State: true, Privs: "user/logout,user/info", } roleManager.ID = 2 db.DB.FirstOrCreate(&roleManager, roleManager.ID) // User name := "admin" user := User{ Password: UserDefaultPassword, PasswordSalt: UserPasswordSalt, Name: &name, RealName: "超级管理员", State: true, RoleID: 1, } user.ID = 1 user.Password = UserGeneratePassword(user.Password, user.PasswordSalt) db.DB.FirstOrCreate(&user, user.ID) } }