Files
mostlymatter/migrations/migrations.go
Agniva De Sarker c4b4e1bc38 MM-36271: Bump major version to 6.0 (#17973)
https://mattermost.atlassian.net/browse/MM-36271

```release-note
We bump the major version to 6.0
```
2021-07-22 12:21:47 +05:30

67 строки
1.7 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package migrations
import (
"net/http"
"github.com/mattermost/mattermost-server/v6/app"
tjobs "github.com/mattermost/mattermost-server/v6/jobs/interfaces"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/store"
)
const (
MigrationStateUnscheduled = "unscheduled"
MigrationStateInProgress = "in_progress"
MigrationStateCompleted = "completed"
JobDataKeyMigration = "migration_key"
JobDataKeyMigrationLastDone = "last_done"
)
type MigrationsJobInterfaceImpl struct {
srv *app.Server
}
func init() {
app.RegisterJobsMigrationsJobInterface(func(s *app.Server) tjobs.MigrationsJobInterface {
return &MigrationsJobInterfaceImpl{s}
})
}
func MakeMigrationsList() []string {
return []string{
model.MigrationKeyAdvancedPermissionsPhase2,
}
}
func GetMigrationState(migration string, store store.Store) (string, *model.Job, *model.AppError) {
if _, err := store.System().GetByName(migration); err == nil {
return MigrationStateCompleted, nil, nil
}
jobs, err := store.Job().GetAllByType(model.JobTypeMigrations)
if err != nil {
return "", nil, model.NewAppError("GetMigrationState", "app.job.get_all.app_error", nil, err.Error(), http.StatusInternalServerError)
}
for _, job := range jobs {
if key, ok := job.Data[JobDataKeyMigration]; ok {
if key != migration {
continue
}
switch job.Status {
case model.JobStatusInProgress, model.JobStatusPending:
return MigrationStateInProgress, job, nil
default:
return MigrationStateUnscheduled, job, nil
}
}
}
return MigrationStateUnscheduled, nil, nil
}