diff options
author | George Goldberg <george@gberg.me> | 2018-05-14 15:59:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-14 15:59:04 +0100 |
commit | 51bd710ecdca6628461c9fa2679737073e4d5059 (patch) | |
tree | b2a4837ced3ed515ee505728917a6630b0553f76 /migrations/migrations.go | |
parent | 91557bbd978500388a11b99401783164e143a966 (diff) | |
download | chat-51bd710ecdca6628461c9fa2679737073e4d5059.tar.gz chat-51bd710ecdca6628461c9fa2679737073e4d5059.tar.bz2 chat-51bd710ecdca6628461c9fa2679737073e4d5059.zip |
MM-9728: Online migration for advanced permissions phase 2 (#8744)
* MM-9728: Online migration for advanced permissions phase 2
* Add unit tests for new store functions.
* Move migration specific code to own file.
* Add migration state function test.
* Style fixes.
* Add i18n strings.
* Fix mocks.
* Add TestMain to migrations package tests.
* Fix typo.
* Fix review comments.
* Fix up the "Check if migration is done" check to actually work.
Diffstat (limited to 'migrations/migrations.go')
-rw-r--r-- | migrations/migrations.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/migrations/migrations.go b/migrations/migrations.go new file mode 100644 index 000000000..940992839 --- /dev/null +++ b/migrations/migrations.go @@ -0,0 +1,63 @@ +// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package migrations + +import ( + "github.com/mattermost/mattermost-server/app" + tjobs "github.com/mattermost/mattermost-server/jobs/interfaces" + "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/store" +) + +const ( + MIGRATION_STATE_UNSCHEDULED = "unscheduled" + MIGRATION_STATE_IN_PROGRESS = "in_progress" + MIGRATION_STATE_COMPLETED = "completed" + + JOB_DATA_KEY_MIGRATION = "migration_key" + JOB_DATA_KEY_MIGRATION_LAST_DONE = "last_done" +) + +type MigrationsJobInterfaceImpl struct { + App *app.App +} + +func init() { + app.RegisterJobsMigrationsJobInterface(func(a *app.App) tjobs.MigrationsJobInterface { + return &MigrationsJobInterfaceImpl{a} + }) +} + +func MakeMigrationsList() []string { + return []string{ + model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, + } +} + +func GetMigrationState(migration string, store store.Store) (string, *model.Job, *model.AppError) { + if result := <-store.System().GetByName(migration); result.Err == nil { + return MIGRATION_STATE_COMPLETED, nil, nil + } + + if result := <-store.Job().GetAllByType(model.JOB_TYPE_MIGRATIONS); result.Err != nil { + return "", nil, result.Err + } else { + for _, job := range result.Data.([]*model.Job) { + if key, ok := job.Data[JOB_DATA_KEY_MIGRATION]; ok { + if key != migration { + continue + } + + switch job.Status { + case model.JOB_STATUS_IN_PROGRESS, model.JOB_STATUS_PENDING: + return MIGRATION_STATE_IN_PROGRESS, job, nil + default: + return MIGRATION_STATE_UNSCHEDULED, job, nil + } + } + } + } + + return MIGRATION_STATE_UNSCHEDULED, nil, nil +} |