开发者

Preserving some tables when upgrading app database?

开发者 https://www.devze.com 2023-03-03 13:57 出处:网络
In my sqlite3 database I have some tables with user added values that开发者_运维百科 I would like to preserve when I upgrade my app.However, I would like to drop most of the other tables (around 10) a

In my sqlite3 database I have some tables with user added values that开发者_运维百科 I would like to preserve when I upgrade my app. However, I would like to drop most of the other tables (around 10) and repopulate them with data from the new database that I'm going to ship. In prior versions, I could just drop the database and copy over the new one. Going forward this won't be possible because I'm going to allow users to enter data in separate tables.


Instead dropping the entire database and repopulating from scratch, consider using DROP TABLE explicitly. A healthy dose of ALTER TABLE .. RENAME may also be in order to put the "new" tables where the "old" tables were. And perhaps clean up with a VACUUM at the end to keep things tidy.

If the new data is distributed in a new database file, then consider using ATTACH DATABASE temporarily for the copy operation.

In my databases I have a meta-data table which stores the "database version" among other things (although the USER_VERSION PRAGMA could also be used). This enables code to selectively roll-forward through change-sets.

Happy coding.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号