房间迁移过程中的一些重要问题?
关于房间迁移过程,有一些基本但重要的信息。他们可能会帮助其他人。我到处搜索,但什么也没发现。谁能帮忙?
1-当迁移开始时(安装后的第一个App启动之后,或在App和DB之间进行第一次连接之后?)
2-如果设置后迁移,我可以控制它吗?在开始之前和结束后显示升级消息?
3-我们可以确定是否根本不需要迁移(例如新用户)?
关于迁移测试:
1-如何在每个应用程序运行后从开始重新运行测试(例如,每次从VER 1到Ver 2运行)?
所有这些之后,我在测试,
未解决的参考文献中有自己的问题:MigrationTestHelper。我尝试了以下依赖项而没有结果:
androidTestImplementation "androidx.room:room-testing:2.4.2"
def room_version1 = "2.2.5"
def test_version = "1.4.0"
androidTestImplementation "androidx.test:runner:$test_version"
androidTestImplementation "androidx.test:rules:$test_version"
androidTestImplementation "androidx.room:room-testing:$room_version1"
androidTestImplementation "android.arch.persistence.room:testing:1.0.0"
testImplementation "junit:junit:4.12" //downgrade may solve
androidTestImplementation "android.arch.core:core-testing:1.1.1"
任何帮助都将不胜感激。谢谢
There are some basic but important info missed about room migration process. They may help other people. I've searched everywhere but found nothing. can anyone help?
1- When migration starts (while app setup, after first app startup after setup, or after first connection between app and db?)
2- If migration runs after setup, can I control it? showing upgrade messages before starting and after finishing?
3- Can we deted whether we don't need migration at all (like for new users)?
About migration testing:
1- how to re run test from beginning after each app running (e.g. runs every time from ver 1 to ver 2)?
After all of this, I have my own issue with testing,
Unresolved reference: MigrationTestHelper. I've tried the following dependencies with no result:
androidTestImplementation "androidx.room:room-testing:2.4.2"
def room_version1 = "2.2.5"
def test_version = "1.4.0"
androidTestImplementation "androidx.test:runner:$test_version"
androidTestImplementation "androidx.test:rules:$test_version"
androidTestImplementation "androidx.room:room-testing:$room_version1"
androidTestImplementation "android.arch.persistence.room:testing:1.0.0"
testImplementation "junit:junit:4.12" //downgrade may solve
androidTestImplementation "android.arch.core:core-testing:1.1.1"
Any help will be highly appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
迁移开始时,迁移开始尝试访问数据库(不是当您获得该数据库的实例时构建的数据库对象)。如果: -
.fallback ???
被编码(最常hallbackTodeStructivemigration
)。这可能有助于理解: -
是/否,
至少您不能轻松地控制它实际开始停止(除了不更改/更改版本号)。
但是然后调用您的迁移,因此您可以对所做的事情有某种形式的控制。但是,之后对实际数据库(发现)的架构进行检查,以预期的架构(即@Entity注释的类别 @entity注释的类中定义的实体列表中定义的类别 @database注释类中的类别)。无法按预期更改数据库将导致例外。
您可以在房间外和构建之前更改数据库(我建议)并将版本编号更改为VER1。 .com/reference/android/database/sqlite/sqlitedatabase#setVersion(int)“ rel =“ nofollow noreferrer”> setVersion 方法。
另一种方法可能是拥有第二个(原始/基本数据库),然后在房间构建之前再次复制。
The Migration starts when an attempt is made to access the database (not when you get an instance of the built database object). IF :-
.fallback???
is coded (most frequentlyfallbackToDestructiveMigration
).This could assist in understanding:-
Yes/No
You can't, at least easily, control it actually starting stopping (other than not changing/changing the version number).
But your Migration is then invoked, so you can have some form of control over what is done. However, afterwards the schema of the actual database (FOUND) is checked against the EXPECTED schema (i.e. the @Entity annotated classes defined in the list of entities in the @Database annotated class). A failure to change the database as expected WILL result in an exception.
You could alter the database, outside of room and before the build (I would suggest) and change the version number to ver 1. e.g. Open the database as an SQLiteDatabase and then use the setVersion method.
Another way could be to have a second (original/base database) and copy that over, again prior to the the Room build.