mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	修复无法自动升级数据库的问题
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
			
		||||
package teaconst
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	Version = "0.0.2"
 | 
			
		||||
	Version = "0.0.1"
 | 
			
		||||
 | 
			
		||||
	ProductName   = "Edge API"
 | 
			
		||||
	ProcessName   = "edge-api"
 | 
			
		||||
 
 | 
			
		||||
@@ -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
											
										
									
								
							
		Reference in New Issue
	
	Block a user