Adding new table
ghatasheh opened this issue · 3 comments
ghatasheh commented
Hello
I've added a new table but ProviGen didn't upgrade the database, I've noticed in the code that you just update the columns.
ProviGenOpenHelper
@Override
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
if (newVersion > oldVersion) {
for (Class contract : contracts)
TableUpdater.addMissingColumns(database, contract);
}
}
TimotheeJeannin commented
Hi @ghatasheh,
As you can read in the README.md file:
ProviGen comes with an implementation of the SQLiteOpenHelper called ProviGenOpenHelper. This default implementation will
- automatically create the needed tables on the first application launch
- automatically add missing columns every time the database version increases
If you want ProviGen to create a new table on version increase, you can provide your own implementation of the SQLiteOpenHelper
or extend the ProviGenOpenHelper
.
public class MySQLiteOpenHelper extends ProviGenOpenHelper {
public MySQLiteOpenHelper(Context context, String databaseName, SQLiteDatabase.CursorFactory factory, int version, Class[] contractClasses) {
super(context, databaseName, factory, version, contractClasses);
}
@Override
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
// Create the table for your new contract.
if(newVersion > 3 && oldVersion < 3){
new TableBuilder(myNewContract.class).createTable(database);
}
// Calling the super method will add missing columns.
super.onUpgrade(database, oldVersion, newVersion);
}
}
Feel free to get back to me if something isn't working for you with ProviGen. :)
Tim
ghatasheh commented
Sorry my mistake. Thank you so much!
TimotheeJeannin commented
You're welcome. :)