From 08ca16c6a15bdd7987ff1473d994c3d502e3cba2 Mon Sep 17 00:00:00 2001 From: Keima Date: Fri, 28 Oct 2022 19:53:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=85=8D=E7=BD=AE=E9=A1=B9?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=8E=A7=E5=88=B6=E6=98=AF=E5=90=A6=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E6=B5=8B=E8=AF=95=E6=95=B0=E6=8D=AE=E5=BA=93=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=B0=8F=E4=BA=8E=E7=BA=BF=E4=B8=8A=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=20(#297)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增配置项用于控制是否允许测试数据库版本小于线上数据库 Log: 新增配置项用于控制是否允许测试数据库版本小于线上数据库 --- common/config.go | 1 + doc/config.md | 2 ++ env/env.go | 11 +++++++---- etc/soar.yaml | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/common/config.go b/common/config.go index ccb086f..2f65289 100644 --- a/common/config.go +++ b/common/config.go @@ -54,6 +54,7 @@ type Configuration struct { OnlineDSN *Dsn `yaml:"online-dsn"` // 线上环境数据库配置 TestDSN *Dsn `yaml:"test-dsn"` // 测试环境数据库配置 AllowOnlineAsTest bool `yaml:"allow-online-as-test"` // 允许 Online 环境也可以当作 Test 环境 + DisableVersionCheck bool `yaml:"disable-version-check"` // 是否禁用环境检测,开启后表示允许测试环境版本低于线上环境 不建议开启,可能会导致语句执行异常 DropTestTemporary bool `yaml:"drop-test-temporary"` // 是否清理Test环境产生的临时库表 CleanupTestDatabase bool `yaml:"cleanup-test-database"` // 清理残余的测试数据库(程序异常退出或未开启drop-test-temporary) issue #48 OnlySyntaxCheck bool `yaml:"only-syntax-check"` // 只做语法检查不输出优化建议 diff --git a/doc/config.md b/doc/config.md index 4582468..cedd6b7 100644 --- a/doc/config.md +++ b/doc/config.md @@ -23,6 +23,8 @@ test-dsn: disable: false # 是否允许测试环境与线上环境配置相同 allow-online-as-test: true +# 是否禁用环境检测,开启后表示允许测试环境版本低于线上环境 不建议开启,可能会导致语句执行异常 +disable-version-check: false # 是否清理测试时产生的临时文件 drop-test-temporary: true # 语法检查小工具 diff --git a/env/env.go b/env/env.go index 18b4e40..facf71b 100644 --- a/env/env.go +++ b/env/env.go @@ -99,10 +99,13 @@ func BuildEnv() (*VirtualEnv, *database.Connector) { common.Config.OnlineDSN.Disable = true } - // 判断测试环境与线上环境版本是否一致,要求测试环境版本不低于线上环境 - if vEnvVersion < rEnvVersion { - common.Log.Warning("TestDSN MySQL version older than OnlineDSN(%d), TestDSN(%d) will not be used", rEnvVersion, vEnvVersion) - common.Config.TestDSN.Disable = true + // 是否禁用版本检测,禁用后,不再对比测试环境和线上环境的版本大小 + if !common.Config.DisableVersionCheck { + // 判断测试环境与线上环境版本是否一致,要求测试环境版本不低于线上环境 + if vEnvVersion < rEnvVersion { + common.Log.Warning("TestDSN MySQL version older than OnlineDSN(%d), TestDSN(%d) will not be used", rEnvVersion, vEnvVersion) + common.Config.TestDSN.Disable = true + } } return vEnv, connOnline diff --git a/etc/soar.yaml b/etc/soar.yaml index ee9760f..ec47e96 100644 --- a/etc/soar.yaml +++ b/etc/soar.yaml @@ -15,6 +15,7 @@ test-dsn: # 高危,仅测试时使用,线上环境禁止配置为 true allow-online-as-test: true +disable-version-check: false column-not-allow-type: - json - text -- GitLab