From a0131bf39b6a8e7e864dce800d84eb32c5d6aac0 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Wed, 22 May 2024 16:28:16 -0300 Subject: [PATCH] Fix db inconsistency. --- .../helpers/SignalDatabaseMigrations.kt | 6 ++- ...ixInAppPaymentTableDefaultNotifiedValue.kt | 53 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/database/helpers/migration/V233_FixInAppPaymentTableDefaultNotifiedValue.kt diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SignalDatabaseMigrations.kt b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SignalDatabaseMigrations.kt index 0053e46eb6..d1be3754f9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SignalDatabaseMigrations.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SignalDatabaseMigrations.kt @@ -90,6 +90,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V229_MarkMissedCall import org.thoughtcrime.securesms.database.helpers.migration.V230_UnreadCountIndices import org.thoughtcrime.securesms.database.helpers.migration.V231_ArchiveThumbnailColumns import org.thoughtcrime.securesms.database.helpers.migration.V232_CreateInAppPaymentTable +import org.thoughtcrime.securesms.database.helpers.migration.V233_FixInAppPaymentTableDefaultNotifiedValue /** * Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness. @@ -182,10 +183,11 @@ object SignalDatabaseMigrations { 229 to V229_MarkMissedCallEventsNotified, 230 to V230_UnreadCountIndices, 231 to V231_ArchiveThumbnailColumns, - 232 to V232_CreateInAppPaymentTable + 232 to V232_CreateInAppPaymentTable, + 233 to V233_FixInAppPaymentTableDefaultNotifiedValue ) - const val DATABASE_VERSION = 232 + const val DATABASE_VERSION = 233 @JvmStatic fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/migration/V233_FixInAppPaymentTableDefaultNotifiedValue.kt b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/migration/V233_FixInAppPaymentTableDefaultNotifiedValue.kt new file mode 100644 index 0000000000..217cfb03b1 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/migration/V233_FixInAppPaymentTableDefaultNotifiedValue.kt @@ -0,0 +1,53 @@ +/* + * Copyright 2024 Signal Messenger, LLC + * SPDX-License-Identifier: AGPL-3.0-only + */ + +package org.thoughtcrime.securesms.database.helpers.migration + +import android.app.Application +import net.zetetic.database.sqlcipher.SQLiteDatabase + +/** + * Updates notified default value from 0 to 1 + */ +@Suppress("ClassName") +object V233_FixInAppPaymentTableDefaultNotifiedValue : SignalDatabaseMigration { + override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { + db.execSQL( + """ + CREATE TABLE in_app_payment_tmp ( + _id INTEGER PRIMARY KEY, + type INTEGER NOT NULL, + state INTEGER NOT NULL, + inserted_at INTEGER NOT NULL, + updated_at INTEGER NOT NULL, + notified INTEGER DEFAULT 1, + subscriber_id TEXT, + end_of_period INTEGER DEFAULT 0, + data BLOB NOT NULL + ) + """.trimIndent() + ) + + db.execSQL( + """ + INSERT INTO in_app_payment_tmp + SELECT + _id, + type, + state, + inserted_at, + updated_at, + notified, + subscriber_id, + end_of_period, + data + FROM in_app_payment + """.trimIndent() + ) + + db.execSQL("DROP TABLE in_app_payment") + db.execSQL("ALTER TABLE in_app_payment_tmp RENAME TO in_app_payment") + } +}