Reputation: 2043
Consider a SQLite database for an iPhone app with some "documents" as templates. The user is able to add his own templates too.
I want to update the program and the database. Is there any chance to do so without overwriting the user's data?
I've considered two different databases, but since this is overhead, I want to avoid this option.
How can this be done without overwriting the user's data?
Upvotes: 3
Views: 871
Reputation: 4985
If you're using Core Data, then it should be relatively easy to add a new data model (schema) version and have 'migration' happen automatically. With some minor changes, you may need to creating a mapping model. And if your schema is changing significantly with entities being refactored, levels of abstraction being added, etc. then you may need to subclass NSEntityMigrationPolicy.
You might want to look at the Core Data Model Versioning and Data Migration Programming Guide
You might also look at Marcus Zarra's 'Core Data' book and sample code.
Upvotes: 1
Reputation: 100557
When updating your application and its datastore, deliver ALTER
scripts in the upgrade package. When the app first runs, it should:
ALTER
and UPDATE
scripts to take schema and data from v1 to v2Upvotes: 0
Reputation: 13292
You could make your app check for old versions of the db when it runs and update it itself if necessary. So basically, update the app and it will handle updating the db. This would allow you to backup/restore data (if necessary).
Upvotes: 0