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.

59 lines
1.4 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. var err error
  11. err = InitSysApi(db)
  12. err = InitSysUser(db)
  13. err = InitExaCustomer(db)
  14. err = InitCasbinModel(db)
  15. err = InitSysAuthority(db)
  16. err = InitSysBaseMenus(db)
  17. err = InitAuthorityMenu(db)
  18. err = InitSysDictionary(db)
  19. err = InitSysAuthorityMenus(db)
  20. err = InitSysDataAuthorityId(db)
  21. err = InitSysDictionaryDetail(db)
  22. err = InitExaFileUploadAndDownload(db)
  23. if err != nil {
  24. color.Warn.Printf("[Mysql]-->初始化数据失败,err: %v\n", err)
  25. os.Exit(0)
  26. }
  27. color.Info.Println("[Mysql]-->初始化数据成功")
  28. }
  29. func InitMysqlTables(db *gorm.DB) {
  30. var err error
  31. if !db.Migrator().HasTable("casbin_rule") {
  32. err = db.Migrator().CreateTable(&gormadapter.CasbinRule{})
  33. }
  34. err = db.AutoMigrate(
  35. model.SysApi{},
  36. model.SysUser{},
  37. model.ExaFile{},
  38. model.ExaCustomer{},
  39. model.SysBaseMenu{},
  40. model.SysWorkflow{},
  41. model.SysAuthority{},
  42. model.JwtBlacklist{},
  43. model.ExaFileChunk{},
  44. model.SysDictionary{},
  45. model.ExaSimpleUploader{},
  46. model.SysOperationRecord{},
  47. model.SysWorkflowStepInfo{},
  48. model.SysDictionaryDetail{},
  49. model.SysBaseMenuParameter{},
  50. model.ExaFileUploadAndDownload{},
  51. )
  52. if err != nil {
  53. color.Warn.Printf("[Mysql]-->初始化数据表失败,err: %v\n", err)
  54. os.Exit(0)
  55. }
  56. color.Info.Println("[Mysql]-->初始化数据表成功")
  57. }