From 3b33a1d51d2f25ad3af2e7e65a14046df3521163 Mon Sep 17 00:00:00 2001 From: Anton Poltoratskyi Date: Thu, 18 Oct 2018 13:48:45 +0300 Subject: [PATCH] Added migration for Desc's parentId. --- Nynja/MigrationManager.swift | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Nynja/MigrationManager.swift b/Nynja/MigrationManager.swift index a89c87bd7..1fb754ad4 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 = """ -- GitLab