It might be a bit early to ask, but is it possible and how to migrate/upgrade an existing SQLite database application to a new Android Room Persistance Library?
You can use AutoMigrationSpec to give Room the additional information that it needs to correctly generate migration paths. Define a static class that implements AutoMigrationSpec in your RoomDatabase class and annotate it with one or more of the following: @DeleteTable. @RenameTable.
Room provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite. Room is now considered as a better approach for data persistence than SQLiteDatabase.
Sqlite Database commonly used to persist the data in most Android applications. Sqlite file is created in your package folder. Sqlite data is persisted after application close and even phone switch off.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With