1

I have an entity in my ROOM database.

child_exercises_table which is populated in PopulateDbAsyncTask.

@PrimaryKey
int childExercises_id;

private String child_exercise_name;

@Nullable
private String vid_file_path;`

This entity has 3 field: childExercises_id, child_exercise_name and vid_file_path.

Some of the childExercises do not have a vid_file_path at the moment (null), however I would like to add some in future updates.

I would also like to rename some of the child_exercise_name's in future updates.

How can I achieve this while preserving the rest of the data?

Up until now I have been using .fallbackToDestructiveMigration() and then making updates in populateDbAsyncTask but I will not be able to use this once the app is published.

(I suspect that this should be done with ROOM migrations, however writing a migration every single time I want to add some vid_file_path's or maybe change an exercise name doesn't look very efficient and I could see my code getting very confusing after 10+ migrations.)

Josh Brett
  • 77
  • 3
  • 18
  • Do you have the IDs for entities that you will need to change in the future? – Boda Aug 09 '20 at 08:56
  • Yes, I do you have the IDs (primary key) for the entities that I will change in the future. – Josh Brett Aug 09 '20 at 08:58
  • 1
    Then I don't think migrations is the answer for you. Migrations are usually more about changing the structure of the table itself (adding col, removing col, etc..). You can do it simply by using an update method in the DAO or something. You will be able to update only the fields you need (i.e child_exercise_name, vid_file_path). Does this answer you question? If not, pls provide a bit more context if possiable. – Boda Aug 09 '20 at 10:27
  • Yes, an update query sounds better. Where should I make the update query? I know I shouldn't call in in `prepopulatedbAsyncTask`. – Josh Brett Aug 09 '20 at 10:41
  • When I add vid_file_paths in future app updates, I would like these changes to be added to everyone's database. – Josh Brett Aug 09 '20 at 10:44
  • I have created this method in my DAO `@Update void update(ChildExercises childExercises);` should I call this in my Mainactivity? – Josh Brett Aug 09 '20 at 10:52
  • 1
    Well, it depends on what you mean by "to everyone's database": if you mean everyone who updates the app then that shouldn't be a problem, this can be done easily. If you mean everyone even the ones who didn't update the app, then you will need a backend DB with some services and maybe syncing between room and remote db.. – Boda Aug 09 '20 at 10:54
  • 1
    Looks like it, but I can't be sure since I don't see the rest of the code. : ) – Boda Aug 09 '20 at 10:54

0 Answers0