I have a situation where I have made changes to an SQLite database for the next release of my app, because of the changes to the SQLite database I have also made changes to some code that reads from it, primarily adding columns to the query method.
Because of the changes the next time the user updates the application they must have the new database for it to work. On the previous version of my app I have a database named File.sqlite, when the user downloads the application fresh that file gets saved to their documents folder. Now I have built the application with a new file but same name File.sqlite that has some more columns and such in it but when I update the application (not a fresh install) that new file does not replace the old.
How can I ensure that when the user updates the application the file will be replaced/updated?
As of right now I understand that I can use the following to get the path of the old file in documents directory:
//Reference the path to the documents directory.
NSString *documentDir =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
//Get the path of old file.
NSString *filePath = [documentDir stringByAppendingPathComponent:@"File.sqlite"];
Does the new file have to have a different name and I just reference the new name in the code? That seems silly to me, I must be able to make a copy of the old and use the new version?
Also, I am not even sure if this is the best approach to do what I am trying to do so also if you know of a better way please advise.