MM-35030: Hoist GetDBVersion before creating store (#17764)
* MM-35030: Hoist GetDBVersion before creating store The creation of the store included running the migrations which means that SQL statements would be executed before we could make the check for DB version. We perform the DB check before running the migrations. https://mattermost.atlassian.net/browse/MM-35030 ```release-note NONE ``` * fix lint error
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3daa315028
Коммит
723902f4cb
@@ -20,7 +20,6 @@ import (
|
||||
"os/exec"
|
||||
"path"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -360,19 +359,6 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
if s.newStore == nil {
|
||||
s.newStore = func() (store.Store, error) {
|
||||
s.sqlStore = sqlstore.New(s.Config().SqlSettings, s.Metrics)
|
||||
if s.sqlStore.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||
ver, err2 := s.sqlStore.GetDbVersion(true)
|
||||
if err2 != nil {
|
||||
return nil, errors.Wrap(err2, "cannot get DB version")
|
||||
}
|
||||
intVer, err2 := strconv.Atoi(ver)
|
||||
if err2 != nil {
|
||||
return nil, errors.Wrap(err2, "cannot parse DB version")
|
||||
}
|
||||
if intVer < sqlstore.MinimumRequiredPostgresVersion {
|
||||
return nil, fmt.Errorf("minimum required postgres version is %s; found %s", sqlstore.VersionString(sqlstore.MinimumRequiredPostgresVersion), sqlstore.VersionString(intVer))
|
||||
}
|
||||
}
|
||||
|
||||
lcl, err2 := localcachelayer.NewLocalCacheLayer(
|
||||
retrylayer.New(s.sqlStore),
|
||||
|
||||
@@ -179,6 +179,23 @@ func New(settings model.SqlSettings, metrics einterfaces.MetricsInterface) *SqlS
|
||||
|
||||
store.initConnection()
|
||||
|
||||
if *settings.DriverName == model.DATABASE_DRIVER_POSTGRES {
|
||||
ver, err := store.GetDbVersion(true)
|
||||
if err != nil {
|
||||
mlog.Critical("Cannot get DB version.", mlog.Err(err))
|
||||
os.Exit(ExitGenericFailure)
|
||||
}
|
||||
intVer, err := strconv.Atoi(ver)
|
||||
if err != nil {
|
||||
mlog.Critical("Cannot parse DB version.", mlog.Err(err))
|
||||
os.Exit(ExitGenericFailure)
|
||||
}
|
||||
if intVer < MinimumRequiredPostgresVersion {
|
||||
mlog.Critical("Minimum Postgres version requirements not met.", mlog.String("Found", VersionString(intVer)), mlog.String("Wanted", VersionString(MinimumRequiredPostgresVersion)))
|
||||
os.Exit(ExitGenericFailure)
|
||||
}
|
||||
}
|
||||
|
||||
err := store.migrate(migrationsDirectionUp)
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to apply database migrations.", mlog.Err(err))
|
||||
|
||||
Ссылка в новой задаче
Block a user