kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix bad unread mentions database migration.
rodzic
06c9dbe6ec
commit
e00ed81e7c
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.database.helpers
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import net.zetetic.database.sqlcipher.SQLiteDatabase
|
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.V149_LegacyMigrations
|
||||||
import org.thoughtcrime.securesms.database.helpers.migration.V150_UrgentMslFlagMigration
|
import org.thoughtcrime.securesms.database.helpers.migration.V150_UrgentMslFlagMigration
|
||||||
import org.thoughtcrime.securesms.database.helpers.migration.V151_MyStoryMigration
|
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.V159_ThreadUnreadSelfMentionCount
|
||||||
import org.thoughtcrime.securesms.database.helpers.migration.V160_SmsMmsExportedIndexMigration
|
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.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.
|
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
|
||||||
*/
|
*/
|
||||||
object SignalDatabaseMigrations {
|
object SignalDatabaseMigrations {
|
||||||
|
|
||||||
const val DATABASE_VERSION = 161
|
val TAG: String = Log.tag(SignalDatabaseMigrations.javaClass)
|
||||||
|
|
||||||
|
const val DATABASE_VERSION = 162
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||||
|
@ -77,6 +81,10 @@ object SignalDatabaseMigrations {
|
||||||
if (oldVersion < 161) {
|
if (oldVersion < 161) {
|
||||||
V161_StorySendMessageIdIndex.migrate(context, db, oldVersion, newVersion)
|
V161_StorySendMessageIdIndex.migrate(context, db, oldVersion, newVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldVersion < 162) {
|
||||||
|
V162_ThreadUnreadSelfMentionCountFixup.migrate(context, db, oldVersion, newVersion)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
|
|
@ -58,7 +58,7 @@ import java.util.UUID
|
||||||
*/
|
*/
|
||||||
object V149_LegacyMigrations : SignalDatabaseMigration {
|
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
|
private const val RECIPIENT_CALL_RINGTONE_VERSION = 2
|
||||||
const val MIGRATE_PREKEYS_VERSION = 3
|
const val MIGRATE_PREKEYS_VERSION = 3
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
Ładowanie…
Reference in New Issue