Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS SQLite.swift, regarding upgrade of app?

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.)

like image 766
Fattie Avatar asked Dec 12 '16 11:12

Fattie


1 Answers

The implementation of SQLiteOpenHelper is quite simple:

        db = SQLiteDatabase.openDatabase(...);

        onConfigure(db);

        int version = db.getVersion();
        if (version != mNewVersion) {
            db.beginTransaction();
            try {
                if (version == 0) {
                    onCreate(db);
                } else {
                    if (version > mNewVersion) {
                        onDowngrade(db, version, mNewVersion);
                    } else {
                        onUpgrade(db, version, mNewVersion);
                    }
                }
                db.setVersion(mNewVersion);
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }
        }

Just do the same in Swift.

For how to implement onUpgrade(), see SQLiteOpenHelper onUpgrade() Confusion Android.

like image 111
CL. Avatar answered Nov 13 '22 23:11

CL.