diff --git a/Nynja/MigrationManager.swift b/Nynja/MigrationManager.swift index a89c87bd76184c4c73a98a35427abdd4a5ae0f12..1fb754ad469eed46798a1314db8b92d3edb21f93 100644 --- a/Nynja/MigrationManager.swift +++ b/Nynja/MigrationManager.swift @@ -10,6 +10,7 @@ import GRDBCipher enum Migration: Int, Describable { case addSeenByColumnToMessage = 0 + case setupParentIdForThumbnails case updateDBFeatureTargetTypes static var allTitles: [String] = { @@ -61,6 +62,26 @@ final class MigrationManager { } } + migrator.registerMigration(.setupParentIdForThumbnails) { db in + let cursor = try DBMessage.fetchCursor(db) + + while let message = try cursor.next() { + try message.construct(db) + + let thumb = SendMessageType.thumbnails.rawValue + guard let thumbnailFile = message.files.first(where: { $0.mime == thumb }) else { + continue + } + let message = Message(message: message) + guard let mainFile = message.mainFile, mainFile.type == .image || mainFile.type == .video else { + continue + } + thumbnailFile.parendId = mainFile.id + + try thumbnailFile.save(db) + } + } + migrator.registerMigration(.updateDBFeatureTargetTypes) { db in let targetType = Column(FeatureTable.Column.targetType.title) let sql = """