mirror of
https://github.com/documize/community.git
synced 2025-07-21 22:29:41 +02:00
parent
d45aa70157
commit
db1af55c6c
3 changed files with 33 additions and 20 deletions
|
@ -22,11 +22,6 @@ import (
|
||||||
"github.com/documize/community/server/web"
|
"github.com/documize/community/server/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
// sql variantsa
|
|
||||||
const sqlVariantMySQL string = "MySQL"
|
|
||||||
const sqlVariantPercona string = "Percona"
|
|
||||||
const sqlVariantMariaDB string = "MariaDB"
|
|
||||||
|
|
||||||
var dbCheckOK bool // default false
|
var dbCheckOK bool // default false
|
||||||
|
|
||||||
// Check that the database is configured correctly and that all the required tables exist.
|
// Check that the database is configured correctly and that all the required tables exist.
|
||||||
|
@ -66,8 +61,8 @@ func Check(runtime *env.Runtime) bool {
|
||||||
// Get SQL variant as this affects minimum version checking logic.
|
// Get SQL variant as this affects minimum version checking logic.
|
||||||
// MySQL and Percona share same version scheme (e..g 5.7.10).
|
// MySQL and Percona share same version scheme (e..g 5.7.10).
|
||||||
// MariaDB starts at 10.2.x
|
// MariaDB starts at 10.2.x
|
||||||
sqlVariant := GetSQLVariant(dbComment)
|
runtime.DbVariant = GetSQLVariant(dbComment)
|
||||||
runtime.Log.Info("Database checks: SQL variant " + sqlVariant)
|
runtime.Log.Info(fmt.Sprintf("Database checks: SQL variant %v", runtime.DbVariant))
|
||||||
runtime.Log.Info("Database checks: SQL version " + version)
|
runtime.Log.Info("Database checks: SQL version " + version)
|
||||||
|
|
||||||
verNums, err := GetSQLVersion(version)
|
verNums, err := GetSQLVersion(version)
|
||||||
|
@ -77,7 +72,7 @@ func Check(runtime *env.Runtime) bool {
|
||||||
|
|
||||||
// Check minimum MySQL version as we need JSON column type.
|
// Check minimum MySQL version as we need JSON column type.
|
||||||
verInts := []int{5, 7, 10} // Minimum MySQL version
|
verInts := []int{5, 7, 10} // Minimum MySQL version
|
||||||
if sqlVariant == sqlVariantMariaDB {
|
if runtime.DbVariant == env.DBVariantMariaDB {
|
||||||
verInts = []int{10, 2, 0} // Minimum MariaDB version
|
verInts = []int{10, 2, 0} // Minimum MariaDB version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,8 +88,8 @@ func Check(runtime *env.Runtime) bool {
|
||||||
|
|
||||||
{ // check the MySQL character set and collation
|
{ // check the MySQL character set and collation
|
||||||
if charset != "utf8" && charset != "utf8mb4" {
|
if charset != "utf8" && charset != "utf8mb4" {
|
||||||
runtime.Log.Error("MySQL character set not utf8:", errors.New(charset))
|
runtime.Log.Error("MySQL character set not utf8/utf8mb4:", errors.New(charset))
|
||||||
web.SiteInfo.Issue = "MySQL character set not utf8: " + charset
|
web.SiteInfo.Issue = "MySQL character set not utf8/utf8mb4: " + charset
|
||||||
runtime.Flags.SiteMode = env.SiteModeBadDB
|
runtime.Flags.SiteMode = env.SiteModeBadDB
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -147,15 +142,15 @@ func Check(runtime *env.Runtime) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSQLVariant uses database value form @@version_comment to deduce MySQL variant.
|
// GetSQLVariant uses database value form @@version_comment to deduce MySQL variant.
|
||||||
func GetSQLVariant(vc string) string {
|
func GetSQLVariant(vc string) env.DbVariant {
|
||||||
vc = strings.ToLower(vc)
|
vc = strings.ToLower(vc)
|
||||||
|
|
||||||
if strings.Contains(vc, "mariadb") {
|
if strings.Contains(vc, "mariadb") {
|
||||||
return sqlVariantMariaDB
|
return env.DBVariantMariaDB
|
||||||
} else if strings.Contains(vc, "percona") {
|
} else if strings.Contains(vc, "percona") {
|
||||||
return sqlVariantPercona
|
return env.DBVariantPercona
|
||||||
} else if strings.Contains(vc, "mysql") {
|
} else if strings.Contains(vc, "mysql") {
|
||||||
return sqlVariantMySQL
|
return env.DbVariantMySQL
|
||||||
}
|
}
|
||||||
|
|
||||||
return "UNKNOWN"
|
return "UNKNOWN"
|
||||||
|
|
|
@ -78,7 +78,7 @@ func (m migrationsT) migrate(runtime *env.Runtime, tx *sqlx.Tx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = processSQLfile(tx, buf)
|
err = processSQLfile(tx, runtime.DbVariant, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -247,10 +247,15 @@ func Migrate(runtime *env.Runtime, ConfigTableExists bool) error {
|
||||||
return migrateEnd(runtime, tx, nil, amLeader)
|
return migrateEnd(runtime, tx, nil, amLeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func processSQLfile(tx *sqlx.Tx, buf []byte) error {
|
func processSQLfile(tx *sqlx.Tx, v env.DbVariant, buf []byte) error {
|
||||||
stmts := getStatements(buf)
|
stmts := getStatements(buf)
|
||||||
|
|
||||||
for _, stmt := range stmts {
|
for _, stmt := range stmts {
|
||||||
|
// MariaDB has no specific JSON column type (but has JSON queries)
|
||||||
|
if v == env.DBVariantMariaDB {
|
||||||
|
stmt = strings.Replace(stmt, "` JSON", "` TEXT", -1)
|
||||||
|
}
|
||||||
|
|
||||||
_, err := tx.Exec(stmt)
|
_, err := tx.Exec(stmt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
13
core/env/runtime.go
vendored
13
core/env/runtime.go
vendored
|
@ -19,6 +19,7 @@ import "github.com/jmoiron/sqlx"
|
||||||
type Runtime struct {
|
type Runtime struct {
|
||||||
Flags Flags
|
Flags Flags
|
||||||
Db *sqlx.DB
|
Db *sqlx.DB
|
||||||
|
DbVariant DbVariant
|
||||||
Log Logger
|
Log Logger
|
||||||
Product ProdInfo
|
Product ProdInfo
|
||||||
}
|
}
|
||||||
|
@ -33,3 +34,15 @@ const (
|
||||||
// SiteModeBadDB redirects to db-error.html page
|
// SiteModeBadDB redirects to db-error.html page
|
||||||
SiteModeBadDB = "3"
|
SiteModeBadDB = "3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DbVariant details SQL database variant
|
||||||
|
type DbVariant string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// DbVariantMySQL is MySQL
|
||||||
|
DbVariantMySQL DbVariant = "MySQL"
|
||||||
|
// DBVariantPercona is Percona
|
||||||
|
DBVariantPercona DbVariant = "Percona"
|
||||||
|
// DBVariantMariaDB is MariaDB
|
||||||
|
DBVariantMariaDB DbVariant = "MariaDB"
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue