Do not perform any migration on fresh application installation.
This commit is contained in:
parent
76e34ae798
commit
b00061263a
3 changed files with 33 additions and 1 deletions
|
|
@ -46,7 +46,7 @@ class DefaultMigrationStore @Inject constructor(
|
||||||
|
|
||||||
override fun applicationMigrationVersion(): Flow<Int> {
|
override fun applicationMigrationVersion(): Flow<Int> {
|
||||||
return store.data.map { prefs ->
|
return store.data.map { prefs ->
|
||||||
prefs[applicationMigrationVersion] ?: 0
|
prefs[applicationMigrationVersion] ?: -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,12 @@ class MigrationPresenter @Inject constructor(
|
||||||
|
|
||||||
LaunchedEffect(migrationStoreVersion) {
|
LaunchedEffect(migrationStoreVersion) {
|
||||||
val migrationValue = migrationStoreVersion ?: return@LaunchedEffect
|
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) {
|
if (migrationValue == lastMigration) {
|
||||||
Timber.d("Current app migration version: $migrationValue. No migration needed.")
|
Timber.d("Current app migration version: $migrationValue. No migration needed.")
|
||||||
migrationAction = AsyncData.Success(Unit)
|
migrationAction = AsyncData.Success(Unit)
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,32 @@ class MigrationPresenterTest {
|
||||||
@get:Rule
|
@get:Rule
|
||||||
val warmUpRule = WarmUpRule()
|
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
|
@Test
|
||||||
fun `present - no migration should occurs if ApplicationMigrationVersion is the last one`() = runTest {
|
fun `present - no migration should occurs if ApplicationMigrationVersion is the last one`() = runTest {
|
||||||
val migrations = (1..10).map { FakeAppMigration(it) }
|
val migrations = (1..10).map { FakeAppMigration(it) }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue