Do not perform any migration on fresh application installation.
This commit is contained in:
parent
5b13a51b0c
commit
54dc8e7c54
3 changed files with 33 additions and 1 deletions
|
|
@ -46,7 +46,7 @@ class DefaultMigrationStore @Inject constructor(
|
|||
|
||||
override fun applicationMigrationVersion(): Flow<Int> {
|
||||
return store.data.map { prefs ->
|
||||
prefs[applicationMigrationVersion] ?: 0
|
||||
prefs[applicationMigrationVersion] ?: -1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,12 @@ 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
|
||||
}
|
||||
if (migrationValue == lastMigration) {
|
||||
Timber.d("Current app migration version: $migrationValue. No migration needed.")
|
||||
migrationAction = AsyncData.Success(Unit)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,32 @@ class MigrationPresenterTest {
|
|||
@get:Rule
|
||||
val warmUpRule = WarmUpRule()
|
||||
|
||||
@Test
|
||||
fun `present - no migration should occurs on fresh installation, and last version should be stored`() = runTest {
|
||||
val migrations = (1..10).map { order ->
|
||||
FakeAppMigration(
|
||||
order = order,
|
||||
migrateLambda = LambdaNoParamRecorder(ensureNeverCalled = true) { },
|
||||
)
|
||||
}
|
||||
val store = InMemoryMigrationStore(initialApplicationMigrationVersion = -1)
|
||||
val presenter = createPresenter(
|
||||
migrationStore = store,
|
||||
migrations = migrations.toSet(),
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.migrationAction).isEqualTo(AsyncData.Uninitialized)
|
||||
skipItems(1)
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.migrationAction).isEqualTo(AsyncData.Success(Unit))
|
||||
}
|
||||
assertThat(store.applicationMigrationVersion().first()).isEqualTo(migrations.maxOf { it.order })
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - no migration should occurs if ApplicationMigrationVersion is the last one`() = runTest {
|
||||
val migrations = (1..10).map { FakeAppMigration(it) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue