From d2ae7834aec7f71ef23f883181f52f3493573de1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Mon, 14 Mar 2022 16:06:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0SQL=E5=AD=90=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/const/const.go | 3 +++ internal/nodes/api_node.go | 6 +++--- internal/setup/sql_executor.go | 3 +-- internal/setup/utils.go | 20 ++++++++++++++++++++ internal/setup/utils_test.go | 12 ++++++++++++ 5 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 internal/setup/utils.go create mode 100644 internal/setup/utils_test.go diff --git a/internal/const/const.go b/internal/const/const.go index c9b3617d..01f645c1 100644 --- a/internal/const/const.go +++ b/internal/const/const.go @@ -24,4 +24,7 @@ const ( MonitorNodeVersion = "0.0.3" DNSNodeVersion = "0.2.1" ReportNodeVersion = "0.1.0" + + // SQLVersion SQL版本号 + SQLVersion = "1" ) diff --git a/internal/nodes/api_node.go b/internal/nodes/api_node.go index aa95e78f..fb310af6 100644 --- a/internal/nodes/api_node.go +++ b/internal/nodes/api_node.go @@ -276,7 +276,7 @@ func (this *APINode) autoUpgrade() error { if err != nil { return errors.New("decode database config failed: " + err.Error()) } - dbConfig := config.DBs[Tea.Env] + var dbConfig = config.DBs[Tea.Env] db, err := dbs.NewInstanceFromConfig(dbConfig) if err != nil { return errors.New("load database failed: " + err.Error()) @@ -287,8 +287,8 @@ func (this *APINode) autoUpgrade() error { } if one != nil { // 如果是同样的版本,则直接认为是最新版本 - version := one.GetString("version") - if stringutil.VersionCompare(version, teaconst.Version) >= 0 { + var version = one.GetString("version") + if stringutil.VersionCompare(version, setup.ComposeSQLVersion()) >= 0 { return nil } } diff --git a/internal/setup/sql_executor.go b/internal/setup/sql_executor.go index 4c51c382..80bd9324 100644 --- a/internal/setup/sql_executor.go +++ b/internal/setup/sql_executor.go @@ -2,7 +2,6 @@ package setup import ( "encoding/json" - teaconst "github.com/TeaOSLab/EdgeAPI/internal/const" "github.com/TeaOSLab/EdgeAPI/internal/db/models" "github.com/TeaOSLab/EdgeAPI/internal/errors" "github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs" @@ -113,7 +112,7 @@ func (this *SQLExecutor) checkData(db *dbs.DB) error { } // 更新版本号 - err = this.updateVersion(db, teaconst.Version) + err = this.updateVersion(db, ComposeSQLVersion()) if err != nil { return err } diff --git a/internal/setup/utils.go b/internal/setup/utils.go new file mode 100644 index 00000000..c79f4da5 --- /dev/null +++ b/internal/setup/utils.go @@ -0,0 +1,20 @@ +// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package setup + +import ( + teaconst "github.com/TeaOSLab/EdgeAPI/internal/const" + "strings" +) + +func ComposeSQLVersion() string { + var version = teaconst.Version + if len(teaconst.SQLVersion) == 0 { + return version + } + + if strings.Count(version, ".") <= 2 { + return version + "." + teaconst.SQLVersion + } + return version +} diff --git a/internal/setup/utils_test.go b/internal/setup/utils_test.go new file mode 100644 index 00000000..591b7914 --- /dev/null +++ b/internal/setup/utils_test.go @@ -0,0 +1,12 @@ +// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package setup_test + +import ( + "github.com/TeaOSLab/EdgeAPI/internal/setup" + "testing" +) + +func TestComposeSQLVersion(t *testing.T) { + t.Log(setup.ComposeSQLVersion()) +}