diff --git a/Scripts/sds_codegen/sds_config/sds_record_type_map.json b/Scripts/sds_codegen/sds_config/sds_record_type_map.json index 287b074301..d9bead7f02 100644 --- a/Scripts/sds_codegen/sds_config/sds_record_type_map.json +++ b/Scripts/sds_codegen/sds_config/sds_record_type_map.json @@ -1,72 +1,27 @@ { "#comment": "NOTE: This file is generated by /Scripts/sds_codegen/sds_generate.py. Do not manually edit it, instead run `sds_codegen.sh`.", - "BaseModel": 56, - "ExperienceUpgrade": 55, - "IncomingGroupsV2MessageJob": 63, - "InstalledSticker": 24, - "OWS100RemoveTSRecipientsMigration": 40, - "OWS101ExistingUsersBlockOnIdentityChange": 43, - "OWS102MoveLoggingPreferenceToUserDefaults": 47, - "OWS103EnableVideoCalling": 42, - "OWS104CreateRecipientIdentities": 45, - "OWS105AttachmentFilePaths": 44, - "OWS107LegacySounds": 50, - "OWS108CallLoggingPreference": 48, - "OWS109OutgoingMessageState": 51, + "#max": 80, "OWSAddToContactsOfferMessage": 25, "OWSAddToProfileWhitelistOfferMessage": 7, - "OWSBackupFragment": 32, - "OWSContactOffersInteraction": 22, - "OWSContactQuery": 57, - "OWSDatabaseMigration": 46, - "OWSDevice": 33, "OWSDisappearingConfigurationUpdateInfoMessage": 28, - "OWSDisappearingMessagesConfiguration": 39, "OWSGroupCallMessage": 65, "OWSIncomingArchivedPaymentMessage": 78, - "OWSIncomingContactSyncJobRecord": 61, - "OWSIncomingGroupSyncJobRecord": 60, "OWSIncomingPaymentMessage": 75, - "OWSLinkedDeviceReadReceipt": 36, - "OWSLocalUserLeaveGroupJobRecord": 74, - "OWSMessageContentJob": 15, "OWSOutgoingArchivedPaymentMessage": 79, "OWSOutgoingPaymentMessage": 68, - "OWSPaymentActivationRequestFinishedMessage": 77, - "OWSPaymentActivationRequestMessage": 76, - "OWSReaction": 62, - "OWSReceiptCredentialRedemptionJobRecord": 71, - "OWSRecipientIdentity": 38, "OWSRecoverableDecryptionPlaceholder": 70, - "OWSResaveCollectionDBMigration": 49, - "OWSSendGiftBadgeJobRecord": 73, - "OWSSessionResetJobRecord": 52, "OWSUnknownContactBlockOfferMessage": 5, - "OWSUnknownDBObject": 37, "OWSUnknownProtocolVersionMessage": 54, - "OWSUserProfile": 41, "OWSVerificationStateChangeMessage": 13, - "SSKJobRecord": 34, - "SSKMessageDecryptJobRecord": 53, - "SSKMessageSenderJobRecord": 35, - "SignalAccount": 30, - "SignalRecipient": 31, - "StickerPack": 14, "TSCall": 20, "TSErrorMessage": 9, - "TSGroupMember": 69, "TSIncomingMessage": 19, "TSInfoMessage": 10, "TSInteraction": 16, "TSInvalidIdentityKeyErrorMessage": 17, "TSInvalidIdentityKeyReceivingErrorMessage": 1, "TSInvalidIdentityKeySendingErrorMessage": 23, - "TSMention": 64, "TSMessage": 11, "TSOutgoingMessage": 21, - "TSPaymentModel": 67, - "TSPaymentRequestModel": 66, - "TSRecipientReadReceipt": 12, - "TSUnreadIndicatorInteraction": 4, - "TestModel": 59 + "TSUnreadIndicatorInteraction": 4 } \ No newline at end of file diff --git a/Scripts/sds_codegen/sds_generate.py b/Scripts/sds_codegen/sds_generate.py index 72fc633b26..4746d8c925 100755 --- a/Scripts/sds_codegen/sds_generate.py +++ b/Scripts/sds_codegen/sds_generate.py @@ -2440,31 +2440,23 @@ record_type_map = {} # It's critical that our "record type" values are consistent, even if we add/remove/rename model classes. # Therefore we persist the mapping of known classes in a JSON file that is under source control. def update_record_type_map(record_type_swift_path, record_type_json_path): - record_type_map_filepath = record_type_json_path + old_record_types = {} + if os.path.exists(record_type_json_path): + with open(record_type_json_path, "r") as f: + old_record_types = json.load(f) - if os.path.exists(record_type_map_filepath): - with open(record_type_map_filepath, "rt") as f: - json_string = f.read() - json_data = json.loads(json_string) - record_type_map.update(json_data) - - max_record_type = 0 - for class_name in record_type_map: - if class_name.startswith("#"): - continue - record_type = record_type_map[class_name] - max_record_type = max(max_record_type, record_type) + max_record_type = old_record_types.get("#max", 0) for clazz in global_class_map.values(): - if clazz.name not in record_type_map: - - if not clazz.should_generate_extensions(): - continue - - max_record_type = int(max_record_type) + 1 - record_type = max_record_type - record_type_map[clazz.name] = record_type + if not clazz.should_generate_extensions(): + continue + if clazz.name in old_record_types: + record_type_map[clazz.name] = old_record_types[clazz.name] + else: + max_record_type += 1 + record_type_map[clazz.name] = max_record_type + record_type_map["#max"] = max_record_type record_type_map["#comment"] = ( "NOTE: This file is generated by %s. Do not manually edit it, instead run `sds_codegen.sh`." % (sds_common.pretty_module_path(__file__),) @@ -2472,7 +2464,7 @@ def update_record_type_map(record_type_swift_path, record_type_json_path): json_string = json.dumps(record_type_map, sort_keys=True, indent=4) - sds_common.write_text_file_if_changed(record_type_map_filepath, json_string) + sds_common.write_text_file_if_changed(record_type_json_path, json_string) # TODO: We'll need to import SignalServiceKit for non-SSK classes. diff --git a/SignalServiceKit/Axolotl/OWSRecipientIdentity.swift b/SignalServiceKit/Axolotl/OWSRecipientIdentity.swift index c06efd67c0..059cc15f21 100644 --- a/SignalServiceKit/Axolotl/OWSRecipientIdentity.swift +++ b/SignalServiceKit/Axolotl/OWSRecipientIdentity.swift @@ -55,7 +55,7 @@ public enum VerificationState: Equatable { /// Record for a recipient's identity key and associated fields used to make trust decisions. public final class OWSRecipientIdentity: NSObject, SDSCodableModel, Decodable { public static let databaseTableName = "model_OWSRecipientIdentity" - private static var recordType: SDSRecordType { .recipientIdentity } + private static let recordType: UInt = 38 public var id: Int64? public let uniqueId: String @@ -94,7 +94,7 @@ public final class OWSRecipientIdentity: NSObject, SDSCodableModel, Decodable { let container = try decoder.container(keyedBy: CodingKeys.self) let decodedRecordType = try container.decode(Int64.self, forKey: .recordType) - guard decodedRecordType == Self.recordType.rawValue else { + guard decodedRecordType == Self.recordType else { owsFailDebug("Unexpected record type: \(decodedRecordType)") throw SDSError.invalidValue() } @@ -110,7 +110,7 @@ public final class OWSRecipientIdentity: NSObject, SDSCodableModel, Decodable { public func encode(to encoder: any Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(self.id, forKey: .id) - try container.encode(Self.recordType.rawValue, forKey: .recordType) + try container.encode(Self.recordType, forKey: .recordType) try container.encode(self.uniqueId, forKey: .uniqueId) try container.encode(self.uniqueId, forKey: .accountId) try container.encode(self.identityKey, forKey: .identityKey) diff --git a/SignalServiceKit/Contacts/DisappearingMessagesConfigurationRecord.swift b/SignalServiceKit/Contacts/DisappearingMessagesConfigurationRecord.swift index b7245b1eff..8642d2146f 100644 --- a/SignalServiceKit/Contacts/DisappearingMessagesConfigurationRecord.swift +++ b/SignalServiceKit/Contacts/DisappearingMessagesConfigurationRecord.swift @@ -105,7 +105,7 @@ public struct DisappearingMessagesConfigurationRecord: FetchableRecord, MutableP public func encode(to encoder: any Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(self.id, forKey: .id) - try container.encode(SDSRecordType.disappearingMessagesConfiguration.rawValue, forKey: .recordType) + try container.encode(39, forKey: .recordType) try container.encode(self.threadUniqueId, forKey: .threadUniqueId) try container.encode(self.durationSeconds, forKey: .durationSeconds) try container.encode(self.isEnabled, forKey: .isEnabled) diff --git a/SignalServiceKit/Contacts/SignalAccount.swift b/SignalServiceKit/Contacts/SignalAccount.swift index e04afc70d0..d81c83f12c 100644 --- a/SignalServiceKit/Contacts/SignalAccount.swift +++ b/SignalServiceKit/Contacts/SignalAccount.swift @@ -9,7 +9,7 @@ public import LibSignalClient @objc(SignalAccount) public final class SignalAccount: NSObject, SDSCodableModel, Decodable { public static let databaseTableName = "model_SignalAccount" - private static var recordType: SDSRecordType { .signalAccount } + private static let recordType: UInt = 30 public enum CodingKeys: String, CodingKey, ColumnExpression { case id @@ -105,7 +105,7 @@ public final class SignalAccount: NSObject, SDSCodableModel, Decodable { let container = try decoder.container(keyedBy: CodingKeys.self) let decodedRecordType = try container.decode(Int64.self, forKey: .recordType) - owsAssertDebug(decodedRecordType == Self.recordType.rawValue, "Unexpectedly decoded record with wrong type!") + owsAssertDebug(decodedRecordType == Self.recordType, "Unexpectedly decoded record with wrong type!") id = try container.decodeIfPresent(RowId.self, forKey: .id) uniqueId = try container.decode(String.self, forKey: .uniqueId) @@ -140,7 +140,7 @@ public final class SignalAccount: NSObject, SDSCodableModel, Decodable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(Self.recordType.rawValue, forKey: .recordType) + try container.encode(Self.recordType, forKey: .recordType) try id.map { try container.encode($0, forKey: .id) } try container.encode(uniqueId, forKey: .uniqueId) diff --git a/SignalServiceKit/Contacts/SignalRecipient/SignalRecipient.swift b/SignalServiceKit/Contacts/SignalRecipient/SignalRecipient.swift index 8b7f24319d..0e4c364f19 100644 --- a/SignalServiceKit/Contacts/SignalRecipient/SignalRecipient.swift +++ b/SignalServiceKit/Contacts/SignalRecipient/SignalRecipient.swift @@ -19,6 +19,7 @@ public import LibSignalClient /// doesn't have any devices, then that user isn't registered. public struct SignalRecipient: FetchableRecord, PersistableRecord, Codable { public static let databaseTableName = "model_SignalRecipient" + private static let recordType: UInt = 31 public enum Constants { public static let distantPastUnregisteredTimestamp: UInt64 = 1 @@ -109,7 +110,7 @@ public struct SignalRecipient: FetchableRecord, PersistableRecord, Codable { ) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING * """, arguments: [ - SDSRecordType.signalRecipient.rawValue, + Self.recordType, UUID().uuidString, aci?.serviceIdUppercaseString, phoneNumber?.stringValue, @@ -141,7 +142,7 @@ public struct SignalRecipient: FetchableRecord, PersistableRecord, Codable { let container = try decoder.container(keyedBy: CodingKeys.self) let decodedRecordType = try container.decode(UInt.self, forKey: .recordType) - guard decodedRecordType == SDSRecordType.signalRecipient.rawValue else { + guard decodedRecordType == Self.recordType else { owsFailDebug("Unexpected record type: \(decodedRecordType)") throw SDSError.invalidValue() } @@ -167,7 +168,7 @@ public struct SignalRecipient: FetchableRecord, PersistableRecord, Codable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) - try container.encode(SDSRecordType.signalRecipient.rawValue, forKey: .recordType) + try container.encode(Self.recordType, forKey: .recordType) try container.encode(uniqueId, forKey: .uniqueId) try container.encodeIfPresent(aciString, forKey: .aciString) try container.encodeIfPresent(pni?.serviceIdUppercaseString, forKey: .pni) diff --git a/SignalServiceKit/Groups/TSGroupMember.swift b/SignalServiceKit/Groups/TSGroupMember.swift index acefb36615..5762ae08c9 100644 --- a/SignalServiceKit/Groups/TSGroupMember.swift +++ b/SignalServiceKit/Groups/TSGroupMember.swift @@ -29,7 +29,7 @@ public import LibSignalClient /// ACI). Take care if this model is ever extended to include invited members. public final class TSGroupMember: NSObject, SDSCodableModel, Decodable { public static let databaseTableName = "model_TSGroupMember" - private static var recordType: SDSRecordType { .groupMember } + private static let recordType: UInt = 69 public enum CodingKeys: String, CodingKey, ColumnExpression { case id @@ -66,7 +66,7 @@ public final class TSGroupMember: NSObject, SDSCodableModel, Decodable { let container = try decoder.container(keyedBy: CodingKeys.self) let decodedRecordType = try container.decode(Int64.self, forKey: .recordType) - owsAssertDebug(decodedRecordType == Self.recordType.rawValue, "Unexpectedly decoded record with wrong type.") + owsAssertDebug(decodedRecordType == Self.recordType, "Unexpectedly decoded record with wrong type.") id = try container.decodeIfPresent(RowId.self, forKey: .id) uniqueId = try container.decode(String.self, forKey: .uniqueId) @@ -80,7 +80,7 @@ public final class TSGroupMember: NSObject, SDSCodableModel, Decodable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(id, forKey: .id) - try container.encode(Self.recordType.rawValue, forKey: .recordType) + try container.encode(Self.recordType, forKey: .recordType) try container.encode(uniqueId, forKey: .uniqueId) try container.encode(groupThreadId, forKey: .groupThreadId) try container.encodeIfPresent(serviceId?.serviceIdUppercaseString, forKey: .serviceId) diff --git a/SignalServiceKit/Jobs/DonationReceiptCredentialRedemptionJobQueue.swift b/SignalServiceKit/Jobs/DonationReceiptCredentialRedemptionJobQueue.swift index 6c2e088e10..f332573366 100644 --- a/SignalServiceKit/Jobs/DonationReceiptCredentialRedemptionJobQueue.swift +++ b/SignalServiceKit/Jobs/DonationReceiptCredentialRedemptionJobQueue.swift @@ -208,7 +208,7 @@ struct DonationReceiptCredentialRedemptionJobFinder { ) """ let arguments: StatementArguments = [ - SDSRecordType.receiptCredentialRedemptionJobRecord.rawValue, + JobRecord.JobRecordType.donationReceiptCredentialRedemption.rawValue, subscriberID, ] diff --git a/SignalServiceKit/Jobs/SendGiftBadgeJobQueue.swift b/SignalServiceKit/Jobs/SendGiftBadgeJobQueue.swift index 7e22ad2613..fd5e640d71 100644 --- a/SignalServiceKit/Jobs/SendGiftBadgeJobQueue.swift +++ b/SignalServiceKit/Jobs/SendGiftBadgeJobQueue.swift @@ -109,7 +109,7 @@ private func jobExists(threadId: String, transaction: DBReadTransaction) -> Bool """ let arguments: StatementArguments = [ threadId, - SDSRecordType.sendGiftBadgeJobRecord.rawValue, + JobRecord.JobRecordType.sendGiftBadge.rawValue, SendGiftBadgeJobRecord.Status.permanentlyFailed.rawValue, SendGiftBadgeJobRecord.Status.obsolete.rawValue, ] diff --git a/SignalServiceKit/Megaphones/ExperienceUpgrade.swift b/SignalServiceKit/Megaphones/ExperienceUpgrade.swift index c07c80529e..d24678e26d 100644 --- a/SignalServiceKit/Megaphones/ExperienceUpgrade.swift +++ b/SignalServiceKit/Megaphones/ExperienceUpgrade.swift @@ -10,7 +10,7 @@ public class ExperienceUpgrade: Codable, FetchableRecord, PersistableRecord { public typealias IDType = Int64 public static let databaseTableName = "model_ExperienceUpgrade" - private static var recordType: SDSRecordType { .experienceUpgrade } + private static let recordType: UInt = 55 public enum CodingKeys: String, CodingKey, ColumnExpression { case id @@ -79,7 +79,7 @@ public class ExperienceUpgrade: Codable, FetchableRecord, PersistableRecord { let container = try decoder.container(keyedBy: CodingKeys.self) let decodedRecordType = try container.decode(Int64.self, forKey: .recordType) - owsAssertDebug(decodedRecordType == Self.recordType.rawValue, "Unexpectedly decoded record with wrong type.") + owsAssertDebug(decodedRecordType == Self.recordType, "Unexpectedly decoded record with wrong type.") id = try container.decodeIfPresent(IDType.self, forKey: .id) @@ -105,7 +105,7 @@ public class ExperienceUpgrade: Codable, FetchableRecord, PersistableRecord { var container = encoder.container(keyedBy: CodingKeys.self) try id.map { try container.encode($0, forKey: .id) } - try container.encode(Self.recordType.rawValue, forKey: .recordType) + try container.encode(Self.recordType, forKey: .recordType) try container.encode(uniqueId, forKey: .uniqueId) try container.encode(firstViewedTimestamp, forKey: .firstViewedTimestamp) diff --git a/SignalServiceKit/Messages/GroupMessageProcessorJob.swift b/SignalServiceKit/Messages/GroupMessageProcessorJob.swift index 58886411dc..ee87a33273 100644 --- a/SignalServiceKit/Messages/GroupMessageProcessorJob.swift +++ b/SignalServiceKit/Messages/GroupMessageProcessorJob.swift @@ -8,6 +8,7 @@ import GRDB struct GroupMessageProcessorJob: Codable, PersistableRecord, FetchableRecord { static let databaseTableName: String = "model_IncomingGroupsV2MessageJob" + private static let recordType: UInt = 63 let id: Int64 let groupId: Data? @@ -88,7 +89,7 @@ struct GroupMessageProcessorJob: Codable, PersistableRecord, FetchableRecord { wasReceivedByUD, Int64(bitPattern: serverDeliveryTimestamp), Date().timeIntervalSince1970, - SDSRecordType.incomingGroupsV2MessageJob.rawValue, + Self.recordType, UUID().uuidString, ], )! diff --git a/SignalServiceKit/Messages/Interactions/TSMention.swift b/SignalServiceKit/Messages/Interactions/TSMention.swift index 1b89c5d717..5cd303b585 100644 --- a/SignalServiceKit/Messages/Interactions/TSMention.swift +++ b/SignalServiceKit/Messages/Interactions/TSMention.swift @@ -10,7 +10,7 @@ public import LibSignalClient @objc public final class TSMention: NSObject, SDSCodableModel, Decodable { public static let databaseTableName = "model_TSMention" - private static var recordType: SDSRecordType { .mention } + private static let recordType: UInt = 64 public enum CodingKeys: String, CodingKey, ColumnExpression { case id @@ -47,7 +47,7 @@ public final class TSMention: NSObject, SDSCodableModel, Decodable { let container = try decoder.container(keyedBy: CodingKeys.self) let decodedRecordType = try container.decode(Int64.self, forKey: .recordType) - owsAssertDebug(decodedRecordType == Self.recordType.rawValue, "Unexpectedly decoded record with wrong type.") + owsAssertDebug(decodedRecordType == Self.recordType, "Unexpectedly decoded record with wrong type.") id = try container.decodeIfPresent(RowId.self, forKey: .id) uniqueId = try container.decode(String.self, forKey: .uniqueId) @@ -62,7 +62,7 @@ public final class TSMention: NSObject, SDSCodableModel, Decodable { var container = encoder.container(keyedBy: CodingKeys.self) try id.map { try container.encode($0, forKey: .id) } - try container.encode(Self.recordType.rawValue, forKey: .recordType) + try container.encode(Self.recordType, forKey: .recordType) try container.encode(uniqueId, forKey: .uniqueId) try container.encode(uniqueMessageId, forKey: .uniqueMessageId) diff --git a/SignalServiceKit/Messages/Reactions/OWSReaction.swift b/SignalServiceKit/Messages/Reactions/OWSReaction.swift index acd7ad88bf..015165a184 100644 --- a/SignalServiceKit/Messages/Reactions/OWSReaction.swift +++ b/SignalServiceKit/Messages/Reactions/OWSReaction.swift @@ -10,7 +10,7 @@ public import LibSignalClient @objc(OWSReaction) // Named explicitly to preserve NSKeyedUnarchiving compatability public final class OWSReaction: NSObject, SDSCodableModel, Decodable, NSSecureCoding { public static let databaseTableName = "model_OWSReaction" - private static var recordType: SDSRecordType { .reaction } + private static let recordType: UInt = 62 public enum CodingKeys: String, CodingKey, ColumnExpression { case id @@ -86,7 +86,7 @@ public final class OWSReaction: NSObject, SDSCodableModel, Decodable, NSSecureCo let container = try decoder.container(keyedBy: CodingKeys.self) let decodedRecordType = try container.decode(Int64.self, forKey: .recordType) - owsAssertDebug(decodedRecordType == Self.recordType.rawValue, "Unexpectedly decoded record with wrong type.") + owsAssertDebug(decodedRecordType == Self.recordType, "Unexpectedly decoded record with wrong type.") id = try container.decodeIfPresent(RowId.self, forKey: .id) uniqueId = try container.decode(String.self, forKey: .uniqueId) @@ -107,7 +107,7 @@ public final class OWSReaction: NSObject, SDSCodableModel, Decodable, NSSecureCo var container = encoder.container(keyedBy: CodingKeys.self) try id.map { try container.encode($0, forKey: .id) } - try container.encode(Self.recordType.rawValue, forKey: .recordType) + try container.encode(Self.recordType, forKey: .recordType) try container.encode(uniqueId, forKey: .uniqueId) try container.encode(uniqueMessageId, forKey: .uniqueMessageId) diff --git a/SignalServiceKit/Messages/Stickers/InstalledStickerRecord.swift b/SignalServiceKit/Messages/Stickers/InstalledStickerRecord.swift index 11fccbb8a6..fa0f818b3c 100644 --- a/SignalServiceKit/Messages/Stickers/InstalledStickerRecord.swift +++ b/SignalServiceKit/Messages/Stickers/InstalledStickerRecord.swift @@ -8,7 +8,7 @@ public import GRDB public final class InstalledStickerRecord: SDSCodableModel, Decodable { public static let databaseTableName: String = "model_InstalledSticker" - private static let recordType: SDSRecordType = .installedSticker + private static let recordType: UInt = 24 public var id: Int64? public let uniqueId: String @@ -39,7 +39,7 @@ public final class InstalledStickerRecord: SDSCodableModel, Decodable { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(self.id, forKey: .id) try container.encode(self.uniqueId, forKey: .uniqueId) - try container.encode(Self.recordType.rawValue, forKey: .recordType) + try container.encode(Self.recordType, forKey: .recordType) try container.encode(LegacySDSSerializer().serializeAsLegacySDSData(self.info), forKey: .info) try container.encodeIfPresent(self.emojiString, forKey: .emojiString) try container.encodeIfPresent(self.contentType, forKey: .contentType) diff --git a/SignalServiceKit/Messages/Stickers/StickerPackRecord.swift b/SignalServiceKit/Messages/Stickers/StickerPackRecord.swift index c2139c2ddb..e3db88bc25 100644 --- a/SignalServiceKit/Messages/Stickers/StickerPackRecord.swift +++ b/SignalServiceKit/Messages/Stickers/StickerPackRecord.swift @@ -8,7 +8,7 @@ public import GRDB public final class StickerPackRecord: SDSCodableModel, Decodable, Equatable, NSCopying { public static let databaseTableName: String = "model_StickerPack" - private static let recordType: SDSRecordType = .stickerPack + private static let recordType: UInt = 14 public var id: Int64? public let uniqueId: String @@ -53,7 +53,7 @@ public final class StickerPackRecord: SDSCodableModel, Decodable, Equatable, NSC var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(self.id, forKey: .id) try container.encode(self.uniqueId, forKey: .uniqueId) - try container.encode(Self.recordType.rawValue, forKey: .recordType) + try container.encode(Self.recordType, forKey: .recordType) try container.encode(LegacySDSSerializer().serializeAsLegacySDSData(self.info), forKey: .info) try container.encodeIfPresent(self.title, forKey: .title) try container.encodeIfPresent(self.author, forKey: .author) diff --git a/SignalServiceKit/Payments/TSPaymentModel.swift b/SignalServiceKit/Payments/TSPaymentModel.swift index 3f1a0462c9..ee607b4b3b 100644 --- a/SignalServiceKit/Payments/TSPaymentModel.swift +++ b/SignalServiceKit/Payments/TSPaymentModel.swift @@ -15,7 +15,7 @@ public import LibSignalClient // all payments. public final class TSPaymentModel: NSObject, SDSCodableModel, Decodable { public static let databaseTableName: String = "model_TSPaymentModel" - private static let recordType: SDSRecordType = .paymentModel + private static let recordType: UInt = 67 public var id: Int64? public let uniqueId: String @@ -119,7 +119,7 @@ public final class TSPaymentModel: NSObject, SDSCodableModel, Decodable { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(self.id, forKey: .id) try container.encode(self.uniqueId, forKey: .uniqueId) - try container.encode(Self.recordType.rawValue, forKey: .recordType) + try container.encode(Self.recordType, forKey: .recordType) try container.encode(self.paymentType, forKey: .paymentType) try container.encode(self.paymentState, forKey: .paymentState) try container.encode(self.paymentFailure, forKey: .paymentFailure) diff --git a/SignalServiceKit/Profiles/OWSUserProfile.swift b/SignalServiceKit/Profiles/OWSUserProfile.swift index c681ed7dd0..d184c77f91 100644 --- a/SignalServiceKit/Profiles/OWSUserProfile.swift +++ b/SignalServiceKit/Profiles/OWSUserProfile.swift @@ -139,7 +139,7 @@ public final class UserProfileNotifications: NSObject { @objc public final class OWSUserProfile: NSObject, SDSCodableModel, Decodable { public static let databaseTableName = "model_OWSUserProfile" - private static var recordType: SDSRecordType { .userProfile } + private static let recordType: UInt = 41 /// An address used to identify an ``OWSUserProfile``. public enum Address: Hashable { @@ -393,7 +393,7 @@ public final class OWSUserProfile: NSObject, SDSCodableModel, Decodable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(id, forKey: .id) - try container.encode(Self.recordType.rawValue, forKey: .recordType) + try container.encode(Self.recordType, forKey: .recordType) try container.encode(uniqueId, forKey: .uniqueId) try container.encodeIfPresent(serviceIdString, forKey: .serviceIdString) try container.encodeIfPresent(phoneNumber, forKey: .phoneNumber) @@ -417,7 +417,7 @@ public final class OWSUserProfile: NSObject, SDSCodableModel, Decodable { let container = try decoder.container(keyedBy: CodingKeys.self) let decodedRecordType = try container.decode(Int64.self, forKey: .recordType) - guard decodedRecordType == Self.recordType.rawValue else { + guard decodedRecordType == Self.recordType else { owsFailDebug("Unexpected record type: \(decodedRecordType)") throw SDSError.invalidValue() } diff --git a/SignalServiceKit/Storage/Database/GRDBSchemaMigrator.swift b/SignalServiceKit/Storage/Database/GRDBSchemaMigrator.swift index 43ca64412e..99cbaa1845 100644 --- a/SignalServiceKit/Storage/Database/GRDBSchemaMigrator.swift +++ b/SignalServiceKit/Storage/Database/GRDBSchemaMigrator.swift @@ -1757,7 +1757,7 @@ public class GRDBSchemaMigrator { try transaction.database.execute(sql: "UPDATE model_TSInteraction SET serverDeliveryTimestamp = 0 WHERE recordType IS \(SDSRecordType.incomingMessage.rawValue)") // Backfill all jobs with "0" as their timestamp - try transaction.database.execute(sql: "UPDATE model_SSKJobRecord SET serverDeliveryTimestamp = 0 WHERE recordType IS \(SDSRecordType.messageDecryptJobRecord.rawValue)") + try transaction.database.execute(sql: "UPDATE model_SSKJobRecord SET serverDeliveryTimestamp = 0 WHERE recordType IS 53") return .success(()) } diff --git a/SignalServiceKit/Storage/Database/SDSRecordType.swift b/SignalServiceKit/Storage/Database/SDSRecordType.swift index d8c5453121..fb4056b0e1 100644 --- a/SignalServiceKit/Storage/Database/SDSRecordType.swift +++ b/SignalServiceKit/Storage/Database/SDSRecordType.swift @@ -18,66 +18,20 @@ public enum SDSRecordType: UInt, CaseIterable { case errorMessage = 9 case infoMessage = 10 case message = 11 - case recipientReadReceipt = 12 case verificationStateChangeMessage = 13 - case stickerPack = 14 - case messageContentJob = 15 case interaction = 16 case invalidIdentityKeyErrorMessage = 17 case incomingMessage = 19 case call = 20 case outgoingMessage = 21 - case contactOffersInteraction = 22 case invalidIdentityKeySendingErrorMessage = 23 - case installedSticker = 24 case addToContactsOfferMessage = 25 case disappearingConfigurationUpdateInfoMessage = 28 - case signalAccount = 30 - case signalRecipient = 31 - case backupFragment = 32 - case device = 33 - case jobRecord = 34 - case messageSenderJobRecord = 35 - case linkedDeviceReadReceipt = 36 - case unknownDBObject = 37 - case recipientIdentity = 38 - case disappearingMessagesConfiguration = 39 - case _100RemoveTSRecipientsMigration = 40 - case userProfile = 41 - case _103EnableVideoCalling = 42 - case _101ExistingUsersBlockOnIdentityChange = 43 - case _105AttachmentFilePaths = 44 - case _104CreateRecipientIdentities = 45 - case databaseMigration = 46 - case _102MoveLoggingPreferenceToUserDefaults = 47 - case _108CallLoggingPreference = 48 - case resaveCollectionDBMigration = 49 - case _107LegacySounds = 50 - case _109OutgoingMessageState = 51 - case sessionResetJobRecord = 52 - case messageDecryptJobRecord = 53 case unknownProtocolVersionMessage = 54 - case experienceUpgrade = 55 - case baseModel = 56 - case contactQuery = 57 - case testModel = 59 - case incomingGroupSyncJobRecord = 60 - case incomingContactSyncJobRecord = 61 - case reaction = 62 - case incomingGroupsV2MessageJob = 63 - case mention = 64 case groupCallMessage = 65 - case paymentRequestModel = 66 - case paymentModel = 67 case outgoingPaymentMessage = 68 - case groupMember = 69 case recoverableDecryptionPlaceholder = 70 - case receiptCredentialRedemptionJobRecord = 71 - case sendGiftBadgeJobRecord = 73 - case localUserLeaveGroupJobRecord = 74 case incomingPaymentMessage = 75 - case paymentActivationRequestMessage = 76 - case paymentActivationRequestFinishedMessage = 77 case incomingArchivedPaymentMessage = 78 case outgoingArchivedPaymentMessage = 79 }