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
Этот коммит содержится в:
Agniva De Sarker
2021-06-14 15:00:18 +05:30
коммит произвёл GitHub
родитель 3daa315028
Коммит 723902f4cb
2 изменённых файлов: 17 добавлений и 14 удалений

Просмотреть файл

@@ -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),