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

Commit 03f0fa9f authored by cketti's avatar cketti
Browse files

Add 'outbox_state' table to database

parent 4160a1b4
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -378,6 +378,9 @@ public class LockableDatabase {
                }
                doOpenOrCreateDb(databaseFile);
            }

            mDb.execSQL("PRAGMA foreign_keys = ON;");

            if (mDb.getVersion() != mSchemaDefinition.getVersion()) {
                mSchemaDefinition.doDbUpgrade(mDb);
            }
+9 −1
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 = 67;
    static final int DB_VERSION = 68;

    private final MigrationsHelper migrationsHelper;

@@ -209,6 +209,14 @@ class StoreSchemaDefinition implements SchemaDefinition {
                "UPDATE threads SET root=id WHERE root IS NULL AND ROWID = NEW.ROWID; " +
                "END");

        db.execSQL("DROP TABLE IF EXISTS outbox_state");
        db.execSQL("CREATE TABLE outbox_state (" +
                "message_id INTEGER PRIMARY KEY NOT NULL REFERENCES messages(id) ON DELETE CASCADE," +
                "send_state TEXT," +
                "number_of_send_attempts INTEGER DEFAULT 0," +
                "error_timestamp INTEGER DEFAULT 0," +
                "error TEXT)");

        db.execSQL("DROP TABLE IF EXISTS pending_commands");
        db.execSQL("CREATE TABLE pending_commands " +
                "(id INTEGER PRIMARY KEY, command TEXT, data TEXT)");
+31 −0
Original line number Diff line number Diff line
package com.fsck.k9.storage.migrations

import android.database.sqlite.SQLiteDatabase


internal object MigrationTo68 {
    @JvmStatic
    fun addOutboxStateTable(db: SQLiteDatabase) {
        createOutboxStateTable(db)
        createOutboxStateEntries(db)
    }

    private fun createOutboxStateTable(db: SQLiteDatabase) {
        db.execSQL("CREATE TABLE outbox_state (" +
                "message_id INTEGER PRIMARY KEY NOT NULL REFERENCES messages(id) ON DELETE CASCADE," +
                "send_state TEXT," +
                "number_of_send_attempts INTEGER DEFAULT 0," +
                "error_timestamp INTEGER DEFAULT 0," +
                "error TEXT)")
    }

    private fun createOutboxStateEntries(db: SQLiteDatabase) {
        db.execSQL("""
            INSERT INTO outbox_state (message_id, send_state)
              SELECT messages.id, 'ready' FROM folders
                JOIN messages ON (folders.id = messages.folder_id)
                WHERE folders.server_id = 'K9MAIL_INTERNAL_OUTBOX'
            """.trimIndent()
        )
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -92,6 +92,8 @@ public class Migrations {
                MigrationTo66.addEncryptionTypeColumnToMessagesTable(db);
            case 66:
                MigrationTo67.addTypeColumnToFoldersTable(db, migrationsHelper);
            case 67:
                MigrationTo68.addOutboxStateTable(db);
        }

        if (shouldBuildFtsTable) {