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.5 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package initialize
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/example"
  6. "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  7. "os"
  8. "go.uber.org/zap"
  9. "gorm.io/gorm"
  10. )
  11. // Gorm 初始化数据库并产生数据库全局变量
  12. // Author SliverHorn
  13. func Gorm() *gorm.DB {
  14. switch global.GVA_CONFIG.System.DbType {
  15. case "mysql":
  16. return GormMysql()
  17. case "pgsql":
  18. return GormPgSql()
  19. default:
  20. return GormMysql()
  21. }
  22. }
  23. // RegisterTables 注册数据库表专用
  24. // Author SliverHorn
  25. func RegisterTables(db *gorm.DB) {
  26. err := db.AutoMigrate(
  27. // 系统模块表
  28. system.SysApi{},
  29. system.SysUser{},
  30. system.SysBaseMenu{},
  31. system.JwtBlacklist{},
  32. system.SysAuthority{},
  33. system.SysDictionary{},
  34. system.SysOperationRecord{},
  35. system.SysAutoCodeHistory{},
  36. system.SysDictionaryDetail{},
  37. system.SysBaseMenuParameter{},
  38. // 示例模块表
  39. example.ExaFile{},
  40. example.ExaCustomer{},
  41. example.ExaFileChunk{},
  42. example.ExaFileUploadAndDownload{},
  43. // 自动化模块表
  44. // Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
  45. autocode.AutoCodeExample{},
  46. // Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
  47. )
  48. if err != nil {
  49. global.GVA_LOG.Error("register table failed", zap.Error(err))
  50. os.Exit(0)
  51. }
  52. global.GVA_LOG.Info("register table success")
  53. }