Fix bad unread mentions database migration.

main
Cody Henthorne 2022-10-31 12:52:50 -04:00
rodzic 06c9dbe6ec
commit e00ed81e7c
3 zmienionych plików z 45 dodań i 2 usunięć

Wyświetl plik

@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.database.helpers
import android.app.Application
import android.content.Context
import net.zetetic.database.sqlcipher.SQLiteDatabase
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.database.helpers.migration.V149_LegacyMigrations
import org.thoughtcrime.securesms.database.helpers.migration.V150_UrgentMslFlagMigration
import org.thoughtcrime.securesms.database.helpers.migration.V151_MyStoryMigration
@ -16,13 +17,16 @@ import org.thoughtcrime.securesms.database.helpers.migration.V158_GroupsLastForc
import org.thoughtcrime.securesms.database.helpers.migration.V159_ThreadUnreadSelfMentionCount
import org.thoughtcrime.securesms.database.helpers.migration.V160_SmsMmsExportedIndexMigration
import org.thoughtcrime.securesms.database.helpers.migration.V161_StorySendMessageIdIndex
import org.thoughtcrime.securesms.database.helpers.migration.V162_ThreadUnreadSelfMentionCountFixup
/**
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
*/
object SignalDatabaseMigrations {
const val DATABASE_VERSION = 161
val TAG: String = Log.tag(SignalDatabaseMigrations.javaClass)
const val DATABASE_VERSION = 162
@JvmStatic
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
@ -77,6 +81,10 @@ object SignalDatabaseMigrations {
if (oldVersion < 161) {
V161_StorySendMessageIdIndex.migrate(context, db, oldVersion, newVersion)
}
if (oldVersion < 162) {
V162_ThreadUnreadSelfMentionCountFixup.migrate(context, db, oldVersion, newVersion)
}
}
@JvmStatic

Wyświetl plik

@ -58,7 +58,7 @@ import java.util.UUID
*/
object V149_LegacyMigrations : SignalDatabaseMigration {
private val TAG: String = Log.tag(SignalDatabaseMigrations.javaClass)
private val TAG: String = SignalDatabaseMigrations.TAG
private const val RECIPIENT_CALL_RINGTONE_VERSION = 2
const val MIGRATE_PREKEYS_VERSION = 3

Wyświetl plik

@ -0,0 +1,35 @@
package org.thoughtcrime.securesms.database.helpers.migration
import android.app.Application
import androidx.sqlite.db.SupportSQLiteDatabase
import net.zetetic.database.sqlcipher.SQLiteDatabase
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.database.helpers.SignalDatabaseMigrations
/**
* A bad cherry-pick for a database change requires us to attempt to alter the table again
* to fix it.
*/
object V162_ThreadUnreadSelfMentionCountFixup : SignalDatabaseMigration {
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
if (columnMissing(db, "thread", "unread_self_mention_count")) {
Log.i(SignalDatabaseMigrations.TAG, "Fixing up thread table and unread_self_mention_count column")
db.execSQL("ALTER TABLE thread ADD COLUMN unread_self_mention_count INTEGER DEFAULT 0")
}
}
@Suppress("SameParameterValue")
private fun columnMissing(db: SupportSQLiteDatabase, table: String, column: String): Boolean {
db.query("PRAGMA table_info($table)", null).use { cursor ->
val nameColumnIndex = cursor.getColumnIndexOrThrow("name")
while (cursor.moveToNext()) {
val name = cursor.getString(nameColumnIndex)
if (name == column) {
return false
}
}
}
return true
}
}