Add 'outbox_state' table to database

This commit is contained in:
cketti 2018-12-02 05:13:43 +01:00
parent 4160a1b4ee
commit 03f0fa9f0f
4 changed files with 45 additions and 1 deletions

View file

@ -378,6 +378,9 @@ public class LockableDatabase {
}
doOpenOrCreateDb(databaseFile);
}
mDb.execSQL("PRAGMA foreign_keys = ON;");
if (mDb.getVersion() != mSchemaDefinition.getVersion()) {
mSchemaDefinition.doDbUpgrade(mDb);
}

View file

@ -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)");

View file

@ -0,0 +1,31 @@
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()
)
}
}

View file

@ -92,6 +92,8 @@ public class Migrations {
MigrationTo66.addEncryptionTypeColumnToMessagesTable(db);
case 66:
MigrationTo67.addTypeColumnToFoldersTable(db, migrationsHelper);
case 67:
MigrationTo68.addOutboxStateTable(db);
}
if (shouldBuildFtsTable) {