diff --git a/app/build.gradle b/app/build.gradle index 94509f08d..cf11a1284 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" diff --git a/app/src/main/java/com/keylesspalace/tusky/TuskyApplication.java b/app/src/main/java/com/keylesspalace/tusky/TuskyApplication.java index 86c865b0c..260165665 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TuskyApplication.java +++ b/app/src/main/java/com/keylesspalace/tusky/TuskyApplication.java @@ -54,6 +54,7 @@ public class TuskyApplication extends Application { db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "tuskyDB") .allowMainThreadQueries() + .addMigrations(AppDatabase.MIGRATION_2_3) .build(); } } \ No newline at end of file diff --git a/app/src/main/java/com/keylesspalace/tusky/db/AppDatabase.java b/app/src/main/java/com/keylesspalace/tusky/db/AppDatabase.java index c4bea594f..28f69da71 100644 --- a/app/src/main/java/com/keylesspalace/tusky/db/AppDatabase.java +++ b/app/src/main/java/com/keylesspalace/tusky/db/AppDatabase.java @@ -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;"); + + } + }; + +} \ No newline at end of file