Essentially I want to migrate sqlite schemata, and data accordingly, as I upgrade iPhone applications. I've heard of migrati开发者_如何学运维ons frameworks becoming more popular in the Ruby, Java and .NET spaces, but is there something to help me in the iOS space?
CoreData isn't an option for me at the moment. (Please don't ask why, it just isn't.)
If a migrations library isn't available what approaches do you take?
In my past I usually kept a version info using a PRAGMA command in the database. Whenever my app starts up, I check which version the database is currently in, and call any needed update routines to alter the structure.
For most cases having a whole framework to do that is overkill; especially if you have less than 10 or 20 tables in the database.
Some pseudocode:
currentVersion = getCurrentDbVersion()
if currentVersion < 2 then
upgradeToVersion2();
end if
if currentVersion < 3 then
upgradeToVersion3();
end if
if currentVersion < 4 then
upgradeToVersion4();
end if
Here is some more information about that PRAGMA command: http://www.sqlite.org/pragma.html#pragma_user_version
Hope that helps. :)
精彩评论