Files
mayfly-go/server/internal/db/config/config.go
zongyangleo 6343173cf8 !124 一些更新和bug
* fix: 代码合并
* feat:支持数据库版本兼容,目前兼容了oracle11g部分特性
* fix: 修改数据同步bug,数据sql里指定修改字段别,导致未正确记录修改字段值
* feat: 数据库迁移支持定时迁移和迁移到sql文件
2024-10-20 03:52:23 +00:00

99 lines
2.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package config
import (
"cmp"
sysapp "mayfly-go/internal/sys/application"
"path/filepath"
"runtime"
"github.com/may-fly/cast"
)
const (
ConfigKeyDbms string = "DbmsConfig" // dbms相关配置信息
ConfigKeyDbBackupRestore string = "DbBackupRestore" // 数据库备份
ConfigKeyDbMysqlBin string = "MysqlBin" // mysql可执行文件配置
ConfigKeyDbMariadbBin string = "MariadbBin" // mariadb可执行文件配置
)
type Dbms struct {
QuerySqlSave bool // 是否记录查询类sql
MaxResultSet int // 允许sql查询的最大结果集数。注: 0=不限制
SqlExecTl int // sql执行时间限制超过该时间单位执行将被取消
}
func GetDbms() *Dbms {
c := sysapp.GetConfigApp().GetConfig(ConfigKeyDbms)
jm := c.GetJsonMap()
dbmsConf := new(Dbms)
dbmsConf.QuerySqlSave = c.ConvBool(jm["querySqlSave"], false)
dbmsConf.MaxResultSet = cast.ToInt(jm["maxResultSet"])
dbmsConf.SqlExecTl = cast.ToIntD(jm["sqlExecTl"], 60)
return dbmsConf
}
type DbBackupRestore struct {
BackupPath string // 备份文件路径呢
TransferPath string // 数据库迁移文件存储路径
}
// 获取数据库备份配置
func GetDbBackupRestore() *DbBackupRestore {
c := sysapp.GetConfigApp().GetConfig(ConfigKeyDbBackupRestore)
jm := c.GetJsonMap()
dbrc := new(DbBackupRestore)
dbrc.BackupPath = filepath.Join(cmp.Or(jm["backupPath"], "./db/backup"))
dbrc.TransferPath = filepath.Join(cmp.Or(jm["transferPath"], "./db/transfer"))
return dbrc
}
// mysql客户端可执行文件配置
type MysqlBin struct {
Path string // 可执行文件路径
MysqlPath string // mysql可执行文件路径
MysqldumpPath string // mysqldump可执行文件路径
MysqlbinlogPath string // mysqlbinlog可执行文件路径
}
// 获取数据库备份配置
func GetMysqlBin(configKey string) *MysqlBin {
c := sysapp.GetConfigApp().GetConfig(configKey)
jm := c.GetJsonMap()
mbc := new(MysqlBin)
path := jm["path"]
if path == "" {
path = "./db/mysql/bin"
}
mbc.Path = filepath.Join(path)
var extName string
if runtime.GOOS == "windows" {
extName = ".exe"
}
mysqlPath := jm["mysql"]
if mysqlPath == "" {
mysqlPath = filepath.Join(path, "mysql"+extName)
}
mbc.MysqlPath = filepath.Join(mysqlPath)
mysqldumpPath := jm["mysqldump"]
if mysqldumpPath == "" {
mysqldumpPath = filepath.Join(path, "mysqldump"+extName)
}
mbc.MysqldumpPath = filepath.Join(mysqldumpPath)
mysqlbinlogPath := jm["mysqlbinlog"]
if mysqlbinlogPath == "" {
mysqlbinlogPath = filepath.Join(path, "mysqlbinlog"+extName)
}
mbc.MysqlbinlogPath = filepath.Join(mysqlbinlogPath)
return mbc
}