如何将现有的 SQLite 应用程序迁移到 Room Persistance Library? [英] How to migrate existing SQLite application to Room Persistance Library?
本文介绍了如何将现有的 SQLite 应用程序迁移到 Room Persistance Library?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在问可能有点早,但是否有可能以及如何将现有的 SQLite 数据库应用程序迁移/升级到新的 Android Room Persistance 库?
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屋!
查看全文