1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00

Add dbtype command line switch and improved database type detection

Closes #116 and #117
This commit is contained in:
Harvey Kandola 2017-08-30 13:00:07 +01:00
parent d3512b499a
commit e505bb36e2
10 changed files with 659 additions and 644 deletions

View file

@ -8,7 +8,7 @@ The mission is to bring software dev inspired features (refactoring, testing, li
## Latest version
v1.53.2
v1.53.3
## OS Support

View file

@ -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.

View file

@ -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
View file

@ -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
}

View file

@ -38,7 +38,7 @@ func main() {
rt.Product = env.ProdInfo{}
rt.Product.Major = "1"
rt.Product.Minor = "53"
rt.Product.Patch = "2"
rt.Product.Patch = "3"
rt.Product.Version = fmt.Sprintf("%s.%s.%s", rt.Product.Major, rt.Product.Minor, rt.Product.Patch)
rt.Product.Edition = "Community"
rt.Product.Title = fmt.Sprintf("%s Edition", rt.Product.Edition)

File diff suppressed because one or more lines are too long

View file

@ -67,7 +67,7 @@ export default Ember.Route.extend(ApplicationRouteMixin, TooltipMixin, {
console.log(transition); // eslint-disable-line no-console
if (netUtil.isAjaxAccessError(error) && !this.get('appMeta.setupMode')) {
localStorage.clearAll();
this.get('localStorage').clearAll();
return this.transitionTo('auth.login');
}
}

View file

@ -32,7 +32,7 @@
width: 100%;
border: none;
border-bottom: 1px solid $color-input;
height: 2.3rem;
height: 2.5rem;
outline: none;
&:focus {
@ -57,7 +57,7 @@
padding: 5px;
border: 1px solid $color-input;
border-radius: 2px;
height: 2.3rem;
height: 2.5rem;
font-size: 1rem;
display: inline-block;

View file

@ -1,6 +1,6 @@
{
"name": "documize",
"version": "1.53.2",
"version": "1.53.3",
"description": "The Document IDE",
"private": true,
"repository": "",

View file

@ -1,16 +1,16 @@
{
"community":
{
"version": "1.53.2",
"version": "1.53.3",
"major": 1,
"minor": 53,
"patch": 2
"patch": 3
},
"enterprise":
{
"version": "1.55.2",
"version": "1.55.3",
"major": 1,
"minor": 55,
"patch": 2
"patch": 3
}
}