3

Performing a migration from SharedPrefs into DataStore is straightforward and documented very well. However when I want to do a simple "version bump" migration from DataStore to still DataStore, meaning some keys might have changed etc. how should one do that?

As far as I see now, we need to manually implement these functions in the migrations parameter when creating the DataStore.

PreferenceDataStoreFactory.create(
    migrations = listOf(
        object : DataMigration<Preferences> {
            override suspend fun cleanUp() {
                TODO("Not yet implemented")
            }

            override suspend fun migrate(currentData: Preferences): Preferences {
                TODO("Not yet implemented")
            }

            override suspend fun shouldMigrate(currentData: Preferences): Boolean {
                TODO("Not yet implemented")
            }
        },
    ),
    produceFile = {
        get<Context>().preferencesDataStoreFile("hedvig_data_store_preferences")
    }
)

I haven't seen anyone talking about it, or it being part of the codelab unfortunately which was a big surprise to me. Could someone point me to where I could look to get some inspiration about how to do this properly?

4

0 回答 0