Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bad unread mentions database migration.
- Loading branch information
1 parent
06c9dbe
commit e00ed81
Showing
3 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...oughtcrime/securesms/database/helpers/migration/V162_ThreadUnreadSelfMentionCountFixup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |