feat: 初始化管理员账号

main
熊二 2 years ago
parent 07b3a61fac
commit f58abf7425
  1. 17
      app/db.go

@ -17,7 +17,22 @@ func ConfigGormDB() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if err = DB.AutoMigrate(&User{}, &Goods{}, &Price{}); err != nil { if err = DB.AutoMigrate(&User{}, &UserToken{}, &Goods{}, &Price{}); err != nil {
panic(err)
}
hash, err := HashPassword("123456")
if err != nil {
panic(err)
}
admin := User{
Model: gorm.Model{ID: 1},
Name: "超级管理员",
PhoneNumber: "18982052224",
Password: hash,
Admin: true,
}
err = DB.Save(&admin).Error
if err != nil {
panic(err) panic(err)
} }
} }

Loading…
Cancel
Save