fixup migration

- nested transaction for enumeration
- save when complete
pull/1/head
Michael Kirk 7 years ago
parent fe7d69e9c6
commit 04a52980a3

@ -28,7 +28,7 @@ class OWS110SortIdMigration: OWSDatabaseMigration {
var archivedThreads: [TSThread] = [] var archivedThreads: [TSThread] = []
// get archived threads before migration // get archived threads before migration
TSThread.enumerateCollectionObjects({ (object, _) in TSThread.enumerateCollectionObjects(with: transaction) { (object, _) in
guard let thread = object as? TSThread else { guard let thread = object as? TSThread else {
owsFailDebug("unexpected object: \(type(of: object))") owsFailDebug("unexpected object: \(type(of: object))")
return return
@ -37,7 +37,7 @@ class OWS110SortIdMigration: OWSDatabaseMigration {
if thread.isArchivedByLegacyTimestampForSorting { if thread.isArchivedByLegacyTimestampForSorting {
archivedThreads.append(thread) archivedThreads.append(thread)
} }
}) }
guard let legacySorting: YapDatabaseAutoViewTransaction = transaction.extension(TSMessageDatabaseViewExtensionName_Legacy) as? YapDatabaseAutoViewTransaction else { guard let legacySorting: YapDatabaseAutoViewTransaction = transaction.extension(TSMessageDatabaseViewExtensionName_Legacy) as? YapDatabaseAutoViewTransaction else {
owsFailDebug("legacySorting was unexpectedly nil") owsFailDebug("legacySorting was unexpectedly nil")
@ -61,6 +61,8 @@ class OWS110SortIdMigration: OWSDatabaseMigration {
for archivedThread in archivedThreads { for archivedThread in archivedThreads {
archivedThread.archiveThread(with: transaction) archivedThread.archiveThread(with: transaction)
} }
self.save(with: transaction)
} }
completion() completion()

Loading…
Cancel
Save