Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3-bug-fixes/WPB-4425-fix-es-migration-script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ES migration script.
17 changes: 9 additions & 8 deletions services/brig/src/Brig/Index/Migrations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,21 @@ failIfIndexAbsent targetIndex =

-- | Runs only the migrations which need to run
runMigration :: MigrationVersion -> MigrationActionT IO ()
runMigration ver = do
vmax <- latestMigrationVersion
if ver > vmax
runMigration expectedVersion = do
foundVersion <- latestMigrationVersion
if expectedVersion > foundVersion
then do
Log.info $
Log.msg (Log.val "Migration necessary.")
. Log.field "expectedVersion" vmax
. Log.field "foundVersion" ver
. Log.field "expectedVersion" expectedVersion
. Log.field "foundVersion" foundVersion
Search.reindexAllIfSameOrNewer
persistVersion ver
persistVersion expectedVersion
else do
Log.info $
Log.msg (Log.val "No migration necessary.")
. Log.field "expectedVersion" vmax
. Log.field "foundVersion" ver
. Log.field "expectedVersion" expectedVersion
. Log.field "foundVersion" foundVersion

persistVersion :: (MonadThrow m, MonadIO m) => MigrationVersion -> MigrationActionT m ()
persistVersion v =
Expand All @@ -148,6 +148,7 @@ persistVersion v =
. Log.field "migrationVersion" v
else throwM $ PersistVersionFailed v $ show persistResponse

-- | Which version is the table space currently running on?
latestMigrationVersion :: (MonadThrow m, MonadIO m) => MigrationActionT m MigrationVersion
latestMigrationVersion = do
resp <- ES.parseEsResponse =<< ES.searchByIndex indexName (ES.mkSearch Nothing Nothing)
Expand Down