android - Upgrading database using my OpenHelper in greendao -
i use greendao orm. want migrate schema oldversion new version. use this link implement mygration. wrote own openhelper class , put package. implement onupgrade method this:
public class upgradehelper extends openhelper { public upgradehelper(context context, string name, cursorfactory factory) { super(context, name, factory); } /** * apply appropriate migrations update database. */ @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { log.i("greendao", "my upgrade helper -------- upgrading schema version " + oldversion + " " + newversion + " dropping tables"); switch (newversion) { case 2: new migratev1tov2().applymigration(db, oldversion); break; case 3: new migratev2tov3().applymigration(db, oldversion); break; default: return; } }
}
but method never called when upgrade version of database 1 2. can not change onupgrade() method in generated daomaster class, because auto generated. when upgrade schema_version, onupgrade() method called in daomaster class , can not modify it.
the onupgrade(database, oldschemaversion, newschemaversion)
-method called if schema-version
stored in sqlite-database differs schema-version
specify in code.
thus method run once each version of database. if forgot include update-logic in first run, have reset schema-version manually example using sqlitemanager.
Comments
Post a Comment