Skip to content

Commit b189820

Browse files
SyncEngine primary key migration tool (#226)
* Automatic tool for migrating primary keys. * more todos * move stuff to library * wip * wip * wip * wip * wip * wip * wip * wip * wip * more tests * handle non-int primary key * more tests * wip * index/trigger test * tests * wip * md5 hash the id and table name for backfilling ids. * handle row ids * clean up * wip * foreign key checks and docs. * fix merge conflict * tests * fixes * merge fix * docs * wip * Fix comment formatting in migratePrimaryKeys function --------- Co-authored-by: Brandon Williams <[email protected]>
1 parent d4d630e commit b189820

19 files changed

+2606
-910
lines changed

Package.resolved

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ library, [subscribe today](https://www.pointfree.co/pricing).
3535
## Overview
3636

3737
SQLiteData is a [fast](#performance), lightweight replacement for SwiftData, including CloudKit
38-
synchronization (and even CloudKit sharing), built on top of the popular [GRDB] library.
38+
synchronization (and even CloudKit sharing), built on top of the popular [GRDB] library.
3939
To populate data from the database you can use `@Table` and `@FetchAll`, which are
4040
similar to SwiftData's `@Model` and `@Query`:
4141

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
import Dependencies
2-
import Foundation
1+
#if canImport(CloudKit)
2+
import Dependencies
3+
import Foundation
34

4-
package struct CurrentTimeGenerator: DependencyKey, Sendable {
5-
private var generate: @Sendable () -> Int64
6-
package var now: Int64 {
7-
get { self.generate() }
8-
set { self.generate = { newValue } }
5+
package struct CurrentTimeGenerator: DependencyKey, Sendable {
6+
private var generate: @Sendable () -> Int64
7+
package var now: Int64 {
8+
get { self.generate() }
9+
set { self.generate = { newValue } }
10+
}
11+
package func callAsFunction() -> Int64 {
12+
self.generate()
13+
}
14+
package static var liveValue: CurrentTimeGenerator {
15+
Self { Int64(clock_gettime_nsec_np(CLOCK_REALTIME)) }
16+
}
17+
package static var testValue: CurrentTimeGenerator {
18+
Self { Int64(clock_gettime_nsec_np(CLOCK_REALTIME)) }
19+
}
920
}
10-
package func callAsFunction() -> Int64 {
11-
self.generate()
12-
}
13-
package static var liveValue: CurrentTimeGenerator {
14-
Self { Int64(clock_gettime_nsec_np(CLOCK_REALTIME)) }
15-
}
16-
package static var testValue: CurrentTimeGenerator {
17-
Self { Int64(clock_gettime_nsec_np(CLOCK_REALTIME)) }
18-
}
19-
}
2021

21-
extension DependencyValues {
22-
package var currentTime: CurrentTimeGenerator {
23-
get { self[CurrentTimeGenerator.self] }
24-
set { self[CurrentTimeGenerator.self] = newValue }
22+
extension DependencyValues {
23+
package var currentTime: CurrentTimeGenerator {
24+
get { self[CurrentTimeGenerator.self] }
25+
set { self[CurrentTimeGenerator.self] = newValue }
26+
}
2527
}
26-
}
28+
#endif

Sources/SQLiteData/CloudKit/Internal/DefaultNotificationCenter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if canImport(UIKit)
1+
#if canImport(CloudKit) && canImport(UIKit)
22
import UIKit
33

44
private enum DefaultNotificationCenterKey: DependencyKey {
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import Foundation
1+
#if canImport(CloudKit)
2+
import Foundation
23

3-
final class IsolatedWeakVar<T: AnyObject>: @unchecked Sendable {
4-
let lock = NSLock()
5-
weak var _value: T?
4+
final class IsolatedWeakVar<T: AnyObject>: @unchecked Sendable {
5+
let lock = NSLock()
6+
weak var _value: T?
67

7-
init() {}
8+
init() {}
89

9-
var value: T? {
10-
lock.lock()
11-
defer { lock.unlock() }
12-
return _value
10+
var value: T? {
11+
lock.lock()
12+
defer { lock.unlock() }
13+
return _value
14+
}
15+
func set(_ value: T) {
16+
precondition(_value == nil)
17+
lock.lock()
18+
defer { lock.unlock() }
19+
_value = value
20+
}
1321
}
14-
func set(_ value: T) {
15-
precondition(_value == nil)
16-
lock.lock()
17-
defer { lock.unlock() }
18-
_value = value
19-
}
20-
}
22+
#endif

0 commit comments

Comments
 (0)