common.go 287 B

123456789101112131415161718192021
  1. package dao
  2. import (
  3. "fmt"
  4. _ "github.com/go-sql-driver/mysql"
  5. "github.com/jinzhu/gorm"
  6. )
  7. var Db *gorm.DB
  8. func InitDB(db *gorm.DB) {
  9. Db = db
  10. err := Db.AutoMigrate(
  11. &User{},
  12. &Tenant{},
  13. &Role{},
  14. ).Error
  15. if err != nil {
  16. panic(fmt.Sprintf("AutoMigrate err : %v", err))
  17. }
  18. }