35 lines
941 B
Go
35 lines
941 B
Go
package main
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/spf13/viper"
|
|
"myschools.me/wyh/token.git/model"
|
|
"myschools.me/wyh/token.git/mysql"
|
|
)
|
|
|
|
//initMysql 初始化表
|
|
func initMysql() {
|
|
if !viper.GetBool("mysql.inittable") {
|
|
return
|
|
}
|
|
|
|
db := mysql.New()
|
|
// if !db.Migrator().HasTable(&model.Device{}) {
|
|
// if err := db.Set("gorm:table_options", "ENGINE=memory").Migrator().CreateTable(&model.Device{}); err != nil {
|
|
// log.WithFields(log.Fields{
|
|
// "func": "initMysql",
|
|
// }).Fatalf("device table: %s", err.Error())
|
|
// }
|
|
// }
|
|
// if err := db.AutoMigrate(&model.Device{}, &model.Event{}, &model.EventMedia{}, &model.EventObject{}, &model.Server{}); err != nil {
|
|
// log.WithFields(log.Fields{
|
|
// "func": "initMysql",
|
|
// }).Fatalf("%s", err.Error())
|
|
// }
|
|
if err := db.AutoMigrate(&model.User{}); err != nil {
|
|
log.WithFields(log.Fields{
|
|
"func": "initMysql",
|
|
}).Fatalf("%s", err.Error())
|
|
}
|
|
}
|