iOS推出应用更新。需要DB更新时保持用户数据完好无损 [英] iOS Rolling out app updates. Keeping user data intact when DB update required

查看:127
本文介绍了iOS推出应用更新。需要DB更新时保持用户数据完好无损的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚做了一个快速搜索,没有太多相关内容,所以这里有。

I have just done a quick search and nothing too relevant came up so here goes.

我已经发布了应用程序的第一个版本。从那以后,我对SQLite数据库进行了一些更改,在下一个版本中,我将需要更新数据库结构,但保留用户的数据。

I have released the first version of an app. I have made a few changes to the SQLite db since then, in the next release I will need to update the DB structure but retain the user's data.

什么是最好的方法为了这?我目前正在考虑在应用程序更新时,我永远不会替换用户的(文档文件夹,而不是捆绑)数据库文件,而是使用SQL查询更改其结构。

What's the best approach for this? I'm currently thinking that on app update I will never replace the user's (documents folder, not in bundle) database file but rather alter its structure using SQL queries.

这将涉及跟踪自上一版本以来对数据库所做的更改。将所有这些更改编写到SQL查询中并运行这些更改以使DB进入最新版本。我还需要在数据库中保留一个字段来跟踪版本号(为简单起见,请与app版本保持一致)。

This would involve tracking changes made to the database since the previous release. Script all these changes into SQL queries and run these to bring the DB to the latest revision. I will also need to keep a field in the database to track the version number (keep in line with app version for simplicity).

除非有特定的钩子,否则委托方法在更新后第一次运行时触发,我将把这个逻辑的调用放到appDelegate的最开头,然后运行其他任何东西。

Unless there are specific hooks, delegate methods that are fired at first run after an update I will put calls for this logic into the very beginning of the appDelegate, before anything else is run.

这样做我会向用户显示正在更新应用或其他内容。

While doing this I will display "Updating app" or something to the user.

接下来,如果沿线某处出现错误并且更新失败,会发生什么。数据库将过时,应用程序将无法正常运行,因为它需要更新版本?

Next thing, what happens if there is an error somewhere along the line and the update fails. The DB will be out of date and the app won't function properly as it expects a newer version?

我应该自己删除用户的数据库文件并将其替换为应用程序包中的新版本。或者,我应该只是测试,测试,测试,直到我身边的一切都很稳固,如果用户身上发生了错误,那就是别的东西,在这种情况下,我无法做任何事情只会丢弃数据。

Should I take it upon myself to just delete the user's DB file and replace it with the new version from the app bundle. OR, should I just test, test, test until everything is solid on my side and if an error occurs on the user's side it's something else, in which case I can't do anything about it only discard the data.

对此有任何想法将不胜感激。 :)

Any ideas on this would be greatly appreciated. :)

谢谢!

推荐答案

首先,方法你正在考虑是正确的。这称为数据库迁移。无论何时修改数据库,都应该将相应的 ALTER TABLE ... 等方法收集到迁移脚本中。

First of all, the approach you are considering is the correct one. This is known as database migration. Whenever you modify the database on your end, you should collect the appropriate ALTER TABLE... etc. methods into a migration script.

然后你的应用程序的下一个版本应运行此代码一次(如你所述)以迁移所有用户的数据。

Then the next release of your app should run this code once (as you described) to migrate all the user's data.

至于处理错误,那是一个艰难的。我会非常厌倦丢弃用户的数据。更好的方法是显示错误消息,并让用户通过错误报告与您联系。然后,您可以发布应用程序的更新,希望可以毫无问题地进行迁移。但理想情况下,您可以很好地测试该过程,以免出现此类问题。当然,这完全取决于迁移过程的复杂性。

As for handling errors, that's a tough one. I would be very weary of discarding the user's data. Better would be to display an error message and perhaps let the user contact you with a bug report. Then you can release an update to your app which hopefully can do the migration with no problems. But ideally you test the process well enough that there shouldn't be any problems like this. Of course it all depends on the complexity of the migration process.

这篇关于iOS推出应用更新。需要DB更新时保持用户数据完好无损的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆