GreenDAO schema update and data migration?

后端 未结 7 2125
借酒劲吻你
借酒劲吻你 2020-12-12 10:14

I\'m evaluating GreenDAO for consideration in a commercial Android app I will be working on and wanted to determine the migration path for schema updates.

Am I corre

7条回答
  •  眼角桃花
    2020-12-12 10:44

    Pedro Okawa' solution is correct, but you need to write your "UpgradeHelper" to extend "OpenHelper" because DaoMaster is overwritten each time you re-generate DAO code.

    Example:

    public class UpgradeHelper extends DaoMaster.OpenHelper {
    
    public UpgradeHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
        super(context, name, factory);
    }
    
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    
        Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by migrating all tables data");
    
        MigrationHelper.getInstance().migrate(db,
                UserDao.class,
                ItemDao.class,
                AnotherClassToGenerateDao.class);
    }
    

    }

提交回复
热议问题