Skip to content

Commit

Permalink
Migrate from GRDB 5 to GRDB 6 (#378)
Browse files Browse the repository at this point in the history
Co-authored-by: Tobias Hagemann <[email protected]>
  • Loading branch information
iammajid and tobihagemann authored Sep 19, 2024
1 parent afba275 commit 1f951ba
Show file tree
Hide file tree
Showing 28 changed files with 66 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/openid/AppAuth-iOS.git",
"state" : {
"revision" : "71cde449f13d453227e687458144bde372d30fc7",
"version" : "1.6.2"
"revision" : "c89ed571ae140f8eb1142735e6e23d7bb8c34cb2",
"version" : "1.7.5"
}
},
{
Expand All @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/aws-amplify/aws-sdk-ios-spm.git",
"state" : {
"revision" : "8ff8bebfe24271f7b16c5abaeb78daf82bee3a80",
"version" : "2.34.2"
"revision" : "6e23b91609f9ddf988fda58bf711896a6062d4ff",
"version" : "2.35.0"
}
},
{
Expand Down Expand Up @@ -68,8 +68,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/cryptomator/cloud-access-swift.git",
"state" : {
"revision" : "2d8444001a4b2c2ccf396942fd78680eefa9dc52",
"version" : "1.11.3"
"revision" : "383c51e1a9b6dee3d7b0a1652270aa0aacd29917",
"version" : "1.12.0"
}
},
{
Expand All @@ -95,8 +95,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/leif-ibsen/Digest",
"state" : {
"revision" : "bb5de567a7b109a473ef5fddd3f02f1e5b9e2a41",
"version" : "1.7.0"
"revision" : "844a17be22efaa443130d081f2c4fa5f12c68e91",
"version" : "1.8.0"
}
},
{
Expand All @@ -122,26 +122,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/groue/GRDB.swift.git",
"state" : {
"revision" : "dd7e7f39e8e4d7a22d258d9809a882f914690b01",
"version" : "5.26.1"
"revision" : "2cf6c756e1e5ef6901ebae16576a7e4e4b834622",
"version" : "6.29.3"
}
},
{
"identity" : "gtm-session-fetcher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/gtm-session-fetcher.git",
"state" : {
"revision" : "d415594121c9e8a4f9d79cecee0965cf35e74dbd",
"version" : "3.1.1"
"revision" : "a2ab612cb980066ee56d90d60d8462992c07f24b",
"version" : "3.5.0"
}
},
{
"identity" : "gtmappauth",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GTMAppAuth.git",
"state" : {
"revision" : "41aba100f28395ebe842cd66e5d371cdd46c6792",
"version" : "4.0.0"
"revision" : "5d7d66f647400952b1758b230e019b07c0b4b22a",
"version" : "4.1.1"
}
},
{
Expand All @@ -158,8 +158,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/AzureAD/microsoft-authentication-library-for-objc.git",
"state" : {
"revision" : "d2f81ded070ac6452b2a6acb5bc45eb566427fe7",
"version" : "1.3.3"
"revision" : "b8733236bfd16e10849f4752a4d1c4621e4bf930",
"version" : "1.5.0"
}
},
{
Expand Down Expand Up @@ -221,8 +221,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/leif-ibsen/SwiftECC",
"state" : {
"revision" : "0efa7eed9eeedb93e6d42bc4a18a40ef5c1ef2d0",
"version" : "5.3.0"
"revision" : "05733024083e9ef1a57f436dc59fe00bdf42d2a2",
"version" : "5.4.0"
}
},
{
Expand Down
8 changes: 4 additions & 4 deletions Cryptomator/Common/CloudAccountList/AccountListPosition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ extension AccountListPosition: FetchableRecord, MutablePersistableRecord {
static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID]
static let account = belongsTo(CloudProviderAccount.self)

mutating func didInsert(with rowID: Int64, for column: String?) {
id = rowID
mutating func didInsert(_ inserted: InsertionSuccess) {
id = inserted.rowID
}

init(row: Row) {
init(row: Row) throws {
self.id = row[Column.rowID]
self.position = row[Columns.position]
self.accountUID = row[Columns.accountUID]
}

func encode(to container: inout PersistenceContainer) {
func encode(to container: inout PersistenceContainer) throws {
container[Column.rowID] = id
container[Columns.position] = position
container[Columns.accountUID] = accountUID
Expand Down
2 changes: 1 addition & 1 deletion Cryptomator/Common/DatabaseManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class DatabaseManager {
let observation = ValueObservation
.tracking { db in try Row.fetchAll(db, request) }
.removeDuplicates()
.map { rows in rows.map(AccountWithDisplayName.init(row:)) }
.map { rows in try rows.map(AccountWithDisplayName.init(row:)) }
.map { annotatedAccounts in annotatedAccounts.map(\.account) }
return observation.start(in: database, scheduling: .immediate, onError: onError, onChange: onChange)
}
Expand Down
8 changes: 4 additions & 4 deletions Cryptomator/VaultList/VaultListPosition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ struct VaultListPosition: Codable {
extension VaultListPosition: FetchableRecord, MutablePersistableRecord {
static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID]

mutating func didInsert(with rowID: Int64, for column: String?) {
id = rowID
mutating func didInsert(_ inserted: InsertionSuccess) {
id = inserted.rowID
}

init(row: Row) {
init(row: Row) throws {
self.id = row[Column.rowID]
self.position = row[Columns.position]
self.vaultUID = row[Columns.vaultUID]
}

func encode(to container: inout PersistenceContainer) {
func encode(to container: inout PersistenceContainer) throws {
container[Column.rowID] = id
container[Columns.position] = position
container[Columns.vaultUID] = vaultUID
Expand Down
2 changes: 1 addition & 1 deletion CryptomatorCommon/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/cryptomator/cloud-access-swift.git", .upToNextMinor(from: "1.11.0")),
.package(url: "https://github.com/cryptomator/cloud-access-swift.git", .upToNextMinor(from: "1.12.0")),
.package(url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git", .upToNextMinor(from: "3.8.0")),
.package(url: "https://github.com/PhilLibs/simple-swift-dependencies", .upToNextMajor(from: "0.1.0")),
.package(url: "https://github.com/siteline/SwiftUI-Introspect.git", .upToNextMajor(from: "0.3.0")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ private enum CryptomatorDatabaseKey: DependencyKey {
static let liveValue: DatabaseWriter = CryptomatorDatabase.live

static var testValue: DatabaseWriter {
let inMemoryDB = DatabaseQueue(configuration: .defaultCryptomatorConfiguration)
do {
let inMemoryDB = try DatabaseQueue(configuration: .defaultCryptomatorConfiguration)
try CryptomatorDatabase.migrator.migrate(inMemoryDB)
return inMemoryDB
} catch {
DDLogError("Failed to migrate in-memory database: \(error)")
DDLogError("Failed to initialize in-memory database: \(error)")
fatalError("Failed to initialize in-memory database")
}
return inMemoryDB
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private struct HubVaultRow: Codable, Equatable, PersistableRecord, FetchableReco
case vaultUID, subscriptionState
}

public func encode(to container: inout PersistenceContainer) {
public func encode(to container: inout PersistenceContainer) throws {
container[Columns.vaultUID] = vaultUID
container[Columns.subscriptionState] = subscriptionState
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct CloudProviderAccount: Decodable, FetchableRecord, TableRecord, Equ
}

extension CloudProviderAccount: PersistableRecord {
public func encode(to container: inout PersistenceContainer) {
public func encode(to container: inout PersistenceContainer) throws {
container[CloudProviderAccount.accountUIDKey] = accountUID
container[CloudProviderAccount.cloudProviderTypeKey] = cloudProviderType
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public struct VaultAccount: Decodable, FetchableRecord, TableRecord, Equatable {
}

extension VaultAccount: PersistableRecord {
public func encode(to container: inout PersistenceContainer) {
public func encode(to container: inout PersistenceContainer) throws {
container[VaultAccount.vaultUIDKey] = vaultUID
container[VaultAccount.delegateAccountUIDKey] = delegateAccountUID
container[VaultAccount.vaultPathKey] = vaultPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension CachedVault: FetchableRecord, TableRecord, PersistableRecord {
case vaultUID, masterkeyFileData, vaultConfigToken, lastUpToDateCheck, masterkeyFileLastModifiedDate, vaultConfigLastModifiedDate
}

public func encode(to container: inout PersistenceContainer) {
public func encode(to container: inout PersistenceContainer) throws {
container[Columns.vaultUID] = vaultUID
container[Columns.masterkeyFileData] = masterkeyFileData
container[Columns.vaultConfigToken] = vaultConfigToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Philipp Schmid on 29.06.22.
//

import CocoaLumberjackSwift
import CryptomatorCloudAccessCore
import Dependencies
import Foundation
Expand Down Expand Up @@ -80,9 +81,14 @@ extension S3CredentialManager {
var configuration = Configuration()
// Workaround for a SQLite regression (see https://github.com/groue/GRDB.swift/issues/1171 for more details)
configuration.acceptsDoubleQuotedStringLiterals = true
let inMemoryDB = DatabaseQueue(configuration: configuration)
try? CryptomatorDatabase.migrator.migrate(inMemoryDB)
return inMemoryDB
do {
let inMemoryDB = try DatabaseQueue(configuration: configuration)
try CryptomatorDatabase.migrator.migrate(inMemoryDB)
return inMemoryDB
} catch {
DDLogError("Failed to initialize in-memory database: \(error)")
fatalError("Failed to initialize in-memory database")
}
}

public static let demo = S3CredentialManager(keychain: CryptomatorKeychain(service: "s3CredentialDemo"))
Expand Down
2 changes: 1 addition & 1 deletion CryptomatorFileProvider/DB/DeletionTaskRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension DeletionTaskRecord {
}

extension DeletionTaskRecord: PersistableRecord {
func encode(to container: inout PersistenceContainer) {
func encode(to container: inout PersistenceContainer) throws {
container[Columns.correspondingItem] = correspondingItem
container[Columns.cloudPath] = cloudPath
container[Columns.parentID] = parentID
Expand Down
2 changes: 1 addition & 1 deletion CryptomatorFileProvider/DB/DownloadTaskRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct DownloadTaskRecord: Decodable, FetchableRecord, TableRecord {
}

extension DownloadTaskRecord: PersistableRecord {
func encode(to container: inout PersistenceContainer) {
func encode(to container: inout PersistenceContainer) throws {
container[Columns.correspondingItem] = correspondingItem
container[Columns.replaceExisting] = replaceExisting
container[Columns.localURL] = localURL
Expand Down
2 changes: 1 addition & 1 deletion CryptomatorFileProvider/DB/ItemEnumerationTaskRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct ItemEnumerationTaskRecord: Decodable, FetchableRecord, TableRecord {
}

extension ItemEnumerationTaskRecord: PersistableRecord {
func encode(to container: inout PersistenceContainer) {
func encode(to container: inout PersistenceContainer) throws {
container[Columns.correspondingItem] = correspondingItem
container[Columns.pageToken] = pageToken
}
Expand Down
10 changes: 5 additions & 5 deletions CryptomatorFileProvider/DB/ItemMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ItemMetadata: Record, Codable {
var favoriteRank: Int64?
var tagData: Data?

required init(row: Row) {
required init(row: Row) throws {
self.id = row[Columns.id]
self.name = row[Columns.name]
self.type = row[Columns.type]
Expand All @@ -45,7 +45,7 @@ public class ItemMetadata: Record, Codable {
self.isMaybeOutdated = row[Columns.isMaybeOutdated]
self.favoriteRank = row[Columns.favoriteRank]
self.tagData = row[Columns.tagData]
super.init(row: row)
try super.init(row: row)
}

convenience init(item: CloudItemMetadata, withParentID parentID: Int64, isPlaceholderItem: Bool = false) {
Expand All @@ -68,11 +68,11 @@ public class ItemMetadata: Record, Codable {
super.init()
}

override public func didInsert(with rowID: Int64, for column: String?) {
id = rowID
override public func didInsert(_ inserted: InsertionSuccess) {
id = inserted.rowID
}

override public func encode(to container: inout PersistenceContainer) {
override public func encode(to container: inout PersistenceContainer) throws {
container[Columns.id] = id
container[Columns.name] = name
container[Columns.type] = type
Expand Down
2 changes: 1 addition & 1 deletion CryptomatorFileProvider/DB/LocalCachedFileInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct LocalCachedFileInfo: Decodable, FetchableRecord, TableRecord {
}

extension LocalCachedFileInfo: PersistableRecord {
func encode(to container: inout PersistenceContainer) {
func encode(to container: inout PersistenceContainer) throws {
container[Columns.lastModifiedDate] = lastModifiedDate
container[Columns.correspondingItem] = correspondingItem
container[Columns.localLastModifiedDate] = localLastModifiedDate
Expand Down
2 changes: 1 addition & 1 deletion CryptomatorFileProvider/DB/MaintenanceDBManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private struct MaintenanceModeEntry: Decodable, FetchableRecord, TableRecord, Pe
case id, flag
}

func encode(to container: inout PersistenceContainer) {
func encode(to container: inout PersistenceContainer) throws {
container[Columns.id] = id
container[Columns.flag] = flag
}
Expand Down
2 changes: 1 addition & 1 deletion CryptomatorFileProvider/DB/ReparentTaskRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct ReparentTaskRecord: Decodable, FetchableRecord, TableRecord {
}

extension ReparentTaskRecord: PersistableRecord {
func encode(to container: inout PersistenceContainer) {
func encode(to container: inout PersistenceContainer) throws {
container[Columns.correspondingItem] = correspondingItem
container[Columns.sourceCloudPath] = sourceCloudPath
container[Columns.targetCloudPath] = targetCloudPath
Expand Down
2 changes: 1 addition & 1 deletion CryptomatorFileProvider/DB/UploadTaskRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct UploadTaskRecord: Decodable, FetchableRecord, TableRecord {
}

extension UploadTaskRecord: PersistableRecord {
func encode(to container: inout PersistenceContainer) {
func encode(to container: inout PersistenceContainer) throws {
container[Columns.correspondingItem] = correspondingItem
container[Columns.lastFailedUploadDate] = lastFailedUploadDate
container[Columns.uploadErrorCode] = uploadErrorCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CachedFileManagerTests: CacheTestCase {

override func setUpWithError() throws {
try super.setUpWithError()
inMemoryDB = DatabaseQueue()
inMemoryDB = try DatabaseQueue()
try DatabaseHelper.migrate(inMemoryDB)
manager = CachedFileDBManager(database: inMemoryDB, fileManagerHelper: .init(fileCoordinator: .init()))
metadataManager = ItemMetadataDBManager(database: inMemoryDB)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DeletionTaskManagerTests: XCTestCase {
var itemMetadataManager: ItemMetadataDBManager!

override func setUpWithError() throws {
let inMemoryDB = DatabaseQueue()
let inMemoryDB = try DatabaseQueue()
try DatabaseHelper.migrate(inMemoryDB)
manager = try DeletionTaskDBManager(database: inMemoryDB)
itemMetadataManager = ItemMetadataDBManager(database: inMemoryDB)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DownloadTaskManagerTests: XCTestCase {
var inMemoryDB: DatabaseQueue!

override func setUpWithError() throws {
inMemoryDB = DatabaseQueue()
inMemoryDB = try DatabaseQueue()
try DatabaseHelper.migrate(inMemoryDB)
manager = try DownloadTaskDBManager(database: inMemoryDB)
itemMetadataManager = ItemMetadataDBManager(database: inMemoryDB)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ItemEnumerationTaskManagerTests: XCTestCase {
var inMemoryDB: DatabaseQueue!

override func setUpWithError() throws {
inMemoryDB = DatabaseQueue()
inMemoryDB = try DatabaseQueue()
try DatabaseHelper.migrate(inMemoryDB)
manager = try ItemEnumerationTaskDBManager(database: inMemoryDB)
itemMetadataManager = ItemMetadataDBManager(database: inMemoryDB)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MaintenanceManagerTests: XCTestCase {
var inMemoryDB: DatabaseQueue!

override func setUpWithError() throws {
inMemoryDB = DatabaseQueue()
inMemoryDB = try DatabaseQueue()
try DatabaseHelper.migrate(inMemoryDB)
manager = MaintenanceDBManager(database: inMemoryDB)
itemMetadataManager = ItemMetadataDBManager(database: inMemoryDB)
Expand Down
2 changes: 1 addition & 1 deletion CryptomatorFileProviderTests/DB/MetadataManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MetadataManagerTests: XCTestCase {
var manager: ItemMetadataDBManager!

override func setUpWithError() throws {
let inMemoryDB = DatabaseQueue()
let inMemoryDB = try DatabaseQueue()
try DatabaseHelper.migrate(inMemoryDB)
manager = ItemMetadataDBManager(database: inMemoryDB)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ReparentTaskManagerTests: XCTestCase {
var inMemoryDB: DatabaseQueue!

override func setUpWithError() throws {
inMemoryDB = DatabaseQueue()
inMemoryDB = try DatabaseQueue()
try DatabaseHelper.migrate(inMemoryDB)
manager = try ReparentTaskDBManager(database: inMemoryDB)
itemMetadataManager = ItemMetadataDBManager(database: inMemoryDB)
Expand Down
Loading

0 comments on commit 1f951ba

Please sign in to comment.