Skip to content

Commit

Permalink
Merge pull request #3535 from element-hq/feature/bma/alwaysMigrateApp
Browse files Browse the repository at this point in the history
Perform the migration, even if the current version is not known.
  • Loading branch information
ganfra authored Sep 25, 2024
2 parents ae7a79e + 23ed755 commit 14dc0da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ class MigrationPresenter @Inject constructor(
LaunchedEffect(migrationStoreVersion) {
val migrationValue = migrationStoreVersion ?: return@LaunchedEffect
if (migrationValue == -1) {
// Fresh install, no migration needed
Timber.d("Fresh install, no migration needed.")
migrationStore.setApplicationMigrationVersion(lastMigration)
return@LaunchedEffect
Timber.d("Fresh install, or previous installed application did not have the migration mechanism.")
}
if (migrationValue == lastMigration) {
Timber.d("Current app migration version: $migrationValue. No migration needed.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ class MigrationPresenterTest {
val warmUpRule = WarmUpRule()

@Test
fun `present - no migration should occurs on fresh installation, and last version should be stored`() = runTest {
fun `present - run all migrations on fresh installation, and last version should be stored`() = runTest {
val migrations = (1..10).map { order ->
FakeAppMigration(
order = order,
migrateLambda = LambdaNoParamRecorder(ensureNeverCalled = true) { },
)
FakeAppMigration(order = order)
}
val store = InMemoryMigrationStore(initialApplicationMigrationVersion = -1)
val presenter = createPresenter(
Expand All @@ -44,12 +41,15 @@ class MigrationPresenterTest {
}.test {
val initialState = awaitItem()
assertThat(initialState.migrationAction).isEqualTo(AsyncData.Uninitialized)
skipItems(1)
skipItems(migrations.size)
awaitItem().also { state ->
assertThat(state.migrationAction).isEqualTo(AsyncData.Success(Unit))
}
assertThat(store.applicationMigrationVersion().first()).isEqualTo(migrations.maxOf { it.order })
}
for (migration in migrations) {
migration.migrateLambda.assertions().isCalledOnce()
}
}

@Test
Expand Down

0 comments on commit 14dc0da

Please sign in to comment.