2017-11-16 19:18:11 +01: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-28 19:33:20 +02:00
package com.keylesspalace.tusky.db ;
2020-12-23 19:13:37 +01:00
import androidx.annotation.NonNull ;
2023-07-06 19:37:51 +02:00
import androidx.annotation.Nullable ;
2023-05-08 13:57:17 +02:00
import androidx.room.AutoMigration ;
2018-12-17 15:25:35 +01:00
import androidx.room.Database ;
2023-05-13 16:00:28 +02:00
import androidx.room.DeleteColumn ;
2018-12-17 15:25:35 +01:00
import androidx.room.RoomDatabase ;
2023-05-13 16:00:28 +02:00
import androidx.room.migration.AutoMigrationSpec ;
2018-12-17 15:25:35 +01:00
import androidx.room.migration.Migration ;
2020-12-23 19:13:37 +01:00
import androidx.sqlite.db.SupportSQLiteDatabase ;
import com.keylesspalace.tusky.TabDataKt ;
import com.keylesspalace.tusky.components.conversation.ConversationEntity ;
2017-06-28 19:33:20 +02:00
2021-05-16 19:17:56 +02:00
import java.io.File ;
2017-06-28 19:33:20 +02:00
/ * *
2017-06-29 12:03:44 +02:00
* DB version & declare DAO
2017-06-28 19:33:20 +02:00
* /
2023-05-08 13:57:17 +02:00
@Database (
entities = {
DraftEntity . class ,
AccountEntity . class ,
InstanceEntity . class ,
TimelineStatusEntity . class ,
TimelineAccountEntity . class ,
ConversationEntity . class
} ,
2023-07-27 00:09:26 +02:00
version = 52 ,
2023-05-08 13:57:17 +02:00
autoMigrations = {
2023-05-13 16:00:28 +02:00
@AutoMigration ( from = 48 , to = 49 ) ,
2023-05-18 23:23:42 +02:00
@AutoMigration ( from = 49 , to = 50 , spec = AppDatabase . MIGRATION_49_50 . class ) ,
2023-07-27 00:09:26 +02:00
@AutoMigration ( from = 50 , to = 51 ) ,
@AutoMigration ( from = 51 , to = 52 )
2023-05-08 13:57:17 +02:00
}
)
2017-07-05 16:36:14 +02:00
public abstract class AppDatabase extends RoomDatabase {
2023-07-06 19:37:51 +02:00
@NonNull public abstract AccountDao accountDao ( ) ;
@NonNull public abstract InstanceDao instanceDao ( ) ;
@NonNull public abstract ConversationsDao conversationDao ( ) ;
@NonNull public abstract TimelineDao timelineDao ( ) ;
@NonNull public abstract DraftDao draftDao ( ) ;
2017-10-23 21:50:41 +02:00
public static final Migration MIGRATION_2_3 = new Migration ( 2 , 3 ) {
@Override
2017-11-16 19:18:11 +01:00
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
2017-10-23 21:50:41 +02: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-16 19:18:11 +01: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 10:12:01 +01: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-13 22:37:21 +02: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 10:35:46 +02: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 15:43:27 +02:00
database . execSQL ( " INSERT OR REPLACE INTO `InstanceEntity` SELECT `instance`,`emojiList`, NULL FROM `EmojiListEntity`; " ) ;
2018-04-22 10:35:46 +02:00
database . execSQL ( " DROP TABLE `EmojiListEntity`; " ) ;
}
} ;
2018-07-30 15:43:27 +02: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-11 19:25:45 +01: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 '[]' " ) ;
}
} ;
2018-11-12 21:09:39 +01:00
public static final Migration MIGRATION_9_10 = new Migration ( 9 , 10 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `defaultPostPrivacy` INTEGER NOT NULL DEFAULT 1 " ) ;
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `defaultMediaSensitivity` INTEGER NOT NULL DEFAULT 0 " ) ;
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `alwaysShowSensitiveMedia` INTEGER NOT NULL DEFAULT 0 " ) ;
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `mediaPreviewEnabled` INTEGER NOT NULL DEFAULT '1' " ) ;
}
} ;
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
public static final Migration MIGRATION_10_11 = new Migration ( 10 , 11 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " CREATE TABLE IF NOT EXISTS `TimelineAccountEntity` ( " +
" `serverId` TEXT NOT NULL, " +
" `timelineUserId` INTEGER NOT NULL, " +
" `instance` TEXT NOT NULL, " +
" `localUsername` TEXT NOT NULL, " +
" `username` TEXT NOT NULL, " +
" `displayName` TEXT NOT NULL, " +
" `url` TEXT NOT NULL, " +
" `avatar` TEXT NOT NULL, " +
" `emojis` TEXT NOT NULL, " +
" PRIMARY KEY(`serverId`, `timelineUserId`)) " ) ;
database . execSQL ( " CREATE TABLE IF NOT EXISTS `TimelineStatusEntity` ( " +
" `serverId` TEXT NOT NULL, " +
" `url` TEXT, " +
" `timelineUserId` INTEGER NOT NULL, " +
" `authorServerId` TEXT, " +
" `instance` TEXT, " +
" `inReplyToId` TEXT, " +
" `inReplyToAccountId` TEXT, " +
" `content` TEXT, " +
" `createdAt` INTEGER NOT NULL, " +
" `emojis` TEXT, " +
" `reblogsCount` INTEGER NOT NULL, " +
" `favouritesCount` INTEGER NOT NULL, " +
" `reblogged` INTEGER NOT NULL, " +
" `favourited` INTEGER NOT NULL, " +
" `sensitive` INTEGER NOT NULL, " +
" `spoilerText` TEXT, " +
" `visibility` INTEGER, " +
" `attachments` TEXT, " +
" `mentions` TEXT, " +
" `application` TEXT, " +
" `reblogServerId` TEXT, " +
" `reblogAccountId` TEXT, " +
" PRIMARY KEY(`serverId`, `timelineUserId`), " +
" FOREIGN KEY(`authorServerId`, `timelineUserId`) REFERENCES `TimelineAccountEntity`(`serverId`, `timelineUserId`) " +
" ON UPDATE NO ACTION ON DELETE NO ACTION ) " ) ;
database . execSQL ( " CREATE INDEX IF NOT EXISTS " +
" `index_TimelineStatusEntity_authorServerId_timelineUserId` " +
" ON `TimelineStatusEntity` (`authorServerId`, `timelineUserId`) " ) ;
}
} ;
2019-02-12 19:22:37 +01:00
public static final Migration MIGRATION_11_12 = new Migration ( 11 , 12 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
String defaultTabs = TabDataKt . HOME + " ; " +
TabDataKt . NOTIFICATIONS + " ; " +
TabDataKt . LOCAL + " ; " +
TabDataKt . FEDERATED ;
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `tabPreferences` TEXT NOT NULL DEFAULT ' " + defaultTabs + " ' " ) ;
database . execSQL ( " CREATE TABLE IF NOT EXISTS `ConversationEntity` ( " +
" `accountId` INTEGER NOT NULL, " +
" `id` TEXT NOT NULL, " +
" `accounts` TEXT NOT NULL, " +
" `unread` INTEGER NOT NULL, " +
" `s_id` TEXT NOT NULL, " +
" `s_url` TEXT, " +
" `s_inReplyToId` TEXT, " +
" `s_inReplyToAccountId` TEXT, " +
" `s_account` TEXT NOT NULL, " +
" `s_content` TEXT NOT NULL, " +
" `s_createdAt` INTEGER NOT NULL, " +
" `s_emojis` TEXT NOT NULL, " +
" `s_favouritesCount` INTEGER NOT NULL, " +
" `s_favourited` INTEGER NOT NULL, " +
" `s_sensitive` INTEGER NOT NULL, " +
" `s_spoilerText` TEXT NOT NULL, " +
" `s_attachments` TEXT NOT NULL, " +
" `s_mentions` TEXT NOT NULL, " +
" `s_showingHiddenContent` INTEGER NOT NULL, " +
" `s_expanded` INTEGER NOT NULL, " +
" `s_collapsible` INTEGER NOT NULL, " +
" `s_collapsed` INTEGER NOT NULL, " +
" PRIMARY KEY(`id`, `accountId`)) " ) ;
}
} ;
2019-02-13 19:20:31 +01:00
public static final Migration MIGRATION_12_13 = new Migration ( 12 , 13 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " DROP TABLE IF EXISTS `TimelineAccountEntity` " ) ;
database . execSQL ( " DROP TABLE IF EXISTS `TimelineStatusEntity` " ) ;
database . execSQL ( " CREATE TABLE IF NOT EXISTS `TimelineAccountEntity` ( " +
" `serverId` TEXT NOT NULL, " +
" `timelineUserId` INTEGER NOT NULL, " +
" `localUsername` TEXT NOT NULL, " +
" `username` TEXT NOT NULL, " +
" `displayName` TEXT NOT NULL, " +
" `url` TEXT NOT NULL, " +
" `avatar` TEXT NOT NULL, " +
" `emojis` TEXT NOT NULL, " +
" PRIMARY KEY(`serverId`, `timelineUserId`)) " ) ;
database . execSQL ( " CREATE TABLE IF NOT EXISTS `TimelineStatusEntity` ( " +
" `serverId` TEXT NOT NULL, " +
" `url` TEXT, " +
" `timelineUserId` INTEGER NOT NULL, " +
" `authorServerId` TEXT, " +
" `inReplyToId` TEXT, " +
" `inReplyToAccountId` TEXT, " +
" `content` TEXT, " +
" `createdAt` INTEGER NOT NULL, " +
" `emojis` TEXT, " +
" `reblogsCount` INTEGER NOT NULL, " +
" `favouritesCount` INTEGER NOT NULL, " +
" `reblogged` INTEGER NOT NULL, " +
" `favourited` INTEGER NOT NULL, " +
" `sensitive` INTEGER NOT NULL, " +
" `spoilerText` TEXT, " +
" `visibility` INTEGER, " +
" `attachments` TEXT, " +
" `mentions` TEXT, " +
" `application` TEXT, " +
" `reblogServerId` TEXT, " +
" `reblogAccountId` TEXT, " +
" PRIMARY KEY(`serverId`, `timelineUserId`), " +
" FOREIGN KEY(`authorServerId`, `timelineUserId`) REFERENCES `TimelineAccountEntity`(`serverId`, `timelineUserId`) " +
" ON UPDATE NO ACTION ON DELETE NO ACTION ) " ) ;
database . execSQL ( " CREATE INDEX IF NOT EXISTS " +
" `index_TimelineStatusEntity_authorServerId_timelineUserId` " +
" ON `TimelineStatusEntity` (`authorServerId`, `timelineUserId`) " ) ;
}
} ;
2019-04-22 10:11:00 +02:00
public static final Migration MIGRATION_10_13 = new Migration ( 10 , 13 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
MIGRATION_11_12 . migrate ( database ) ;
MIGRATION_12_13 . migrate ( database ) ;
}
} ;
2019-04-09 19:13:54 +02:00
public static final Migration MIGRATION_13_14 = new Migration ( 13 , 14 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `notificationsFilter` TEXT NOT NULL DEFAULT '[]' " ) ;
}
} ;
2019-04-22 10:11:00 +02:00
public static final Migration MIGRATION_14_15 = new Migration ( 14 , 15 ) {
2019-02-13 19:20:31 +01:00
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
2019-04-22 10:11:00 +02:00
database . execSQL ( " ALTER TABLE `TimelineStatusEntity` ADD COLUMN `poll` TEXT " ) ;
database . execSQL ( " ALTER TABLE `ConversationEntity` ADD COLUMN `s_poll` TEXT " ) ;
2019-02-13 19:20:31 +01:00
}
} ;
2019-05-02 19:44:35 +02:00
public static final Migration MIGRATION_15_16 = new Migration ( 15 , 16 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `notificationsPolls` INTEGER NOT NULL DEFAULT 1 " ) ;
}
} ;
2019-05-07 07:37:00 +02:00
public static final Migration MIGRATION_16_17 = new Migration ( 16 , 17 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `TimelineAccountEntity` ADD COLUMN `bot` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} ;
2019-07-28 19:59:52 +02:00
public static final Migration MIGRATION_17_18 = new Migration ( 17 , 18 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `alwaysOpenSpoiler` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} ;
2019-08-22 20:30:08 +02:00
public static final Migration MIGRATION_18_19 = new Migration ( 18 , 19 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `InstanceEntity` ADD COLUMN `maxPollOptions` INTEGER " ) ;
database . execSQL ( " ALTER TABLE `InstanceEntity` ADD COLUMN `maxPollOptionLength` INTEGER " ) ;
database . execSQL ( " ALTER TABLE `TootEntity` ADD COLUMN `poll` TEXT " ) ;
}
} ;
2019-11-19 10:15:32 +01:00
public static final Migration MIGRATION_19_20 = new Migration ( 19 , 20 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `TimelineStatusEntity` ADD COLUMN `bookmarked` INTEGER NOT NULL DEFAULT 0 " ) ;
database . execSQL ( " ALTER TABLE `ConversationEntity` ADD COLUMN `s_bookmarked` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2019-12-19 19:09:40 +01:00
} ;
public static final Migration MIGRATION_20_21 = new Migration ( 20 , 21 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `InstanceEntity` ADD COLUMN `version` TEXT " ) ;
}
2019-11-19 10:15:32 +01:00
} ;
2020-03-19 22:02:10 +01:00
public static final Migration MIGRATION_21_22 = new Migration ( 21 , 22 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `notificationsFollowRequested` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} ;
2020-03-24 21:06:04 +01:00
public static final Migration MIGRATION_22_23 = new Migration ( 22 , 23 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `TimelineStatusEntity` ADD COLUMN `muted` INTEGER " ) ;
}
} ;
2023-03-11 13:12:50 +01:00
2020-12-23 12:52:39 +01:00
public static final Migration MIGRATION_23_24 = new Migration ( 23 , 24 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `notificationsSubscriptions` INTEGER NOT NULL DEFAULT 1 " ) ;
}
} ;
2020-03-24 21:06:04 +01:00
2021-01-21 18:57:09 +01:00
public static final Migration MIGRATION_24_25 = new Migration ( 24 , 25 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL (
" CREATE TABLE IF NOT EXISTS `DraftEntity` ( " +
" `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
" `accountId` INTEGER NOT NULL, " +
" `inReplyToId` TEXT, " +
" `content` TEXT, " +
" `contentWarning` TEXT, " +
" `sensitive` INTEGER NOT NULL, " +
" `visibility` INTEGER NOT NULL, " +
" `attachments` TEXT NOT NULL, " +
" `poll` TEXT, " +
" `failedToSend` INTEGER NOT NULL) "
) ;
}
} ;
2021-05-16 19:17:56 +02:00
public static class Migration25_26 extends Migration {
private final File oldDraftDirectory ;
2023-07-06 19:37:51 +02:00
public Migration25_26 ( @Nullable File oldDraftDirectory ) {
2021-05-16 19:17:56 +02:00
super ( 25 , 26 ) ;
this . oldDraftDirectory = oldDraftDirectory ;
}
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " DROP TABLE `TootEntity` " ) ;
if ( oldDraftDirectory ! = null & & oldDraftDirectory . isDirectory ( ) ) {
File [ ] oldDraftFiles = oldDraftDirectory . listFiles ( ) ;
if ( oldDraftFiles ! = null ) {
for ( File file : oldDraftFiles ) {
if ( ! file . isDirectory ( ) ) {
file . delete ( ) ;
}
}
}
}
}
}
2021-06-17 18:54:56 +02:00
public static final Migration MIGRATION_26_27 = new Migration ( 26 , 27 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `ConversationEntity` ADD COLUMN `s_muted` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} ;
2022-01-11 19:00:29 +01:00
public static final Migration MIGRATION_27_28 = new Migration ( 27 , 28 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " DROP TABLE IF EXISTS `TimelineAccountEntity` " ) ;
database . execSQL ( " DROP TABLE IF EXISTS `TimelineStatusEntity` " ) ;
database . execSQL ( " CREATE TABLE IF NOT EXISTS `TimelineAccountEntity` ( " +
" `serverId` TEXT NOT NULL, " +
" `timelineUserId` INTEGER NOT NULL, " +
" `localUsername` TEXT NOT NULL, " +
" `username` TEXT NOT NULL, " +
" `displayName` TEXT NOT NULL, " +
" `url` TEXT NOT NULL, " +
" `avatar` TEXT NOT NULL, " +
" `emojis` TEXT NOT NULL, " +
" `bot` INTEGER NOT NULL, " +
" PRIMARY KEY(`serverId`, `timelineUserId`) ) " ) ;
database . execSQL ( " CREATE TABLE IF NOT EXISTS `TimelineStatusEntity` ( " +
" `serverId` TEXT NOT NULL, " +
" `url` TEXT, " +
" `timelineUserId` INTEGER NOT NULL, " +
" `authorServerId` TEXT, " +
" `inReplyToId` TEXT, " +
" `inReplyToAccountId` TEXT, " +
" `content` TEXT, " +
" `createdAt` INTEGER NOT NULL, " +
" `emojis` TEXT, " +
" `reblogsCount` INTEGER NOT NULL, " +
" `favouritesCount` INTEGER NOT NULL, " +
" `reblogged` INTEGER NOT NULL, " +
" `bookmarked` INTEGER NOT NULL, " +
" `favourited` INTEGER NOT NULL, " +
" `sensitive` INTEGER NOT NULL, " +
" `spoilerText` TEXT NOT NULL, " +
" `visibility` INTEGER NOT NULL, " +
" `attachments` TEXT, " +
" `mentions` TEXT, " +
" `application` TEXT, " +
" `reblogServerId` TEXT, " +
" `reblogAccountId` TEXT, " +
" `poll` TEXT, " +
" `muted` INTEGER, " +
" `expanded` INTEGER NOT NULL, " +
" `contentCollapsed` INTEGER NOT NULL, " +
" `contentShowing` INTEGER NOT NULL, " +
" `pinned` INTEGER NOT NULL, " +
" PRIMARY KEY(`serverId`, `timelineUserId`), " +
" FOREIGN KEY(`authorServerId`, `timelineUserId`) REFERENCES `TimelineAccountEntity`(`serverId`, `timelineUserId`) " +
" ON UPDATE NO ACTION ON DELETE NO ACTION ) " ) ;
database . execSQL ( " CREATE INDEX IF NOT EXISTS `index_TimelineStatusEntity_authorServerId_timelineUserId` " +
" ON `TimelineStatusEntity` (`authorServerId`, `timelineUserId`) " ) ;
}
} ;
2022-02-25 18:56:21 +01:00
public static final Migration MIGRATION_28_29 = new Migration ( 28 , 29 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
2022-02-27 20:16:41 +01:00
database . execSQL ( " ALTER TABLE `ConversationEntity` ADD COLUMN `s_tags` TEXT " ) ;
2022-02-25 18:56:21 +01:00
database . execSQL ( " ALTER TABLE `TimelineStatusEntity` ADD COLUMN `tags` TEXT " ) ;
}
} ;
2022-03-01 19:43:36 +01:00
public static final Migration MIGRATION_29_30 = new Migration ( 29 , 30 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `InstanceEntity` ADD COLUMN `charactersReservedPerUrl` INTEGER " ) ;
database . execSQL ( " ALTER TABLE `InstanceEntity` ADD COLUMN `minPollDuration` INTEGER " ) ;
database . execSQL ( " ALTER TABLE `InstanceEntity` ADD COLUMN `maxPollDuration` INTEGER " ) ;
}
} ;
2022-03-28 18:39:16 +02:00
public static final Migration MIGRATION_30_31 = new Migration ( 30 , 31 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
// no actual scheme change, but placeholder ids are now used differently so the cache needs to be cleared to avoid bugs
database . execSQL ( " DELETE FROM `TimelineAccountEntity` " ) ;
database . execSQL ( " DELETE FROM `TimelineStatusEntity` " ) ;
}
} ;
2022-04-14 19:39:30 +02:00
public static final Migration MIGRATION_31_32 = new Migration ( 31 , 32 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `notificationsSignUps` INTEGER NOT NULL DEFAULT 1 " ) ;
}
} ;
2022-04-15 13:20:27 +02:00
public static final Migration MIGRATION_32_33 = new Migration ( 32 , 33 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
// ConversationEntity lost the s_collapsible column
// since SQLite does not support removing columns and it is just a cache table, we recreate the whole table.
database . execSQL ( " DROP TABLE `ConversationEntity` " ) ;
database . execSQL ( " CREATE TABLE IF NOT EXISTS `ConversationEntity` ( " +
" `accountId` INTEGER NOT NULL, " +
" `id` TEXT NOT NULL, " +
" `accounts` TEXT NOT NULL, " +
" `unread` INTEGER NOT NULL, " +
" `s_id` TEXT NOT NULL, " +
" `s_url` TEXT, " +
" `s_inReplyToId` TEXT, " +
" `s_inReplyToAccountId` TEXT, " +
" `s_account` TEXT NOT NULL, " +
" `s_content` TEXT NOT NULL, " +
" `s_createdAt` INTEGER NOT NULL, " +
" `s_emojis` TEXT NOT NULL, " +
" `s_favouritesCount` INTEGER NOT NULL, " +
" `s_favourited` INTEGER NOT NULL, " +
" `s_bookmarked` INTEGER NOT NULL, " +
" `s_sensitive` INTEGER NOT NULL, " +
" `s_spoilerText` TEXT NOT NULL, " +
" `s_attachments` TEXT NOT NULL, " +
" `s_mentions` TEXT NOT NULL, " +
" `s_tags` TEXT, " +
" `s_showingHiddenContent` INTEGER NOT NULL, " +
" `s_expanded` INTEGER NOT NULL, " +
" `s_collapsed` INTEGER NOT NULL, " +
" `s_muted` INTEGER NOT NULL, " +
" `s_poll` TEXT, " +
" PRIMARY KEY(`id`, `accountId`)) " ) ;
}
} ;
2022-04-19 11:10:13 +02:00
public static final Migration MIGRATION_33_34 = new Migration ( 33 , 34 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `notificationsUpdates` INTEGER NOT NULL DEFAULT 1 " ) ;
}
} ;
2022-05-05 18:27:05 +02:00
public static final Migration MIGRATION_34_35 = new Migration ( 34 , 35 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `TimelineStatusEntity` ADD COLUMN `card` TEXT " ) ;
}
} ;
2022-05-17 19:32:09 +02:00
public static final Migration MIGRATION_35_36 = new Migration ( 35 , 36 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `oauthScopes` TEXT NOT NULL DEFAULT '' " ) ;
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `unifiedPushUrl` TEXT NOT NULL DEFAULT '' " ) ;
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `pushPubKey` TEXT NOT NULL DEFAULT '' " ) ;
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `pushPrivKey` TEXT NOT NULL DEFAULT '' " ) ;
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `pushAuth` TEXT NOT NULL DEFAULT '' " ) ;
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `pushServerKey` TEXT NOT NULL DEFAULT '' " ) ;
}
} ;
2022-05-20 16:47:45 +02:00
public static final Migration MIGRATION_36_37 = new Migration ( 36 , 37 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `TimelineStatusEntity` ADD COLUMN `repliesCount` INTEGER NOT NULL DEFAULT 0 " ) ;
database . execSQL ( " ALTER TABLE `ConversationEntity` ADD COLUMN `s_repliesCount` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} ;
2022-05-30 18:15:17 +02:00
public static final Migration MIGRATION_37_38 = new Migration ( 37 , 38 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
2022-05-30 19:06:14 +02:00
// database needs to be cleaned because the ConversationAccountEntity got a new attribute
database . execSQL ( " DELETE FROM `ConversationEntity` " ) ;
database . execSQL ( " ALTER TABLE `ConversationEntity` ADD COLUMN `order` INTEGER NOT NULL DEFAULT 0 " ) ;
2022-05-30 18:15:17 +02:00
2022-05-30 19:06:14 +02:00
// timestamps are now serialized differently so all cache tables that contain them need to be cleaned
2022-05-30 18:15:17 +02:00
database . execSQL ( " DELETE FROM `TimelineStatusEntity` " ) ;
}
} ;
2022-06-20 16:45:54 +02:00
public static final Migration MIGRATION_38_39 = new Migration ( 38 , 39 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `clientId` TEXT " ) ;
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `clientSecret` TEXT " ) ;
}
} ;
2022-07-26 20:24:50 +02:00
public static final Migration MIGRATION_39_40 = new Migration ( 39 , 40 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `InstanceEntity` ADD COLUMN `videoSizeLimit` INTEGER " ) ;
database . execSQL ( " ALTER TABLE `InstanceEntity` ADD COLUMN `imageSizeLimit` INTEGER " ) ;
database . execSQL ( " ALTER TABLE `InstanceEntity` ADD COLUMN `imageMatrixLimit` INTEGER " ) ;
database . execSQL ( " ALTER TABLE `InstanceEntity` ADD COLUMN `maxMediaAttachments` INTEGER " ) ;
database . execSQL ( " ALTER TABLE `InstanceEntity` ADD COLUMN `maxFields` INTEGER " ) ;
database . execSQL ( " ALTER TABLE `InstanceEntity` ADD COLUMN `maxFieldNameLength` INTEGER " ) ;
database . execSQL ( " ALTER TABLE `InstanceEntity` ADD COLUMN `maxFieldValueLength` INTEGER " ) ;
}
} ;
2022-07-27 21:06:51 +02:00
public static final Migration MIGRATION_40_41 = new Migration ( 40 , 41 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `DraftEntity` ADD COLUMN `scheduledAt` TEXT " ) ;
}
} ;
2022-08-31 18:53:57 +02:00
public static final Migration MIGRATION_41_42 = new Migration ( 41 , 42 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `DraftEntity` ADD COLUMN `language` TEXT " ) ;
database . execSQL ( " ALTER TABLE `TimelineStatusEntity` ADD COLUMN `language` TEXT " ) ;
database . execSQL ( " ALTER TABLE `ConversationEntity` ADD COLUMN `s_language` TEXT " ) ;
}
} ;
2022-11-24 15:45:19 +01:00
public static final Migration MIGRATION_42_43 = new Migration ( 42 , 43 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `defaultPostLanguage` TEXT NOT NULL DEFAULT '' " ) ;
}
} ;
2022-12-01 20:11:55 +01:00
public static final Migration MIGRATION_43_44 = new Migration ( 43 , 44 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `AccountEntity` ADD COLUMN `notificationsReports` INTEGER NOT NULL DEFAULT 1 " ) ;
}
} ;
2022-12-03 12:15:54 +01:00
public static final Migration MIGRATION_44_45 = new Migration ( 44 , 45 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `TimelineStatusEntity` ADD COLUMN `editedAt` INTEGER " ) ;
database . execSQL ( " ALTER TABLE `ConversationEntity` ADD COLUMN `s_editedAt` INTEGER " ) ;
}
} ;
2022-12-08 10:18:12 +01:00
public static final Migration MIGRATION_45_46 = new Migration ( 45 , 46 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `DraftEntity` ADD COLUMN `statusId` TEXT " ) ;
}
} ;
2023-01-27 20:50:45 +01:00
public static final Migration MIGRATION_46_47 = new Migration ( 46 , 47 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `DraftEntity` ADD COLUMN `failedToSendNew` INTEGER NOT NULL DEFAULT 0 " ) ;
2023-03-11 13:12:50 +01:00
}
} ;
public static final Migration MIGRATION_47_48 = new Migration ( 47 , 48 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase database ) {
database . execSQL ( " ALTER TABLE `TimelineStatusEntity` ADD COLUMN `filtered` TEXT " ) ;
2023-01-27 20:50:45 +01:00
}
} ;
2023-05-13 16:00:28 +02:00
@DeleteColumn ( tableName = " AccountEntity " , columnName = " activeNotifications " )
static class MIGRATION_49_50 implements AutoMigrationSpec { }
2020-03-19 22:02:10 +01:00
}