[MM-41576] Revamp database schema version (#19586)

* revamp db version and add applied migrations endpoint

* replace old schema version with new

* add db version subcommand

* add to local api

* reflect review comments

* log errors

* remove setting the version from model.CurrentVersion

* fix a test
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2022-03-08 18:13:37 +03:00
коммит произвёл GitHub
родитель 05503440a6
Коммит 645fee3fe3
37 изменённых файлов: 379 добавлений и 46 удалений

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

@@ -20,6 +20,7 @@ import (
"os/exec"
"path"
"runtime"
"strconv"
"strings"
"sync"
"sync/atomic"
@@ -752,8 +753,8 @@ func (s *Server) Channels() *Channels {
// Return Database type (postgres or mysql) and current version of Mattermost
func (s *Server) DatabaseTypeAndMattermostVersion() (string, string) {
mattermostVersion, _ := s.Store.System().GetByName("Version")
return *s.Config().SqlSettings.DriverName, mattermostVersion.Value
schemaVersion, _ := s.Store.GetDBSchemaVersion()
return *s.Config().SqlSettings.DriverName, strconv.Itoa(schemaVersion)
}
// initLogging initializes and configures the logger(s). This may be called more than once.
@@ -2304,3 +2305,11 @@ func runDNDStatusExpireJob(a *App) {
}
})
}
func (a *App) GetAppliedSchemaMigrations() ([]model.AppliedMigration, *model.AppError) {
table, err := a.Srv().Store.GetAppliedMigrations()
if err != nil {
return nil, model.NewAppError("GetDBSchemaTable", "api.file.read_file.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return table, nil
}