2017-11-17 05:18:11 +11:00
/ * 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 ;
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-11-17 05:18:11 +11:00
import android.support.annotation.NonNull ;
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
* /
2018-11-12 05:25:45 +11:00
@Database ( entities = { TootEntity . class , AccountEntity . class , InstanceEntity . class } , version = 9 , 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 ( ) ;
2018-02-04 08:45:14 +11:00
public abstract AccountDao accountDao ( ) ;
2018-04-22 18:35:46 +10:00
public abstract InstanceDao instanceDao ( ) ;
2017-10-24 06:50:41 +11:00
public static final Migration MIGRATION_2_3 = new Migration ( 2 , 3 ) {
@Override
2017-11-17 05:18:11 +11:00
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
2017-10-24 06:50:41 +11:00
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; " ) ;
}
} ;
2017-11-17 05:18:11 +11:00
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 " ) ;
}
} ;
2018-02-04 20:12:01 +11:00
public static final Migration MIGRATION_4_5 = new Migration ( 4 , 5 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " CREATE TABLE `AccountEntity` ( " +
" `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
" `domain` TEXT NOT NULL, `accessToken` TEXT NOT NULL, " +
" `isActive` INTEGER NOT NULL, `accountId` TEXT NOT NULL, " +
" `username` TEXT NOT NULL, `displayName` TEXT NOT NULL, " +
" `profilePictureUrl` TEXT NOT NULL, " +
" `notificationsEnabled` INTEGER NOT NULL, " +
" `notificationsMentioned` INTEGER NOT NULL, " +
" `notificationsFollowed` INTEGER NOT NULL, " +
" `notificationsReblogged` INTEGER NOT NULL, " +
" `notificationsFavorited` INTEGER NOT NULL, " +
" `notificationSound` INTEGER NOT NULL, " +
" `notificationVibration` INTEGER NOT NULL, " +
" `notificationLight` INTEGER NOT NULL, " +
" `lastNotificationId` TEXT NOT NULL, " +
" `activeNotifications` TEXT NOT NULL) " ) ;
database . execSQL ( " CREATE UNIQUE INDEX `index_AccountEntity_domain_accountId` ON `AccountEntity` (`domain`, `accountId`) " ) ;
}
} ;
2018-04-14 06:37:21 +10:00
public static final Migration MIGRATION_5_6 = new Migration ( 5 , 6 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " CREATE TABLE IF NOT EXISTS `EmojiListEntity` (`instance` TEXT NOT NULL, `emojiList` TEXT NOT NULL, PRIMARY KEY(`instance`)) " ) ;
}
} ;
2018-04-22 18:35:46 +10:00
public static final Migration MIGRATION_6_7 = new Migration ( 6 , 7 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " CREATE TABLE IF NOT EXISTS `InstanceEntity` (`instance` TEXT NOT NULL, `emojiList` TEXT, `maximumTootCharacters` INTEGER, PRIMARY KEY(`instance`)) " ) ;
2018-07-30 23:43:27 +10:00
database . execSQL ( " INSERT OR REPLACE INTO `InstanceEntity` SELECT `instance`,`emojiList`, NULL FROM `EmojiListEntity`; " ) ;
2018-04-22 18:35:46 +10:00
database . execSQL ( " DROP TABLE `EmojiListEntity`; " ) ;
}
} ;
2018-07-30 23:43:27 +10:00
public static final Migration MIGRATION_7_8 = new Migration ( 7 , 8 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `emojis` TEXT NOT NULL DEFAULT '[]' " ) ;
}
} ;
2018-11-12 05:25:45 +11:00
public static final Migration MIGRATION_8_9 = new Migration ( 8 , 9 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `TootEntity` ADD COLUMN `descriptions` TEXT DEFAULT '[]' " ) ;
}
} ;
2017-10-24 06:50:41 +11:00
}