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

Commit f491e00b authored by Philip's avatar Philip Committed by GitHub
Browse files

Merge pull request #2158 from philipwhiuk/databaseMigrationVerification

Test and fix database upgrade process
parents b79673bf a52e0bd6
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ public class LocalStore extends Store implements Serializable {
     */
    private static final int THREAD_FLAG_UPDATE_BATCH_SIZE = 500;

    public static final int DB_VERSION = 58;
    public static final int DB_VERSION = 59;


    public static String getColumnNameForFlag(Flag flag) {
@@ -258,6 +258,10 @@ public class LocalStore extends Store implements Serializable {
        database.switchProvider(newStorageProviderId);
    }

    Context getContext() {
        return context;
    }

    protected Account getAccount() {
        return mAccount;
    }
+1 −1
Original line number Diff line number Diff line
@@ -238,7 +238,7 @@ class StoreSchemaDefinition implements LockableDatabase.SchemaDefinition {

        @Override
        public Context getContext() {
            return localStore.context;
            return localStore.getContext();
        }

        @Override
+4 −0
Original line number Diff line number Diff line
@@ -162,6 +162,10 @@ class MigrationTo51 {
    }

    private static void cleanUpOldAttachmentDirectory(File attachmentDirOld) {
        if (!attachmentDirOld.exists()) {
            Log.d(K9.LOG_TAG, "Old attachment directory doesn't exist: " + attachmentDirOld.getAbsolutePath());
            return;
        }
        for (File file : attachmentDirOld.listFiles()) {
            Log.d(K9.LOG_TAG, "deleting stale attachment file: " + file.getName());
            if (file.exists() && !file.delete()) {
+41 −0
Original line number Diff line number Diff line
package com.fsck.k9.mailstore.migrations;


import android.database.sqlite.SQLiteDatabase;


class MigrationTo59 {
    static void addMissingIndexes(SQLiteDatabase db) {
        addMessageCompositeIndex(db);
        addMessageEmptyIndex(db);
        addMessageFlaggedIndex(db);
        addMessageFolderIdDeletedDateIndex(db);
        addMessageReadIndex(db);
        addMessageUidIndex(db);
        addMessageReadIndex(db);
    }

    private static void addMessageCompositeIndex(SQLiteDatabase db) {
        db.execSQL("CREATE INDEX IF NOT EXISTS msg_composite ON messages (deleted, empty,folder_id,flagged,read)");
    }

    private static void addMessageEmptyIndex(SQLiteDatabase db) {
        db.execSQL("CREATE INDEX IF NOT EXISTS msg_empty ON messages (empty)");
    }

    private static void addMessageFlaggedIndex(SQLiteDatabase db) {
        db.execSQL("CREATE INDEX IF NOT EXISTS msg_flagged ON messages (flagged)");
    }

    private static void addMessageFolderIdDeletedDateIndex(SQLiteDatabase db) {
        db.execSQL("CREATE INDEX IF NOT EXISTS msg_folder_id_deleted_date ON messages (folder_id,deleted,internal_date)");
    }

    private static void addMessageReadIndex(SQLiteDatabase db) {
        db.execSQL("CREATE INDEX IF NOT EXISTS msg_read ON messages (read)");
    }

    private static void addMessageUidIndex(SQLiteDatabase db) {
        db.execSQL("CREATE INDEX IF NOT EXISTS msg_uid ON messages (uid, folder_id)");
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ public class Migrations {
            case 57:
                MigrationTo58.cleanUpOrphanedData(db);
                MigrationTo58.createDeleteMessageTrigger(db);
            case 58:
                MigrationTo59.addMissingIndexes(db);
        }
    }
}
Loading