Skip to content

Commit 14dc0da

Browse files
authored
Merge pull request #3535 from element-hq/feature/bma/alwaysMigrateApp
Perform the migration, even if the current version is not known.
2 parents ae7a79e + 23ed755 commit 14dc0da

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

features/migration/impl/src/main/kotlin/io/element/android/features/migration/impl/MigrationPresenter.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ class MigrationPresenter @Inject constructor(
4545
LaunchedEffect(migrationStoreVersion) {
4646
val migrationValue = migrationStoreVersion ?: return@LaunchedEffect
4747
if (migrationValue == -1) {
48-
// Fresh install, no migration needed
49-
Timber.d("Fresh install, no migration needed.")
50-
migrationStore.setApplicationMigrationVersion(lastMigration)
51-
return@LaunchedEffect
48+
Timber.d("Fresh install, or previous installed application did not have the migration mechanism.")
5249
}
5350
if (migrationValue == lastMigration) {
5451
Timber.d("Current app migration version: $migrationValue. No migration needed.")

features/migration/impl/src/test/kotlin/io/element/android/features/migration/impl/MigrationPresenterTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ class MigrationPresenterTest {
2727
val warmUpRule = WarmUpRule()
2828

2929
@Test
30-
fun `present - no migration should occurs on fresh installation, and last version should be stored`() = runTest {
30+
fun `present - run all migrations on fresh installation, and last version should be stored`() = runTest {
3131
val migrations = (1..10).map { order ->
32-
FakeAppMigration(
33-
order = order,
34-
migrateLambda = LambdaNoParamRecorder(ensureNeverCalled = true) { },
35-
)
32+
FakeAppMigration(order = order)
3633
}
3734
val store = InMemoryMigrationStore(initialApplicationMigrationVersion = -1)
3835
val presenter = createPresenter(
@@ -44,12 +41,15 @@ class MigrationPresenterTest {
4441
}.test {
4542
val initialState = awaitItem()
4643
assertThat(initialState.migrationAction).isEqualTo(AsyncData.Uninitialized)
47-
skipItems(1)
44+
skipItems(migrations.size)
4845
awaitItem().also { state ->
4946
assertThat(state.migrationAction).isEqualTo(AsyncData.Success(Unit))
5047
}
5148
assertThat(store.applicationMigrationVersion().first()).isEqualTo(migrations.maxOf { it.order })
5249
}
50+
for (migration in migrations) {
51+
migration.migrateLambda.assertions().isCalledOnce()
52+
}
5353
}
5454

5555
@Test

0 commit comments

Comments
 (0)