mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-04 20:01:55 +00:00
Merge pull request #3535 from element-hq/feature/bma/alwaysMigrateApp
Perform the migration, even if the current version is not known.
This commit is contained in:
+1
-4
@@ -45,10 +45,7 @@ class MigrationPresenter @Inject constructor(
|
|||||||
LaunchedEffect(migrationStoreVersion) {
|
LaunchedEffect(migrationStoreVersion) {
|
||||||
val migrationValue = migrationStoreVersion ?: return@LaunchedEffect
|
val migrationValue = migrationStoreVersion ?: return@LaunchedEffect
|
||||||
if (migrationValue == -1) {
|
if (migrationValue == -1) {
|
||||||
// Fresh install, no migration needed
|
Timber.d("Fresh install, or previous installed application did not have the migration mechanism.")
|
||||||
Timber.d("Fresh install, no migration needed.")
|
|
||||||
migrationStore.setApplicationMigrationVersion(lastMigration)
|
|
||||||
return@LaunchedEffect
|
|
||||||
}
|
}
|
||||||
if (migrationValue == lastMigration) {
|
if (migrationValue == lastMigration) {
|
||||||
Timber.d("Current app migration version: $migrationValue. No migration needed.")
|
Timber.d("Current app migration version: $migrationValue. No migration needed.")
|
||||||
|
|||||||
+6
-6
@@ -27,12 +27,9 @@ class MigrationPresenterTest {
|
|||||||
val warmUpRule = WarmUpRule()
|
val warmUpRule = WarmUpRule()
|
||||||
|
|
||||||
@Test
|
@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 ->
|
val migrations = (1..10).map { order ->
|
||||||
FakeAppMigration(
|
FakeAppMigration(order = order)
|
||||||
order = order,
|
|
||||||
migrateLambda = LambdaNoParamRecorder(ensureNeverCalled = true) { },
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
val store = InMemoryMigrationStore(initialApplicationMigrationVersion = -1)
|
val store = InMemoryMigrationStore(initialApplicationMigrationVersion = -1)
|
||||||
val presenter = createPresenter(
|
val presenter = createPresenter(
|
||||||
@@ -44,12 +41,15 @@ class MigrationPresenterTest {
|
|||||||
}.test {
|
}.test {
|
||||||
val initialState = awaitItem()
|
val initialState = awaitItem()
|
||||||
assertThat(initialState.migrationAction).isEqualTo(AsyncData.Uninitialized)
|
assertThat(initialState.migrationAction).isEqualTo(AsyncData.Uninitialized)
|
||||||
skipItems(1)
|
skipItems(migrations.size)
|
||||||
awaitItem().also { state ->
|
awaitItem().also { state ->
|
||||||
assertThat(state.migrationAction).isEqualTo(AsyncData.Success(Unit))
|
assertThat(state.migrationAction).isEqualTo(AsyncData.Success(Unit))
|
||||||
}
|
}
|
||||||
assertThat(store.applicationMigrationVersion().first()).isEqualTo(migrations.maxOf { it.order })
|
assertThat(store.applicationMigrationVersion().first()).isEqualTo(migrations.maxOf { it.order })
|
||||||
}
|
}
|
||||||
|
for (migration in migrations) {
|
||||||
|
migration.migrateLambda.assertions().isCalledOnce()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user