MariaDB: Allow unsupported versions in "unsafe" mode #2878

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2022-11-10 07:21:45 +01:00
parent 5e28c02041
commit 2f6e57527b
2 changed files with 27 additions and 16 deletions

View file

@ -627,7 +627,7 @@ func (c *Config) Workers() int {
// required for face recognition and index maintenance(1-86400s).
func (c *Config) WakeupInterval() time.Duration {
if c.options.WakeupInterval <= 0 {
if c.options.Unsafe {
if c.Unsafe() {
// Worker can be disabled only in unsafe mode.
return time.Duration(0)
} else {

View file

@ -308,6 +308,28 @@ func (c *Config) InitTestDb() {
go entity.Error{}.LogEvents()
}
// connectDb checks the database server version.
func (c *Config) checkDb(db *gorm.DB) error {
switch c.DatabaseDriver() {
case MySQL:
type Res struct {
Value string `gorm:"column:Value;"`
}
var res Res
if err := db.Raw("SHOW VARIABLES LIKE 'innodb_version'").Scan(&res).Error; err != nil {
return err
} else if v := strings.Split(res.Value, "."); len(v) < 3 {
log.Warnf("config: unknown database server version")
} else if major := txt.UInt(v[0]); major < 10 {
return fmt.Errorf("config: MySQL %s is not supported, see https://docs.photoprism.app/getting-started/#databases", res.Value)
} else if sub := txt.UInt(v[1]); sub < 5 || sub == 5 && txt.UInt(v[2]) < 12 {
return fmt.Errorf("config: MariaDB %s is not supported, see https://docs.photoprism.app/getting-started/#databases", res.Value)
}
}
return nil
}
// connectDb establishes a database connection.
func (c *Config) connectDb() error {
// Make sure this is not running twice.
@ -354,21 +376,10 @@ func (c *Config) connectDb() error {
db.DB().SetConnMaxLifetime(time.Hour)
// Check database server version.
switch dbDriver {
case MySQL:
type Res struct {
Value string `gorm:"column:Value;"`
}
var res Res
if err = db.Raw("SHOW VARIABLES LIKE 'innodb_version'").Scan(&res).Error; err != nil {
return err
} else if v := strings.Split(res.Value, "."); len(v) < 3 {
log.Warnf("config: unknown database server version")
} else if major := txt.UInt(v[0]); major < 10 {
err = fmt.Errorf("config: MySQL %s is not supported, see https://docs.photoprism.app/getting-started/#databases", res.Value)
return err
} else if sub := txt.UInt(v[1]); sub < 5 || sub == 5 && txt.UInt(v[2]) < 12 {
err = fmt.Errorf("config: MariaDB %s is not supported, see https://docs.photoprism.app/getting-started/#databases", res.Value)
if err = c.checkDb(db); err != nil {
if c.Unsafe() {
log.Error(err)
} else {
return err
}
}