How to migrate existing SQLite application to Room Persistance Library? How to migrate existing SQLite application to Room Persistance Library? sqlite sqlite

How to migrate existing SQLite application to Room Persistance Library?


Assuming your room entities match your current table schemas, you can keep using the same database/tables.

Room manages a master table which is initialized on creation or upgrade of the database, so you need to increment your database version and provide a dummy migration:

@Database(entities = SomeEntity.class, version = EXISTING_VERSION + 1)public class MyDatabase extends RoomDatabase {    // ...}MyDatabase db = Room.databaseBuilder(context, MyDatabase.class, "db_name")                    .addMigrations(new Migration(EXISTING_VERSION, EXISTING_VERSION + 1) {                        @Override                        public void migrate(SupportSQLiteDatabase database) {                            // NOOP                        }                    }).build();


For those who are wondering if there is any way to migrate from SQLite to Room even if your schema does not match, the answer is YES, you can migrate from SQLite to room even if the schema does not match.

It is possible, but a requires quite careful conversions. As the process requires so many steps to cover, I will just leave references you can follow.

Incrementally migrate from SQLite to Room

Hope it will be helpful for a few.