Migrating the Room database, with only a new table added

One line answer

  1. Write SQL that creates the new table in AppDatabase.java
  2. Call the add-migration in DB initialization

The code


The problem

In my comic app project (NHViewer), I wanted to add a "bookmark" function to show the last seen page for each comic. 

So I need to create a new table for the Room database while keeping the original tables and data in the device. 

After some searching, I wrote the above code according to the AppDatabase's schema


Coda

During my searching, the Room database migration seems improved in the version 2.2.0 (androidx.room:room-*:2.2.0)
This note did not cover that part though 🙁


References

留言