db_list.go 619 字节
Newer Older
S
songzhibin97 已提交
1 2 3 4 5 6 7
package initialize

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"gorm.io/gorm"
)

8 9
const system = "system"

S
songzhibin97 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
func DBList() {
	dbMap := make(map[string]*gorm.DB)
	for _, info := range global.GVA_CONFIG.DBList {
		if info.Disable {
			continue
		}
		switch info.Type {
		case "mysql":
			dbMap[info.Dbname] = GormMysqlByConfig(info)
		case "pgsql":
			dbMap[info.Dbname] = GormPgSqlByConfig(info)
		default:
			continue
		}
	}
25 26 27 28 29
	// 做特殊判断,是否有迁移
	// 适配低版本迁移多数据库版本
	if sysDB, ok := dbMap[system]; ok {
		global.GVA_DB = sysDB
	}
S
songzhibin97 已提交
30 31
	global.GVA_DBList = dbMap
}