Skip to content

Commit

Permalink
Merge v186 and v185 migrations.
Browse files Browse the repository at this point in the history
  • Loading branch information
clark-signal authored and cody-signal committed Apr 20, 2023
1 parent 47ebcc0 commit 23a3d78
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 201 deletions.
Expand Up @@ -40,8 +40,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V181_ThreadTableFor
import org.thoughtcrime.securesms.database.helpers.migration.V182_CallTableMigration
import org.thoughtcrime.securesms.database.helpers.migration.V183_CallLinkTableMigration
import org.thoughtcrime.securesms.database.helpers.migration.V184_CallLinkReplaceIndexMigration
import org.thoughtcrime.securesms.database.helpers.migration.V185_MessageRecipientsMigration
import org.thoughtcrime.securesms.database.helpers.migration.V186_AddEditMessageColumnsMigration
import org.thoughtcrime.securesms.database.helpers.migration.V185_MessageRecipientsAndEditMessageMigration

/**
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
Expand All @@ -50,7 +49,7 @@ object SignalDatabaseMigrations {

val TAG: String = Log.tag(SignalDatabaseMigrations.javaClass)

const val DATABASE_VERSION = 186
const val DATABASE_VERSION = 185

@JvmStatic
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
Expand Down Expand Up @@ -199,11 +198,7 @@ object SignalDatabaseMigrations {
}

if (oldVersion < 185) {
V185_MessageRecipientsMigration.migrate(context, db, oldVersion, newVersion)
}

if (oldVersion < 186) {
V186_AddEditMessageColumnsMigration.migrate(context, db, oldVersion, newVersion)
V185_MessageRecipientsAndEditMessageMigration.migrate(context, db, oldVersion, newVersion)
}
}

Expand Down
Expand Up @@ -18,12 +18,20 @@ import org.thoughtcrime.securesms.recipients.RecipientId
import org.whispersystems.signalservice.api.push.ACI

/**
* This is a combination of the edit message and message recipient migrations (would have been V185 and v186), but as they
* both require recreating the message table, they are merged into one.
*
* Original V185:
* Our current column setup for knowing is the the sender/receiver of a message is both confusing and non-optimal from a performance perspective.
* This moves to a world where instead of tracking a single recipient, we track two: a sender and receiver.
*
* Original V186:
* Changes needed for edit message. New foreign keys require recreating the table.
*
*/
object V185_MessageRecipientsMigration : SignalDatabaseMigration {
object V185_MessageRecipientsAndEditMessageMigration : SignalDatabaseMigration {

private val TAG = Log.tag(V185_MessageRecipientsMigration::class.java)
private val TAG = Log.tag(V185_MessageRecipientsAndEditMessageMigration::class.java)

private val outgoingClause = "(" + listOf(21, 23, 22, 24, 25, 26, 2, 11)
.map { "type & ${0x1F} = $it" }
Expand Down Expand Up @@ -106,7 +114,10 @@ object V185_MessageRecipientsMigration : SignalDatabaseMigration {
parent_story_id INTEGER DEFAULT 0,
export_state BLOB DEFAULT NULL,
exported INTEGER DEFAULT 0,
scheduled_date INTEGER DEFAULT -1
scheduled_date INTEGER DEFAULT -1,
latest_revision_id INTEGER DEFAULT NULL REFERENCES message (_id) ON DELETE CASCADE,
original_message_id INTEGER DEFAULT NULL REFERENCES message (_id) ON DELETE CASCADE,
revision_number INTEGER DEFAULT 0
)
"""
)
Expand Down Expand Up @@ -164,7 +175,10 @@ object V185_MessageRecipientsMigration : SignalDatabaseMigration {
parent_story_id,
export_state,
exported,
scheduled_date
scheduled_date,
NULL AS latest_revision_id,
NULL AS original_message_id,
0 as revision_number
FROM message
"""
)
Expand Down Expand Up @@ -194,6 +208,8 @@ object V185_MessageRecipientsMigration : SignalDatabaseMigration {

dependentItems.forEach { item ->
val sql = when (item.name) {
"mms_thread_story_parent_story_scheduled_date_index" -> "CREATE INDEX message_thread_story_parent_story_scheduled_date_latest_revision_id_index ON message (thread_id, date_received, story_type, parent_story_id, scheduled_date, latest_revision_id)"
"mms_quote_id_quote_author_scheduled_date_index" -> "CREATE INDEX message_quote_id_quote_author_scheduled_date_latest_revision_id_index ON message (quote_id, quote_author, scheduled_date, latest_revision_id)"
"mms_date_sent_index" -> "CREATE INDEX message_date_sent_from_to_thread_index ON message (date_sent, from_recipient_id, to_recipient_id, thread_id)"
else -> item.createStatement.replace(Regex.fromLiteral("CREATE INDEX mms_"), "CREATE INDEX message_")
}
Expand Down

This file was deleted.

0 comments on commit 23a3d78

Please sign in to comment.