mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 20:48:43 +00:00
Add foreign key reference to notification profile members.
This commit is contained in:
@@ -52,7 +52,7 @@ class NotificationProfileTables(context: Context, databaseHelper: SignalDatabase
|
|||||||
val CREATE_TABLE: Array<String> = arrayOf(NotificationProfileTable.CREATE_TABLE, NotificationProfileScheduleTable.CREATE_TABLE, NotificationProfileAllowedMembersTable.CREATE_TABLE)
|
val CREATE_TABLE: Array<String> = arrayOf(NotificationProfileTable.CREATE_TABLE, NotificationProfileScheduleTable.CREATE_TABLE, NotificationProfileAllowedMembersTable.CREATE_TABLE)
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
val CREATE_INDEXES: Array<String> = arrayOf(NotificationProfileScheduleTable.CREATE_INDEX, NotificationProfileAllowedMembersTable.CREATE_INDEX)
|
val CREATE_INDEXES: Array<String> = arrayOf(NotificationProfileScheduleTable.CREATE_INDEX, NotificationProfileAllowedMembersTable.CREATE_NOTIFICATION_PROFILE_INDEX, NotificationProfileAllowedMembersTable.CREATE_RECIPIENT_ID_INDEX)
|
||||||
}
|
}
|
||||||
|
|
||||||
object NotificationProfileTable {
|
object NotificationProfileTable {
|
||||||
@@ -124,12 +124,13 @@ class NotificationProfileTables(context: Context, databaseHelper: SignalDatabase
|
|||||||
CREATE TABLE $TABLE_NAME (
|
CREATE TABLE $TABLE_NAME (
|
||||||
$ID INTEGER PRIMARY KEY AUTOINCREMENT,
|
$ID INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
$NOTIFICATION_PROFILE_ID INTEGER NOT NULL REFERENCES ${NotificationProfileTable.TABLE_NAME} (${NotificationProfileTable.ID}) ON DELETE CASCADE,
|
$NOTIFICATION_PROFILE_ID INTEGER NOT NULL REFERENCES ${NotificationProfileTable.TABLE_NAME} (${NotificationProfileTable.ID}) ON DELETE CASCADE,
|
||||||
$RECIPIENT_ID INTEGER NOT NULL,
|
$RECIPIENT_ID INTEGER NOT NULL REFERENCES ${RecipientTable.TABLE_NAME} (${RecipientTable.ID}) ON DELETE CASCADE,
|
||||||
UNIQUE($NOTIFICATION_PROFILE_ID, $RECIPIENT_ID) ON CONFLICT REPLACE
|
UNIQUE($NOTIFICATION_PROFILE_ID, $RECIPIENT_ID) ON CONFLICT REPLACE
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
const val CREATE_INDEX = "CREATE INDEX notification_profile_allowed_members_profile_index ON $TABLE_NAME ($NOTIFICATION_PROFILE_ID)"
|
const val CREATE_NOTIFICATION_PROFILE_INDEX = "CREATE INDEX notification_profile_allowed_members_profile_index ON $TABLE_NAME ($NOTIFICATION_PROFILE_ID)"
|
||||||
|
const val CREATE_RECIPIENT_ID_INDEX = "CREATE INDEX notification_profile_allowed_members_recipient_index ON $TABLE_NAME ($RECIPIENT_ID)"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createProfile(name: String, emoji: String, color: AvatarColor, createdAt: Long): NotificationProfileChangeResult {
|
fun createProfile(name: String, emoji: String, color: AvatarColor, createdAt: Long): NotificationProfileChangeResult {
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V275_EnsureDefaultA
|
|||||||
import org.thoughtcrime.securesms.database.helpers.migration.V276_AttachmentCdnDefaultValueMigration
|
import org.thoughtcrime.securesms.database.helpers.migration.V276_AttachmentCdnDefaultValueMigration
|
||||||
import org.thoughtcrime.securesms.database.helpers.migration.V277_AddNotificationProfileStorageSync
|
import org.thoughtcrime.securesms.database.helpers.migration.V277_AddNotificationProfileStorageSync
|
||||||
import org.thoughtcrime.securesms.database.helpers.migration.V278_BackupSnapshotTableVersions
|
import org.thoughtcrime.securesms.database.helpers.migration.V278_BackupSnapshotTableVersions
|
||||||
|
import org.thoughtcrime.securesms.database.helpers.migration.V279_AddNotificationProfileForeignKey
|
||||||
import org.thoughtcrime.securesms.database.SQLiteDatabase as SignalSqliteDatabase
|
import org.thoughtcrime.securesms.database.SQLiteDatabase as SignalSqliteDatabase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -271,10 +272,11 @@ object SignalDatabaseMigrations {
|
|||||||
275 to V275_EnsureDefaultAllChatsFolder,
|
275 to V275_EnsureDefaultAllChatsFolder,
|
||||||
276 to V276_AttachmentCdnDefaultValueMigration,
|
276 to V276_AttachmentCdnDefaultValueMigration,
|
||||||
277 to V277_AddNotificationProfileStorageSync,
|
277 to V277_AddNotificationProfileStorageSync,
|
||||||
278 to V278_BackupSnapshotTableVersions
|
278 to V278_BackupSnapshotTableVersions,
|
||||||
|
279 to V279_AddNotificationProfileForeignKey
|
||||||
)
|
)
|
||||||
|
|
||||||
const val DATABASE_VERSION = 278
|
const val DATABASE_VERSION = 279
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun migrate(context: Application, db: SignalSqliteDatabase, oldVersion: Int, newVersion: Int) {
|
fun migrate(context: Application, db: SignalSqliteDatabase, oldVersion: Int, newVersion: Int) {
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package org.thoughtcrime.securesms.database.helpers.migration
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import org.thoughtcrime.securesms.database.SQLiteDatabase
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a recipient foreign key constraint to notification profile members
|
||||||
|
*/
|
||||||
|
object V279_AddNotificationProfileForeignKey : SignalDatabaseMigration {
|
||||||
|
|
||||||
|
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||||
|
db.execSQL("DROP INDEX IF EXISTS notification_profile_allowed_members_profile_index")
|
||||||
|
|
||||||
|
db.execSQL(
|
||||||
|
"""
|
||||||
|
CREATE TABLE notification_profile_allowed_members_tmp (
|
||||||
|
_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
notification_profile_id INTEGER NOT NULL REFERENCES notification_profile (_id) ON DELETE CASCADE,
|
||||||
|
recipient_id INTEGER NOT NULL REFERENCES recipient (_id) ON DELETE CASCADE,
|
||||||
|
UNIQUE(notification_profile_id, recipient_id) ON CONFLICT REPLACE
|
||||||
|
)
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
db.execSQL(
|
||||||
|
"""
|
||||||
|
INSERT INTO notification_profile_allowed_members_tmp (_id, notification_profile_id, recipient_id)
|
||||||
|
SELECT
|
||||||
|
notification_profile_allowed_members._id,
|
||||||
|
notification_profile_allowed_members.notification_profile_id,
|
||||||
|
notification_profile_allowed_members.recipient_id
|
||||||
|
FROM notification_profile_allowed_members
|
||||||
|
INNER JOIN recipient ON notification_profile_allowed_members.recipient_id = recipient._id
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
db.execSQL("DROP TABLE notification_profile_allowed_members")
|
||||||
|
db.execSQL("ALTER TABLE notification_profile_allowed_members_tmp RENAME TO notification_profile_allowed_members")
|
||||||
|
|
||||||
|
db.execSQL("CREATE INDEX notification_profile_allowed_members_profile_index ON notification_profile_allowed_members (notification_profile_id)")
|
||||||
|
db.execSQL("CREATE INDEX notification_profile_allowed_members_recipient_index ON notification_profile_allowed_members (recipient_id)")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user