mirror of
https://github.com/documize/community.git
synced 2025-07-23 15:19:42 +02:00
fixed mysql version detection bug
This commit is contained in:
parent
72916ed93d
commit
5f1fed0206
4 changed files with 823 additions and 636 deletions
|
@ -17,9 +17,9 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/documize/community/core/web"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/utility"
|
||||
"github.com/documize/community/core/web"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
|
@ -62,11 +62,6 @@ func Check(Db *sqlx.DB, connectionString string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// See http://dba.stackexchange.com/questions/63763/is-there-any-difference-between-these-two-version-of-mysql-5-1-73-community-lo
|
||||
version = strings.Replace(version, "-log", "", 1)
|
||||
version = strings.Replace(version, "-debug", "", 1)
|
||||
version = strings.Replace(version, "-demo", "", 1)
|
||||
|
||||
{ // check minimum MySQL version as we need JSON column type. 5.7.10
|
||||
vParts := strings.Split(version, ".")
|
||||
if len(vParts) < 3 {
|
||||
|
@ -77,13 +72,16 @@ func Check(Db *sqlx.DB, connectionString string) bool {
|
|||
}
|
||||
verInts := []int{5, 7, 10} // Minimum MySQL version
|
||||
for k, v := range verInts {
|
||||
i, err := strconv.Atoi(vParts[k])
|
||||
if err != nil {
|
||||
log.Error("MySQL version element "+strconv.Itoa(k+1)+" of '"+version+"' not an integer:", err)
|
||||
web.SiteInfo.Issue = "MySQL version element " + strconv.Itoa(k+1) + " of '" + version + "' not an integer: " + err.Error()
|
||||
web.SiteMode = web.SiteModeBadDB
|
||||
return false
|
||||
}
|
||||
i := ExtractVersionNumber(vParts[k])
|
||||
|
||||
// i, err := strconv.Atoi(vParts[k])
|
||||
// if err != nil {
|
||||
// log.Error("MySQL version element "+strconv.Itoa(k+1)+" of '"+version+"' not an integer:", err)
|
||||
// web.SiteInfo.Issue = "MySQL version element " + strconv.Itoa(k+1) + " of '" + version + "' not an integer: " + err.Error()
|
||||
// web.SiteMode = web.SiteModeBadDB
|
||||
// return false
|
||||
// }
|
||||
|
||||
if i < v {
|
||||
want := fmt.Sprintf("%d.%d.%d", verInts[0], verInts[1], verInts[2])
|
||||
log.Error("MySQL version element "+strconv.Itoa(k+1)+" of '"+version+"' not high enough, need at least version "+want, errors.New("bad MySQL version"))
|
||||
|
@ -148,3 +146,36 @@ func Check(Db *sqlx.DB, connectionString string) bool {
|
|||
dbCheckOK = true
|
||||
return true
|
||||
}
|
||||
|
||||
// ExtractVersionNumber checks and sends back an integer.
|
||||
// MySQL can have version numbers like 5.5.47-0ubuntu0.14.04.1
|
||||
func ExtractVersionNumber(s string) (num int) {
|
||||
num = 0
|
||||
|
||||
// deal with build suffixes
|
||||
// http://dba.stackexchange.com/questions/63763/is-there-any-difference-between-these-two-version-of-mysql-5-1-73-community-lo
|
||||
s = strings.Replace(s, "-log", "", 1)
|
||||
s = strings.Replace(s, "-debug", "", 1)
|
||||
s = strings.Replace(s, "-demo", "", 1)
|
||||
|
||||
// convert to number
|
||||
num, err := strconv.Atoi(s)
|
||||
|
||||
if err != nil {
|
||||
num = 0
|
||||
// probably found "47-0ubuntu0.14.04.1" so we need to lose everything after the hypen
|
||||
pos := strings.Index(s, "-")
|
||||
if pos > 1 {
|
||||
num, err = strconv.Atoi(s[:pos])
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
num = 0
|
||||
log.Error("MySQL version element '"+s+"' not an integer:", err)
|
||||
web.SiteInfo.Issue = "MySQL version element '" + s + "' not an integer: " + err.Error()
|
||||
web.SiteMode = web.SiteModeBadDB
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -11,3 +11,21 @@
|
|||
|
||||
package database
|
||||
|
||||
import "testing"
|
||||
|
||||
// go test github.com/documize/community/core/database -run TestVersionExtract
|
||||
func TestVersionExtract(t *testing.T) {
|
||||
ts(t, "5", 5)
|
||||
ts(t, "45-0ubuntu0-12.12.3", 45)
|
||||
ts(t, "untu0-12.12.3", 0)
|
||||
ts(t, "junk-string", 0)
|
||||
ts(t, "somethingstring", 0)
|
||||
}
|
||||
|
||||
func ts(t *testing.T, in string, out int) {
|
||||
got := ExtractVersionNumber(in)
|
||||
|
||||
if got != out {
|
||||
t.Errorf("version input `%s` got `%d` expected `%d`\n", in, got, out)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ type ProdInfo struct {
|
|||
func Product() (p ProdInfo) {
|
||||
p.Major = "0"
|
||||
p.Minor = "24"
|
||||
p.Patch = "0"
|
||||
p.Patch = "1"
|
||||
p.Version = fmt.Sprintf("%s.%s.%s", p.Major, p.Minor, p.Patch)
|
||||
p.Edition = "Community"
|
||||
p.Title = fmt.Sprintf("%s Edition", p.Edition)
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue