mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	修复4位版本号导致无法自动升级SQL的问题
This commit is contained in:
		@@ -4,17 +4,31 @@ package setup
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
	stringutil "github.com/iwind/TeaGo/utils/string"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// ComposeSQLVersion 组合SQL的版本号
 | 
			
		||||
func ComposeSQLVersion() string {
 | 
			
		||||
	var version = teaconst.Version
 | 
			
		||||
	if len(teaconst.SQLVersion) == 0 {
 | 
			
		||||
		return version
 | 
			
		||||
	return teaconst.Version
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CompareVersion 对比版本
 | 
			
		||||
func CompareVersion(version1 string, version2 string) int8 {
 | 
			
		||||
	if len(version1) == 0 || len(version2) == 0 {
 | 
			
		||||
		return 0
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if strings.Count(version, ".") <= 2 {
 | 
			
		||||
		return version + "." + teaconst.SQLVersion
 | 
			
		||||
	return stringutil.VersionCompare(fixVersion(version1), fixVersion(version2))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func fixVersion(version string) string {
 | 
			
		||||
	var pieces = strings.Split(version, ".")
 | 
			
		||||
	var lastPiece = types.Int(pieces[len(pieces)-1])
 | 
			
		||||
	if lastPiece > 10 {
 | 
			
		||||
		// 这个是以前使用的SQL版本号,我们给去掉
 | 
			
		||||
		version = strings.Join(pieces[:len(pieces)-1], ".")
 | 
			
		||||
	}
 | 
			
		||||
	return version
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user