如何将现有的SQLite应用程序迁移到Room Persistance Library? [英] How to migrate existing SQLite application to Room Persistance Library?
本文介绍了如何将现有的SQLite应用程序迁移到Room Persistance Library?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
询问可能还为时过早,但是是否可能以及如何将现有的SQLite数据库应用程序迁移/升级到新的Android Room Persistance Library?
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?
推荐答案
假设您的房间实体与当前表模式匹配,则可以继续使用相同的数据库/表.
Assuming your room entities match your current table schemas, you can keep using the same database/tables.
Room管理一个主表,该主表在创建或升级数据库时初始化,因此您需要增加数据库版本并提供虚拟迁移:
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();
这篇关于如何将现有的SQLite应用程序迁移到Room Persistance Library?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文