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.

31 lines
613 B

3 years ago
3 years ago
  1. package initialize
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "gorm.io/gorm"
  5. )
  6. const sys = "system"
  7. func DBList() {
  8. dbMap := make(map[string]*gorm.DB)
  9. for _, info := range global.GVA_CONFIG.DBList {
  10. if info.Disable {
  11. continue
  12. }
  13. switch info.Type {
  14. case "mysql":
  15. dbMap[info.Dbname] = GormMysqlByConfig(info)
  16. case "pgsql":
  17. dbMap[info.Dbname] = GormPgSqlByConfig(info)
  18. default:
  19. continue
  20. }
  21. }
  22. // 做特殊判断,是否有迁移
  23. // 适配低版本迁移多数据库版本
  24. if sysDB, ok := dbMap[sys]; ok {
  25. global.GVA_DB = sysDB
  26. }
  27. global.GVA_DBList = dbMap
  28. }