How to safely migrate a entity part of app modules...
# room
How to safely migrate a entity part of app modules room database to a feature module room database? i am encountering this as i am modularzing code base and moving one of the entities part of app module to a feature module having its own Room database
the feature relying on this is not that important and in worst case i can rely on destructive migration. the feature caches some photo URI till user orders them to print and the safe migration might come handy if a user selects photos and updates the app before ordering them at which point i want to preserve there selection of photos in previous version of the app
this won't be easy because you have a circular dependency. Your migration in app db will delete the table whereas your migration in the feature db will need that table to copy. But for your feature db migration to access the app db, it would need to open it which means the migration in the app db needs to run first. One option is to not delete the table from the app database so that you can write a migration for the feature db which will copy the data from the app db. And after a couple of app version, you can delete it from the app db (and ensure your feature db migration does not fail if table does not exist in the app db)
given that you are kind of OK with losing data, with some grace period, i guess this is an acceptable plan
🙏 for the insights , appreciate you helping out the dev community
in onCreate of the database2, call: ‘attach database1, move the data, then delete the table’. At the end, call ‘detach database1’
👍 1