mirror of
https://github.com/documize/community.git
synced 2025-07-24 15:49:44 +02:00
Add dbtype command line switch and improved database type detection
Closes #116 and #117
This commit is contained in:
parent
d3512b499a
commit
e505bb36e2
10 changed files with 659 additions and 644 deletions
|
@ -34,7 +34,7 @@ func Check(runtime *env.Runtime) bool {
|
|||
web.SiteInfo.DBname = strings.Split(csBits[len(csBits)-1], "?")[0]
|
||||
}
|
||||
|
||||
rows, err := runtime.Db.Query("SELECT VERSION() AS version, @@version_comment as comment, @@character_set_database AS charset, @@collation_database AS collation;")
|
||||
rows, err := runtime.Db.Query("SELECT VERSION() AS version, @@version_comment as comment, @@character_set_database AS charset, @@collation_database AS collation")
|
||||
if err != nil {
|
||||
runtime.Log.Error("Can't get MySQL configuration", err)
|
||||
web.SiteInfo.Issue = "Can't get MySQL configuration: " + err.Error()
|
||||
|
@ -61,7 +61,7 @@ func Check(runtime *env.Runtime) bool {
|
|||
// Get SQL variant as this affects minimum version checking logic.
|
||||
// MySQL and Percona share same version scheme (e..g 5.7.10).
|
||||
// MariaDB starts at 10.2.x
|
||||
runtime.DbVariant = GetSQLVariant(dbComment)
|
||||
runtime.DbVariant = GetSQLVariant(runtime.Flags.DBType, dbComment)
|
||||
runtime.Log.Info(fmt.Sprintf("Database checks: SQL variant %v", runtime.DbVariant))
|
||||
runtime.Log.Info("Database checks: SQL version " + version)
|
||||
|
||||
|
@ -142,9 +142,11 @@ func Check(runtime *env.Runtime) bool {
|
|||
}
|
||||
|
||||
// GetSQLVariant uses database value form @@version_comment to deduce MySQL variant.
|
||||
func GetSQLVariant(vc string) env.DbVariant {
|
||||
func GetSQLVariant(dbType, vc string) env.DbVariant {
|
||||
vc = strings.ToLower(vc)
|
||||
dbType = strings.ToLower(dbType)
|
||||
|
||||
// determine type from database
|
||||
if strings.Contains(vc, "mariadb") {
|
||||
return env.DBVariantMariaDB
|
||||
} else if strings.Contains(vc, "percona") {
|
||||
|
@ -153,7 +155,17 @@ func GetSQLVariant(vc string) env.DbVariant {
|
|||
return env.DbVariantMySQL
|
||||
}
|
||||
|
||||
return "UNKNOWN"
|
||||
// now determine type from command line switch
|
||||
if strings.Contains(dbType, "mariadb") {
|
||||
return env.DBVariantMariaDB
|
||||
} else if strings.Contains(dbType, "percona") {
|
||||
return env.DBVariantPercona
|
||||
} else if strings.Contains(dbType, "mysql") {
|
||||
return env.DbVariantMySQL
|
||||
}
|
||||
|
||||
// horrid default could cause app to crash
|
||||
return env.DbVariantMySQL
|
||||
}
|
||||
|
||||
// GetSQLVersion returns SQL version as major,minor,patch numerics.
|
||||
|
|
|
@ -125,7 +125,7 @@ func lockDB(runtime *env.Runtime) (bool, error) {
|
|||
if err != nil {
|
||||
// good error would be "Error 1062: Duplicate entry 'DBLOCK' for key 'idx_config_area'"
|
||||
if strings.HasPrefix(err.Error(), "Error 1062:") {
|
||||
runtime.Log.Info("Database locked by annother Documize instance")
|
||||
runtime.Log.Info("Database locked by another Documize instance")
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
|
|
5
core/env/flags.go
vendored
5
core/env/flags.go
vendored
|
@ -25,6 +25,7 @@ import (
|
|||
type Flags struct {
|
||||
DBConn string // database connection string
|
||||
Salt string // the salt string used to encode JWT tokens
|
||||
DBType string // (optional) database type
|
||||
SSLCertFile string // (optional) name of SSL certificate PEM file
|
||||
SSLKeyFile string // (optional) name of SSL key PEM file
|
||||
HTTPPort string // (optional) HTTP or HTTPS port
|
||||
|
@ -71,7 +72,7 @@ var loadMutex sync.Mutex
|
|||
|
||||
// ParseFlags loads command line and OS environment variables required by the program to function.
|
||||
func ParseFlags() (f Flags) {
|
||||
var dbConn, jwtKey, siteMode, port, certFile, keyFile, forcePort2SSL string
|
||||
var dbConn, dbType, jwtKey, siteMode, port, certFile, keyFile, forcePort2SSL string
|
||||
|
||||
register(&jwtKey, "salt", false, "the salt string used to encode JWT tokens, if not set a random value will be generated")
|
||||
register(&certFile, "cert", false, "the cert.pem file used for https")
|
||||
|
@ -79,6 +80,7 @@ func ParseFlags() (f Flags) {
|
|||
register(&port, "port", false, "http/https port number")
|
||||
register(&forcePort2SSL, "forcesslport", false, "redirect given http port number to TLS")
|
||||
register(&siteMode, "offline", false, "set to '1' for OFFLINE mode")
|
||||
register(&dbType, "dbtype", false, "set to database type mysql|percona|mariadb")
|
||||
register(&dbConn, "db", true, `'username:password@protocol(hostname:port)/databasename" for example "fred:bloggs@tcp(localhost:3306)/documize"`)
|
||||
|
||||
parse("db")
|
||||
|
@ -90,6 +92,7 @@ func ParseFlags() (f Flags) {
|
|||
f.SiteMode = siteMode
|
||||
f.SSLCertFile = certFile
|
||||
f.SSLKeyFile = keyFile
|
||||
f.DBType = dbType
|
||||
|
||||
return f
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue