Don't want to replace the old database when app is updated

后端 未结 3 1717
面向向阳花
面向向阳花 2021-01-03 13:21

In my app I am using sqlite database I don\'t want to replace an existing database when app is updated in app store.

Will it replace with new database? Or will it re

3条回答
  •  -上瘾入骨i
    2021-01-03 13:31

    The next time your new app connects to the database, you will have to detect that it needs to be updated, then you need to run the series of sql commands or scripts against it to pull it up (and hopefully in a background thread async).

    What my sqlite wrapper does:

    1. Store a sequence of sql scripts in resources.
    2. I have a file which references the list of scripts to run.
    3. For a new DB, it just runs those scripts in order.
    4. As each script runs, I record in a tracking metadata table the last script that ran.
    5. When the app is updated (or during my developement), when connecting, it detects the latest script is not the one in the table. It then iterates on the scripts and only runs the ones after the one that was already run.

    That servers me on updates but also on day to day development without throwing away the data constantly.

提交回复
热议问题