Fix crash with missing last_resort_key_tuple table.

This commit is contained in:
Cody Henthorne
2025-10-15 14:21:41 -04:00
committed by GitHub
parent 7b6c2fa729
commit 56725f0f5c
5 changed files with 38 additions and 4 deletions

View File

@@ -23,7 +23,7 @@ class LastResortKeyTupleTable(context: Context, databaseHelper: SignalDatabase)
companion object {
private val TAG = Log.tag(LastResortKeyTupleTable::class)
private const val TABLE_NAME = "last_resort_key_tuple"
const val TABLE_NAME = "last_resort_key_tuple"
private const val ID = "_id"
private const val KYBER_PREKEY = "kyber_prekey_id"

View File

@@ -149,6 +149,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V291_NullOutRemoteK
import org.thoughtcrime.securesms.database.helpers.migration.V292_AddPollTables
import org.thoughtcrime.securesms.database.helpers.migration.V293_LastResortKeyTupleTableMigration
import org.thoughtcrime.securesms.database.helpers.migration.V294_RemoveLastResortKeyTupleColumnConstraintMigration
import org.thoughtcrime.securesms.database.helpers.migration.V295_AddLastRestoreKeyTypeTableIfMissingMigration
import org.thoughtcrime.securesms.database.SQLiteDatabase as SignalSqliteDatabase
/**
@@ -303,10 +304,11 @@ object SignalDatabaseMigrations {
291 to V291_NullOutRemoteKeyIfEmpty,
292 to V292_AddPollTables,
293 to V293_LastResortKeyTupleTableMigration,
294 to V294_RemoveLastResortKeyTupleColumnConstraintMigration
294 to V294_RemoveLastResortKeyTupleColumnConstraintMigration,
295 to V295_AddLastRestoreKeyTypeTableIfMissingMigration
)
const val DATABASE_VERSION = 294
const val DATABASE_VERSION = 295
@JvmStatic
fun migrate(context: Application, db: SignalSqliteDatabase, oldVersion: Int, newVersion: Int) {

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2025 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.database.helpers.migration
import android.app.Application
import org.thoughtcrime.securesms.database.SQLiteDatabase
/**
* Creates the LastResortKeyTuple table if missed getting created on backup or device transfer import.
*/
@Suppress("ClassName")
object V295_AddLastRestoreKeyTypeTableIfMissingMigration : SignalDatabaseMigration {
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
db.execSQL(
"""
CREATE TABLE IF NOT EXISTS last_resort_key_tuple (
_id INTEGER PRIMARY KEY,
kyber_prekey_id INTEGER NOT NULL REFERENCES kyber_prekey (_id) ON DELETE CASCADE,
signed_key_id INTEGER NOT NULL,
public_key BLOB NOT NULL,
UNIQUE(kyber_prekey_id, signed_key_id, public_key)
)
""".trimIndent()
)
}
}