gorm.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package initialize
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/model/client"
  4. "os"
  5. "github.com/flipped-aurora/gin-vue-admin/server/global"
  6. "github.com/flipped-aurora/gin-vue-admin/server/model/example"
  7. "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  8. "go.uber.org/zap"
  9. "gorm.io/gorm"
  10. )
  11. func Gorm() *gorm.DB {
  12. switch global.GVA_CONFIG.System.DbType {
  13. case "mysql":
  14. global.GVA_ACTIVE_DBNAME = &global.GVA_CONFIG.Mysql.Dbname
  15. return GormMysql()
  16. case "pgsql":
  17. global.GVA_ACTIVE_DBNAME = &global.GVA_CONFIG.Pgsql.Dbname
  18. return GormPgSql()
  19. case "oracle":
  20. global.GVA_ACTIVE_DBNAME = &global.GVA_CONFIG.Oracle.Dbname
  21. return GormOracle()
  22. case "mssql":
  23. global.GVA_ACTIVE_DBNAME = &global.GVA_CONFIG.Mssql.Dbname
  24. return GormMssql()
  25. case "sqlite":
  26. global.GVA_ACTIVE_DBNAME = &global.GVA_CONFIG.Sqlite.Dbname
  27. return GormSqlite()
  28. default:
  29. global.GVA_ACTIVE_DBNAME = &global.GVA_CONFIG.Mysql.Dbname
  30. return GormMysql()
  31. }
  32. }
  33. func RegisterTables() {
  34. db := global.GVA_DB
  35. err := db.AutoMigrate(
  36. system.SysApi{},
  37. system.SysIgnoreApi{},
  38. system.SysUser{},
  39. system.SysBaseMenu{},
  40. system.JwtBlacklist{},
  41. system.SysAuthority{},
  42. system.SysDictionary{},
  43. system.SysOperationRecord{},
  44. system.SysAutoCodeHistory{},
  45. system.SysDictionaryDetail{},
  46. system.SysBaseMenuParameter{},
  47. system.SysBaseMenuBtn{},
  48. system.SysAuthorityBtn{},
  49. system.SysAutoCodePackage{},
  50. system.SysExportTemplate{},
  51. system.Condition{},
  52. system.JoinTemplate{},
  53. system.SysParams{},
  54. system.SysVersion{},
  55. example.ExaFile{},
  56. example.ExaCustomer{},
  57. example.ExaFileChunk{},
  58. example.ExaFileUploadAndDownload{},
  59. example.ExaAttachmentCategory{},
  60. client.ClientUser{},
  61. )
  62. if err != nil {
  63. global.GVA_LOG.Error("register table failed", zap.Error(err))
  64. os.Exit(0)
  65. }
  66. err = bizModel()
  67. if err != nil {
  68. global.GVA_LOG.Error("register biz_table failed", zap.Error(err))
  69. os.Exit(0)
  70. }
  71. global.GVA_LOG.Info("register table success")
  72. }