diff --git a/.gitignore b/.gitignore index 839d127c8fff949c405a77d770e8f22feb8b2b6b..e051e6d6108fed6f8277dbaea33859447b20c2df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.build .DS_Store *.xcuserstate xcuserdata/ diff --git a/Package.swift b/Package.swift index fc9a709e58219843291d00eca937b38332df17aa..e57b0998d454cb19ffe5ce24cf35db0088fd4356 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 7077acec13cf6f3825cd5ff0d6de8d476e3d4e14..7de05d14f18b9784815f0a660582b36e2c4f9a8b 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 9fabe9397831e89b7ad25668f6ef18c626d25d82..ac651bcc41eec7a910637240b4f8f091c6578011 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" } }, {