Greendao test migrate database onUpgrade Google Play Store

Greendao test migrate database onUpgrade Google Play Store

To simulate migration database or trigger onUpgrade() on DevHelper in GreenDao,
the step will be:

1. Use simulate update app like in Google Play Store
Follow this : http://www.yodiaditya.com/android-simulate-update-application-google-play-store/

2. ALWAYS UPDATE SCHEMA VERSION GREENDAO
yes, i put this capitalized because it’s very important!
For instance:

1
2
3
4
5
greendao {
    schemaVersion 5
    daoPackage "YOUR_PACKAGE_NAME_AND_PATH.dao"

}

3. Always use SQLiteDatabase db to Trigger onUpgrade()

For instance:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
 * Created by Growth on 2016/3/3.
 */
public class DevOpenHelper extends DaoMaster.OpenHelper {

    Context mContext;

    public DevOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
        super(context, name, factory);
        mContext = context;
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Timber.tag("HELO").d("DATABASE UPGREDE.............");
        Timber.tag("HELO").d("GREENDAO upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");

        StandardDatabase dba = new StandardDatabase(db);

        if (newVersion > oldVersion) {
            switch (oldVersion) {
                case 1:

                    DaoMaster.dropAllTables(dba, true);
                    DaoMaster.createAllTables(dba, false);

                    break;

                default:

                    DaoMaster.dropAllTables(dba, true);
                    DaoMaster.createAllTables(dba, false);
            }
        }

    }
}

Try to debug with logcat to see if onUpgrade executed

Leave a Reply

Your email address will not be published. Required fields are marked *