房间迁移过程中的一些重要问题?

发布于 2025-01-22 17:42:57 字数 895 浏览 0 评论 0原文

关于房间迁移过程,有一些基本但重要的信息。他们可能会帮助其他人。我到处搜索,但什么也没发现。谁能帮忙?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁吢 2025-01-29 17:42:57

1-何时迁移开始(安装后的App Setup,设置后的第一次应用程序之后或在App和DB之间进行首次连接之后?)

迁移开始时,迁移开始尝试访问数据库(不是当您获得该数据库的实例时构建的数据库对象)。如果: -

  1. 版本编号已增加,并且
    1. 通过检查编码版号的数据库标题来检测版本编号。
  2. 有一个可用的迁移,涵盖了版本编号更改。
    1. 如果没有迁移,则除非.fallback ???被编码(最常hallbackTodeStructivemigration)。
  • 通过“访问数据库” ,通常使用@DOA注释的类中的一个功能之一。但是,如果您获得了supportsqlitedatabase对象(请参见下文,示例,ps writable/repleable无实际区别)。

这可能有助于理解: -

    db1 = UserDatabase.getInstance(this) /* Does not access the database */
    dao = db1.getAllDao() /* Does not access the database */
    val spprtDB = db.openHelper.writableDatabase /* will access the database */
    dao.invokeAFunction() /* accesses the database (assuming the function does something such as an @Query/ @Insert etc ) */

如果设置后迁移运行,我可以控制它吗?在开始之前和结束后显示升级消息?

是/否,

至少您不能轻松地控制它实际开始停止(除了不更改/更改版本号)。

但是然后调用您的迁移,因此您可以对所做的事情有某种形式的控制。但是,之后对实际数据库(发现)的架构进行检查,以预期的架构(即@Entity注释的类别 @entity注释的类中定义的实体列表中定义的类别 @database注释类中的类别)。无法按预期更改数据库将导致例外。

1-如何从每个应用程序运行后从开始进行测试(例如,每次从VER 1到Ver 2运行)?

您可以在房间外和构建之前更改数据库(我建议)并将版本编号更改为VER1。 .com/reference/android/database/sqlite/sqlitedatabase#setVersion(int)“ rel =“ nofollow noreferrer”> setVersion 方法。

  • 您可能/可能不希望将架构更改为原件。

另一种方法可能是拥有第二个(原始/基本数据库),然后在房间构建之前再次复制。

1- When migration starts (while app setup, after first app start-up after setup, or after first connection between app and db?)

The Migration starts when an attempt is made to access the database (not when you get an instance of the built database object). IF :-

  1. the version number has been increased, AND
    1. a version number increase, is detected by checking the header of the database against the coded version number.
  2. there is a migration available that covers the version number change.
    1. if no Migration then a failure will occur unless covered by a .fallback??? is coded (most frequently fallbackToDestructiveMigration).
  • By "access the database", that is typically using one of the functions in a class that is annotated with @Doa. However, if you get a SupportSQLiteDatabase object (see below for an example, PS writable/readable no real difference).

This could assist in understanding:-

    db1 = UserDatabase.getInstance(this) /* Does not access the database */
    dao = db1.getAllDao() /* Does not access the database */
    val spprtDB = db.openHelper.writableDatabase /* will access the database */
    dao.invokeAFunction() /* accesses the database (assuming the function does something such as an @Query/ @Insert etc ) */

If migration runs after setup, can I control it? showing upgrade messages before starting and after finishing?

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.

1- how to re run test from beginning after each app running (e.g. runs every time from ver 1 to ver 2)?

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.

  • You may/may not wish to change the schema to the original.

Another way could be to have a second (original/base database) and copy that over, again prior to the the Room build.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文