From da5cf239bccaf0fef48854dadc8fab4b9bebf26e Mon Sep 17 00:00:00 2001 From: Bruno Muniz Azevedo Filho <bruno@elixxir.io> Date: Thu, 23 Jun 2022 17:48:28 -0300 Subject: [PATCH] Included migration --- .gitignore | 1 + Package.swift | 9 ++-- Sources/Integration/Session/Session.swift | 45 ++++++++++++++++--- .../xcshareddata/swiftpm/Package.resolved | 3 +- 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 839d127c..e051e6d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.build .DS_Store *.xcuserstate xcuserdata/ diff --git a/Package.swift b/Package.swift index fc9a709e..e57b0998 100644 --- a/Package.swift +++ b/Package.swift @@ -51,10 +51,6 @@ let package = Package( .library(name: "DependencyInjection", targets: ["DependencyInjection"]) ], dependencies: [ - .package( - url: "https://git.xx.network/elixxir/client-ios-db.git", - revision: "eb071f08000b2b7646e45e7a5f55bdc9ad6dbcfa" - ), .package(url: "https://github.com/Quick/Quick", from: "3.0.0"), .package(url: "https://github.com/Quick/Nimble", from: "9.0.0"), .package(url: "https://github.com/SnapKit/SnapKit", from: "5.0.1"), @@ -70,6 +66,7 @@ let package = Package( .package(url: "https://github.com/pointfreeco/combine-schedulers", from: "0.5.0"), .package(url: "https://github.com/kishikawakatsumi/KeychainAccess", from: "4.2.1"), .package(url: "https://github.com/google/google-api-objectivec-client-for-rest", from: "1.6.0"), + .package(url: "https://git.xx.network/elixxir/client-ios-db.git", .upToNextMajor(from: "1.0.1")), .package(url: "https://github.com/firebase/firebase-ios-sdk.git", .upToNextMajor(from: "8.10.0")), .package(url: "https://github.com/pointfreeco/swift-composable-architecture.git",.upToNextMajor(from: "0.32.0")) ], @@ -358,6 +355,10 @@ let package = Package( .product( name: "XXDatabase", package: "client-ios-db" + ), + .product( + name: "XXLegacyDatabaseMigrator", + package: "client-ios-db" ) ], resources: [.process("Resources")] diff --git a/Sources/Integration/Session/Session.swift b/Sources/Integration/Session/Session.swift index 7077acec..7de05d14 100644 --- a/Sources/Integration/Session/Session.swift +++ b/Sources/Integration/Session/Session.swift @@ -1,4 +1,5 @@ import Retry +import os.log import Models import Shared import Combine @@ -6,12 +7,11 @@ import Defaults import XXModels import XXDatabase import Foundation +import ToastFeature import BackupFeature import NetworkMonitor import DependencyInjection - -import os.log -import ToastFeature +import XXLegacyDatabaseMigrator let logHandler = OSLog(subsystem: "xx.network", category: "Performance debugging") @@ -89,7 +89,24 @@ public final class Session: SessionType { os_signpost(.end, log: logHandler, name: "Decrypting", "Finished newClientFromBackup") self.client = client - dbManager = try Database.inMemory() + + let oldPath = NSSearchPathForDirectoriesInDomains( + .documentDirectory, .userDomainMask, true + )[0].appending("/xxmessenger.sqlite") + + let newPath = FileManager.default + .containerURL(forSecurityApplicationGroupIdentifier: "group.elixxir.messenger")! + .appendingPathComponent("database") + .appendingPathExtension("sqlite").path + + try Migrator.live()( + try .init(path: oldPath), + to: try .onDisk(path: newPath), + myContactId: client.bindings.myId, + meMarshaled: client.bindings.meMarshalled + ) + + dbManager = try Database.onDisk(path: newPath) let report = try! JSONDecoder().decode(BackupReport.self, from: backupData!) @@ -111,7 +128,25 @@ public final class Session: SessionType { public init(ndf: String) throws { let network = try! DependencyInjection.Container.shared.resolve() as XXNetworking self.client = try network.newClient(ndf: ndf) - dbManager = try Database.inMemory() + + let oldPath = NSSearchPathForDirectoriesInDomains( + .documentDirectory, .userDomainMask, true + )[0].appending("/xxmessenger.sqlite") + + let newPath = FileManager.default + .containerURL(forSecurityApplicationGroupIdentifier: "group.elixxir.messenger")! + .appendingPathComponent("database") + .appendingPathExtension("sqlite").path + + try Migrator.live()( + try .init(path: oldPath), + to: try .onDisk(path: newPath), + myContactId: client.bindings.myId, + meMarshaled: client.bindings.meMarshalled + ) + + dbManager = try Database.onDisk(path: newPath) + try continueInitialization() } diff --git a/client-ios.xcworkspace/xcshareddata/swiftpm/Package.resolved b/client-ios.xcworkspace/xcshareddata/swiftpm/Package.resolved index 9fabe939..ac651bcc 100644 --- a/client-ios.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/client-ios.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -50,7 +50,8 @@ "kind" : "remoteSourceControl", "location" : "https://git.xx.network/elixxir/client-ios-db.git", "state" : { - "revision" : "eb071f08000b2b7646e45e7a5f55bdc9ad6dbcfa" + "revision" : "8674619071b9e2aa909b0626b0b37e64129c4841", + "version" : "1.0.1" } }, { -- GitLab