chinwag-android/app/src/main/java/com/keylesspalace/tusky/db/AppDatabase.java

54 lines
2.3 KiB
Java
Raw Normal View History

/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
2017-06-29 03:33:20 +10:00
package com.keylesspalace.tusky.db;
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;
import android.arch.persistence.room.migration.Migration;
import android.support.annotation.NonNull;
2017-06-29 03:33:20 +10:00
/**
* DB version & declare DAO
2017-06-29 03:33:20 +10:00
*/
@Database(entities = {TootEntity.class, AccountEntity.class}, version = 4, 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();
public abstract AccountDao accountDao();
public static final Migration MIGRATION_2_3 = new Migration(2, 3) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
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;");
}
};
public static final Migration MIGRATION_3_4 = new Migration(3, 4) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE TootEntity ADD COLUMN inReplyToId TEXT");
database.execSQL("ALTER TABLE TootEntity ADD COLUMN inReplyToText TEXT");
database.execSQL("ALTER TABLE TootEntity ADD COLUMN inReplyToUsername TEXT");
database.execSQL("ALTER TABLE TootEntity ADD COLUMN visibility INTEGER");
}
};
}