I have an iPhone application that uses a sqlite3 database for saving data and before I release the app I need to be sure that some of the tables data (that the user has saved) must be copied to the new database.
How should I manage this migration. I was thinking about separating the database and the queries. Is that bad? So when the app opens I check if the database is in the document folder, if not copy the database and run the queries in the separate file. Then when it is a new version I check the version number and run just the queries in the file (which update the data and alter some of them), and not copy the database?
One way of doing this is to have a table in your database that contains a schema version of the database.
Once a user have a database in the documents folder (which was probably copied from a premade database from the app bundle) you should make changes to that database to keep it in sync with the current schema. This includes upgrading the schema and any changed data.
You can do this by bundling a number of sql scripts in your app that will bring the users database schema forward one step at a time, e.g.:
If you don’t have a schema version in your current db, just regard this as version 0 and add the table in your version 1 update, e.g: