From ba33d2c95eaaa0a56ce36fd3500fabde3eaaeb99 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Wed, 30 Nov 2022 08:49:53 +1100 Subject: [PATCH] Added the logic to create the UserProfile data dump in the migration --- .../Migrations/_011_SharedUtilChanges.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/SessionMessagingKit/Database/Migrations/_011_SharedUtilChanges.swift b/SessionMessagingKit/Database/Migrations/_011_SharedUtilChanges.swift index 8206068f5..605dfe8d1 100644 --- a/SessionMessagingKit/Database/Migrations/_011_SharedUtilChanges.swift +++ b/SessionMessagingKit/Database/Migrations/_011_SharedUtilChanges.swift @@ -2,6 +2,7 @@ import Foundation import GRDB +import SessionUtil import SessionUtilitiesKit /// This migration recreates the interaction FTS table and adds the threadId so we can do a performant in-conversation @@ -9,7 +10,7 @@ import SessionUtilitiesKit enum _011_SharedUtilChanges: Migration { static let target: TargetMigrations.Identifier = .messagingKit static let identifier: String = "SharedUtilChanges" - static let needsConfigSync: Bool = false + static let needsConfigSync: Bool = true static let minExpectedRunDuration: TimeInterval = 0.1 static func migrate(_ db: Database) throws { @@ -21,7 +22,18 @@ enum _011_SharedUtilChanges: Migration { .notNull() } - // TODO: Create dumps for current data + // Create a dump for the user profile data + let userProfileConf: UnsafeMutablePointer? = try SessionUtil.loadState( + for: .userProfile + ) + let confResult: SessionUtil.ConfResult = try SessionUtil.update( + conf: userProfileConf, + with: Profile.fetchOrCreateCurrentUser(db) + ) + + if confResult.needsDump { + try SessionUtil.saveState(db, conf: userProfileConf, for: .userProfile) + } Storage.update(progress: 1, for: self, in: target) // In case this is the last migration }