|
|
|
@ -17,7 +17,22 @@ func ConfigGormDB() { |
|
|
|
|
if err != nil { |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|