Regarding the magnificent and amazing SQLite.swift, I'm wondering
You have an app in the app store, v7. There's an upgrade to v8. User X does upgrade v7 to v8 using the app store.
Say in v8, we have slightly changed one of the sql tables, perhaps add a column or rename a column.
Should anything or must anything special be done in SQLite.swift in this case?
What's the SQLite.swift way to handle that?
(In for example, Android there's a handy onUpgrade concept in their helper class ... which comes with it's own set of complex issues.)
The implementation of SQLiteOpenHelper is quite simple:
Just do the same in Swift.
For how to implement
onUpgrade()
, see SQLiteOpenHelper onUpgrade() Confusion Android.There are 2 cases where you want to upgrade database:
There are no user data stored: database contains only predefined data and you want to alter tables' structure, add new rows, add new tables....
There are user data stored: you want to alter data as well as keep user data persisted.
The example below explains how you can do to solve the first case. The second case would require adding some more logic based on the example.
In this example, once you release a new app version and would like to upgrade database, you just need to increase the variable
databaseVersion
.