Add 'new_message' column to 'messages' table
This commit is contained in:
parent
4e457c987c
commit
245404d6e4
3 changed files with 41 additions and 2 deletions
|
@ -12,7 +12,7 @@ import timber.log.Timber;
|
|||
|
||||
|
||||
class StoreSchemaDefinition implements SchemaDefinition {
|
||||
static final int DB_VERSION = 81;
|
||||
static final int DB_VERSION = 82;
|
||||
|
||||
private final MigrationsHelper migrationsHelper;
|
||||
|
||||
|
@ -140,9 +140,20 @@ class StoreSchemaDefinition implements SchemaDefinition {
|
|||
"answered INTEGER default 0, " +
|
||||
"forwarded INTEGER default 0, " +
|
||||
"message_part_id INTEGER," +
|
||||
"encryption_type TEXT" +
|
||||
"encryption_type TEXT," +
|
||||
"new_message INTEGER DEFAULT 0" +
|
||||
")");
|
||||
|
||||
db.execSQL("DROP INDEX IF EXISTS new_messages");
|
||||
db.execSQL("CREATE INDEX IF NOT EXISTS new_messages ON messages(new_message)");
|
||||
|
||||
db.execSQL("CREATE TRIGGER new_message_reset " +
|
||||
"AFTER UPDATE OF read ON messages " +
|
||||
"FOR EACH ROW WHEN NEW.read = 1 AND NEW.new_message = 1 " +
|
||||
"BEGIN " +
|
||||
"UPDATE messages SET new_message = 0 WHERE ROWID = NEW.ROWID; " +
|
||||
"END");
|
||||
|
||||
db.execSQL("DROP TABLE IF EXISTS message_parts");
|
||||
db.execSQL("CREATE TABLE message_parts (" +
|
||||
"id INTEGER PRIMARY KEY, " +
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.fsck.k9.storage.migrations
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
|
||||
/**
|
||||
* Add 'new_message' column to 'messages' table.
|
||||
*/
|
||||
internal class MigrationTo82(private val db: SQLiteDatabase) {
|
||||
fun addNewMessageColumn() {
|
||||
db.execSQL("ALTER TABLE messages ADD new_message INTEGER DEFAULT 0")
|
||||
|
||||
db.execSQL("DROP INDEX IF EXISTS new_messages")
|
||||
db.execSQL("CREATE INDEX IF NOT EXISTS new_messages ON messages(new_message)")
|
||||
|
||||
db.execSQL(
|
||||
"CREATE TRIGGER new_message_reset " +
|
||||
"AFTER UPDATE OF read ON messages " +
|
||||
"FOR EACH ROW WHEN NEW.read = 1 AND NEW.new_message = 1 " +
|
||||
"BEGIN " +
|
||||
"UPDATE messages SET new_message = 0 WHERE ROWID = NEW.ROWID; " +
|
||||
"END"
|
||||
)
|
||||
|
||||
// Mark messages with existing notifications as "new"
|
||||
db.execSQL("UPDATE messages SET new_message = 1 WHERE id in (SELECT message_id FROM notifications)")
|
||||
}
|
||||
}
|
|
@ -27,5 +27,6 @@ object Migrations {
|
|||
if (oldVersion < 79) MigrationTo79(db).updateDeleteMessageTrigger()
|
||||
if (oldVersion < 80) MigrationTo80(db).rewriteLastUpdatedColumn()
|
||||
if (oldVersion < 81) MigrationTo81(db).addNotificationsTable()
|
||||
if (oldVersion < 82) MigrationTo82(db).addNewMessageColumn()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue