Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fbf4f448 authored by cketti's avatar cketti
Browse files

Add 'type' column to 'folders' table

parent bb87dcc9
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ import timber.log.Timber;


class StoreSchemaDefinition implements SchemaDefinition {
    static final int DB_VERSION = 66;
    static final int DB_VERSION = 67;

    private final MigrationsHelper migrationsHelper;

@@ -93,7 +93,8 @@ class StoreSchemaDefinition implements SchemaDefinition {
                "notify_class TEXT default '"+ Folder.FolderClass.INHERITED.name() + "', " +
                "more_messages TEXT default \"unknown\", " +
                "server_id TEXT, " +
                "local_only INTEGER" +
                "local_only INTEGER, " +
                "type TEXT DEFAULT \"regular\"" +
                ")");

        db.execSQL("DROP INDEX IF EXISTS folder_server_id");
+27 −0
Original line number Diff line number Diff line
package com.fsck.k9.storage.migrations

import android.database.sqlite.SQLiteDatabase
import com.fsck.k9.mailstore.MigrationsHelper


internal object MigrationTo67 {
    @JvmStatic
    fun addTypeColumnToFoldersTable(db: SQLiteDatabase, migrationsHelper: MigrationsHelper) {
        db.execSQL("ALTER TABLE folders ADD type TEXT DEFAULT \"regular\"")

        val account = migrationsHelper.account
        setFolderType(db, account.inboxFolder, "inbox")
        setFolderType(db, account.outboxFolder, "outbox")
        setFolderType(db, account.trashFolder, "trash")
        setFolderType(db, account.draftsFolder, "drafts")
        setFolderType(db, account.spamFolder, "spam")
        setFolderType(db, account.sentFolder, "sent")
        setFolderType(db, account.archiveFolder, "archive")
    }

    private fun setFolderType(db: SQLiteDatabase, serverId: String?, type: String) {
        if (serverId != null) {
            db.execSQL("UPDATE folders SET type = ? WHERE server_id = ?", arrayOf(type, serverId))
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -90,6 +90,8 @@ public class Migrations {
                MigrationTo65.addLocalOnlyColumnToFoldersTable(db, migrationsHelper);
            case 65:
                MigrationTo66.addEncryptionTypeColumnToMessagesTable(db);
            case 66:
                MigrationTo67.addTypeColumnToFoldersTable(db, migrationsHelper);
        }

        if (shouldBuildFtsTable) {
+7 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;

import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.core.BuildConfig;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.MessagingException;
@@ -371,6 +372,12 @@ public class StoreSchemaDefinitionTest extends K9RobolectricTest {
    private Account createAccount() {
        Account account = mock(Account.class);
        when(account.getInboxFolder()).thenReturn("Inbox");
        when(account.getOutboxFolder()).thenReturn(Account.OUTBOX);
        when(account.getTrashFolder()).thenReturn("Trash");
        when(account.getDraftsFolder()).thenReturn("Drafts");
        when(account.getSpamFolder()).thenReturn("Spam");
        when(account.getSentFolder()).thenReturn("Sent");
        when(account.getArchiveFolder()).thenReturn(null);
        when(account.getLocalStorageProviderId()).thenReturn(StorageManager.InternalStorageProvider.ID);
        when(account.getStoreUri()).thenReturn("dummy://");
        return account;