-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do we make changes to the database #44
Comments
You need to use |
@geovanisouza92 can you give an example on how we use that? Do we just declare it like that in the link? Because I tried it, and it doesn't work. It seems that we have to fill in the method some how. |
@chrisjeon Try something like this @Database(fileName = MyDatabase.FILE_NAME, version = MyDatabase.VERSION)
public final class MyDatabase {
public static final int VERSION = 1;
public static final String FILE_NAME = "my.sqlite";
public static final String[] _MIGRATIONS = {
// Put DDL/DML commands here, one string per VERSION increment
};
@OnUpgrade
public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
for (int i = oldVersion; i < newVersion; i++) {
String migration = _MIGRATIONS[i - 2];
db.beginTransaction();
try {
db.execSQL(migration);
db.setTransactionSuccessful();
} catch (Exception e) {
Timber.e(e, "Error executing database migration: %s", migration);
break;
} finally {
db.endTransaction();
}
}
}
} |
In the comment inside |
Ah, so let's say I have 3 sql statements that I would like to run, I would have to bump up the version number by 3? |
You could use DML ( Upgrade to |
Thanks dude, when I get the time, I'll do a PR of updated README.md with better documentation. |
Hi,
I'm wondering how we can make changes to our database (like add/remove columns to the tables, add additional tables, and etc.)
It doesn't seem to be as simple as bumping up the
DATABASE_VERSION
number. Doing that seems to "upgrade" the database, but it doesn't make any changes to the actual database schema itself.The github repo seems to be lacking documentation on this, and I couldn't find much on Google either. Can anyone help me out? The more I learn, I'm willing to contribute to make the documentation more solid.
The text was updated successfully, but these errors were encountered: