You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.2 KiB

  1. package datas
  2. import (
  3. "gin-vue-admin/model"
  4. gormadapter "github.com/casbin/gorm-adapter/v3"
  5. "github.com/gookit/color"
  6. "gorm.io/gorm"
  7. "os"
  8. )
  9. func InitMysqlData(db *gorm.DB) {
  10. InitSysApi(db)
  11. InitSysUser(db)
  12. InitExaCustomer(db)
  13. InitCasbinModel(db)
  14. InitSysAuthority(db)
  15. InitSysBaseMenus(db)
  16. InitAuthorityMenu(db)
  17. InitSysDictionary(db)
  18. InitSysAuthorityMenus(db)
  19. InitSysDataAuthorityId(db)
  20. InitSysDictionaryDetail(db)
  21. InitExaFileUploadAndDownload(db)
  22. }
  23. func InitMysqlTables(db *gorm.DB) {
  24. var err error
  25. if !db.Migrator().HasTable("casbin_rule") {
  26. err = db.Migrator().CreateTable(&gormadapter.CasbinRule{})
  27. }
  28. err = db.AutoMigrate(
  29. model.SysApi{},
  30. model.SysUser{},
  31. model.ExaFile{},
  32. model.ExaCustomer{},
  33. model.SysBaseMenu{},
  34. model.SysWorkflow{},
  35. model.SysAuthority{},
  36. model.JwtBlacklist{},
  37. model.ExaFileChunk{},
  38. model.SysDictionary{},
  39. model.ExaSimpleUploader{},
  40. model.SysOperationRecord{},
  41. model.SysWorkflowStepInfo{},
  42. model.SysDictionaryDetail{},
  43. model.SysBaseMenuParameter{},
  44. model.ExaFileUploadAndDownload{},
  45. )
  46. if err != nil {
  47. color.Warn.Printf("[Mysql]-->初始化数据表失败,err: %v\n", err)
  48. os.Exit(0)
  49. }
  50. color.Info.Println("[Mysql]-->初始化数据表成功")
  51. }