RoomAsset
RoomAsset copied to clipboard
migrate to newer db
i try to update my db file with new data, and update database version to 3. but the data is still from the old db. how to achieve this?
You only need to update the version. I will try to make a migration to make sure it's not a library bug.
On Mon, Aug 13, 2018, 8:31 AM Indra Anisa [email protected] wrote:
i try to update my db file with new data, and update database version to 3. but the data is still from the old db. how to achieve this?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/humazed/RoomAsset/issues/13, or mute the thread https://github.com/notifications/unsubscribe-auth/AIbcJrJzeBlzjtvAPu7UmYO-ISFoZ76pks5uQR04gaJpZM4V58-V .
I have a similar issue. I update the DB data upon every release, but would rather not change the version number unless the schema has changed. Previously I was using android-sqlite-asset-helper, which allowed the db to be overwritten upon every app upgrade. Does such a feature exist?
The lib uses android-sqlite-asset-helper under the hood I will look at supporting this.
I find the problem and I will release a new version with a fix.
Any news about this? It's quite important to be able to update the database.
I tried with fallbackToDestructiveMigrationFrom and it only deleted the old database without getting the new database.
I had no free time lately but I will start working on it actively soon -1 or 2 days- and hopefully fix this bug.
My guess is that when you migrate with fallbackToDestructiveMigrationFrom, it doesn't really delete the db file. It only drops and regenerates all the tables and it prevents RoomAsset from loading the new db file from assets folder.
Any news about this? It's quite important to be able to update the database.
I tried with fallbackToDestructiveMigrationFrom and it only deleted the old database without getting the new database.
i just manually delete data on table and read and loop sql file on migration.
@indraAnisa You're doing that manually? Make the use of the library useless then, no?
@humazed I don't know much about sqlite, but maybe this option can work: https://github.com/jgilfelt/android-sqlite-asset-helper#upgrades-via-overwrite
@indraAnisa You're doing that manually? Make the use of the library useless then, no?
yes, the performance is not bad though, about 1 second for 8K row sql insert.
I had no free time lately but I will start working on it actively soon -1 or 2 days- and hopefully fix this bug.
I'm waiting for this fix too. Will you be working on this issue soon?
unfortunately, I have no free time lately to fix this issue but PRs are welcomed.
I'm still facing this issue, do you have any solution for this ?
Any news about this? It's quite important to be able to update the database.
"Quite important" is quite an understatement..
Updating the Database still not possible, please provide a fix (the old database needs to be deleted and the new one copied)
I made a fork with destructive upgrading, that should be fine for most use cases, if you need something else, feel free to take a look at SQLiteAssetHelper to modify further. https://github.com/ueen/RoomAsset
@ueen Using Room's addMigrations
method, right?
Rooms fallbackToDestructiveMigtation simply drops all rows, addMigration performs actions you specify to convert the rows to the new schema, in this case we only need to tell Room, that the database has changed (overwritten with the new one) and therefore raise the version and in order to do this we need to provide a migration strategy, but as we don't want Room to actually do anything (the database is already overwritten), so we need to set an empty addMigration for the version raise. This only works with my fork tough as humazed code doesn't overwrite anything, it only instantiates the database once.
@ueen
I am getting this crash by using your fork
Unable to create application .ApplicationClass: java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Integer
on this line
appDatabase = RoomAsset.databaseBuilder(getApplicationContext(), AppDatabase.class, "dbname",3). addMigrations(MIGRATION_1_2,MIGRATION_2_3).allowMainThreadQueries().build();
Can you please look into this?
First of all don't use queries on the main thread, that's considered bad practice, secondly you need to add the fileextension (if your file has one, which it should), and most importantly there seems to be an issue with your migrations, please refer to my forks documentation on how to add a new migration (sample at the bottom). And finally, please open an issue on my fork if problems persist, and don't spam this issue :)
@ueen
I am getting this crash by using your fork
Unable to create application .ApplicationClass: java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Integer
appDatabase = RoomAsset.databaseBuilder(getApplicationContext(), AppDatabase.class, "dbname.db",3). addMigrations(MIGRATION_1_2,MIGRATION_2_3).allowMainThreadQueries().build();
My migration class
static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(SupportSQLiteDatabase database) {
// Since we didn't alter the table, there's nothing else to do here.
}
};
static final Migration MIGRATION_2_3 = new Migration(2, 3) {
@Override
public void migrate(SupportSQLiteDatabase database) {
// Since we didn't alter the table, there's nothing else to do here.
}
};
I have already file extension and migration as needed in my code. Until it is crashing. And please allow to open issue in your fork publicly first.
alright, enabled issues, do you have the latest version, what does the stack trace look like -> where exactly is the exception thrown?
@ueen Using Room's
addMigrations
method, right?
updated my fork implementation 'com.github.ueen:RoomAsset:1.2.1'
, manually addMigration is no longer necessary!
Just update the version number of the database and in the databaseBuilder and https://github.com/ueen/RoomAsset takes care of everything else :)
Created a new library that allows you to keep specific columns (eg for userdata) while still updating your database, please have a look https://github.com/ueen/RoomAssetHelper