parent
bb376cfd6c
commit
ed851cb04d
@ -1,14 +1,30 @@ |
|||||||
package com.keylesspalace.tusky.db; |
package com.keylesspalace.tusky.db; |
||||||
|
|
||||||
|
import android.arch.persistence.db.SupportSQLiteDatabase; |
||||||
import android.arch.persistence.room.Database; |
import android.arch.persistence.room.Database; |
||||||
import android.arch.persistence.room.RoomDatabase; |
import android.arch.persistence.room.RoomDatabase; |
||||||
|
import android.arch.persistence.room.migration.Migration; |
||||||
|
|
||||||
/** |
/** |
||||||
* DB version & declare DAO |
* 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 class AppDatabase extends RoomDatabase { |
||||||
|
|
||||||
public abstract TootDao tootDao(); |
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;"); |
||||||
|
|
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue