fixes a crash within TootDao that is caused by an change in the room library

This commit is contained in:
Conny Duck 2017-10-23 21:50:41 +02:00
parent ba7e1a77a1
commit 87b34df892
3 changed files with 20 additions and 3 deletions

View file

@ -59,7 +59,7 @@ dependencies {
compile "org.jsoup:jsoup:1.10.3"
//room
compile "android.arch.persistence.room:runtime:1.0.0-beta2"
compile "android.arch.persistence.room:runtime:1.0.0-rc1"
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0-beta2'
testCompile "junit:junit:4.12"

View file

@ -54,6 +54,7 @@ public class TuskyApplication extends Application {
db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "tuskyDB")
.allowMainThreadQueries()
.addMigrations(AppDatabase.MIGRATION_2_3)
.build();
}
}

View file

@ -1,14 +1,30 @@
package com.keylesspalace.tusky.db;
import android.arch.persistence.db.SupportSQLiteDatabase;
import android.arch.persistence.room.Database;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.migration.Migration;
/**
* DB version & declare DAO
*/
@Database(entities = {TootEntity.class}, version = 2, exportSchema = false)
@Database(entities = {TootEntity.class}, version = 3, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
public abstract TootDao tootDao();
}
public static final Migration MIGRATION_2_3 = new Migration(2, 3) {
@Override
public void migrate(SupportSQLiteDatabase database) {
//this migration is necessary because of a change in the room library
database.execSQL("CREATE TABLE TootEntity2 (uid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, text TEXT, urls TEXT, contentWarning TEXT);");
database.execSQL("INSERT INTO TootEntity2 SELECT * FROM TootEntity;");
database.execSQL("DROP TABLE TootEntity;");
database.execSQL("ALTER TABLE TootEntity2 RENAME TO TootEntity;");
}
};
}