2017-06-29 03:33:20 +10:00
|
|
|
package com.keylesspalace.tusky.db;
|
|
|
|
|
2017-10-24 06:50:41 +11:00
|
|
|
import android.arch.persistence.db.SupportSQLiteDatabase;
|
2017-06-29 03:33:20 +10:00
|
|
|
import android.arch.persistence.room.Database;
|
|
|
|
import android.arch.persistence.room.RoomDatabase;
|
2017-10-24 06:50:41 +11:00
|
|
|
import android.arch.persistence.room.migration.Migration;
|
2017-06-29 03:33:20 +10:00
|
|
|
|
|
|
|
/**
|
2017-06-29 20:03:44 +10:00
|
|
|
* DB version & declare DAO
|
2017-06-29 03:33:20 +10:00
|
|
|
*/
|
|
|
|
|
2017-10-24 06:50:41 +11:00
|
|
|
@Database(entities = {TootEntity.class}, version = 3, exportSchema = false)
|
2017-07-06 00:36:14 +10:00
|
|
|
public abstract class AppDatabase extends RoomDatabase {
|
|
|
|
|
2017-06-29 03:33:20 +10:00
|
|
|
public abstract TootDao tootDao();
|
2017-10-24 06:50:41 +11:00
|
|
|
|
|
|
|
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;");
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|