Add back missing reaction triggers.

main
Greyson Parrelli 2022-12-13 11:57:04 -05:00 zatwierdzone przez Cody Henthorne
rodzic 21a8434e4d
commit ebe82cf3e6
2 zmienionych plików z 45 dodań i 1 usunięć

Wyświetl plik

@ -22,6 +22,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V163_RemoteMegaphon
import org.thoughtcrime.securesms.database.helpers.migration.V164_ThreadDatabaseReadIndexMigration
import org.thoughtcrime.securesms.database.helpers.migration.V165_MmsMessageBoxPaymentTransactionIndexMigration
import org.thoughtcrime.securesms.database.helpers.migration.V166_ThreadAndMessageForeignKeys
import org.thoughtcrime.securesms.database.helpers.migration.V167_RecreateReactionTriggers
/**
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
@ -30,7 +31,7 @@ object SignalDatabaseMigrations {
val TAG: String = Log.tag(SignalDatabaseMigrations.javaClass)
const val DATABASE_VERSION = 166
const val DATABASE_VERSION = 167
@JvmStatic
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
@ -105,6 +106,10 @@ object SignalDatabaseMigrations {
if (oldVersion < 166) {
V166_ThreadAndMessageForeignKeys.migrate(context, db, oldVersion, newVersion)
}
if (oldVersion < 167) {
V167_RecreateReactionTriggers.migrate(context, db, oldVersion, newVersion)
}
}
@JvmStatic

Wyświetl plik

@ -0,0 +1,39 @@
package org.thoughtcrime.securesms.database.helpers.migration
import android.app.Application
import net.zetetic.database.sqlcipher.SQLiteDatabase
/**
* Forgot to recreate the triggers for the reactions table in [V166_ThreadAndMessageForeignKeys]. So we gotta fix stuff up and do it here.
*/
object V167_RecreateReactionTriggers : SignalDatabaseMigration {
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
db.execSQL(
"""
DELETE FROM reaction
WHERE
(is_mms = 0 AND message_id NOT IN (SELECT _id FROM sms))
OR
(is_mms = 1 AND message_id NOT IN (SELECT _id FROM mms))
"""
)
db.execSQL(
"""
CREATE TRIGGER IF NOT EXISTS reactions_sms_delete AFTER DELETE ON sms
BEGIN
DELETE FROM reaction WHERE message_id = old._id AND is_mms = 0;
END
"""
)
db.execSQL(
"""
CREATE TRIGGER IF NOT EXISTS reactions_mms_delete AFTER DELETE ON mms
BEGIN
DELETE FROM reaction WHERE message_id = old._id AND is_mms = 1;
END
"""
)
}
}