修复无法自动升级数据库的问题

This commit is contained in:
GoEdgeLab
2020-11-17 15:42:42 +08:00
parent a3449f028e
commit 98d4837401
3 changed files with 22 additions and 9 deletions

View File

@@ -1,7 +1,7 @@
package teaconst
const (
Version = "0.0.2"
Version = "0.0.1"
ProductName = "Edge API"
ProcessName = "edge-api"

View File

@@ -10,11 +10,14 @@ import (
"github.com/TeaOSLab/EdgeAPI/internal/setup"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/go-yaml/yaml"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/logs"
stringutil "github.com/iwind/TeaGo/utils/string"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"io/ioutil"
"net"
"os"
"strconv"
@@ -204,9 +207,24 @@ func (this *APINode) listenRPC(listener net.Listener, tlsConfig *tls.Config) err
// 自动升级
func (this *APINode) autoUpgrade() error {
db, err := dbs.Default()
if Tea.IsTesting() {
return nil
}
// 执行SQL
config := &dbs.Config{}
configData, err := ioutil.ReadFile(Tea.ConfigFile("db.yaml"))
if err != nil {
return errors.New("load database config failed: " + err.Error())
return errors.New("read database config file failed: " + err.Error())
}
err = yaml.Unmarshal(configData, config)
if err != nil {
return errors.New("decode database config failed: " + err.Error())
}
dbConfig := config.DBs[Tea.Env]
db, err := dbs.NewInstanceFromConfig(dbConfig)
if err != nil {
return errors.New("load database failed: " + err.Error())
}
one, err := db.FindOne("SELECT version FROM edgeVersions LIMIT 1")
if err != nil {
@@ -219,11 +237,6 @@ func (this *APINode) autoUpgrade() error {
return nil
}
}
dbConfig, err := db.Config()
if err != nil {
return errors.New("read db config failed: " + err.Error())
}
logs.Println("[API_NODE]upgrade database starting ...")
err = setup.NewSQLExecutor(dbConfig).Run()
if err != nil {

File diff suppressed because one or more lines are too long