Skip to content

Commit f23f87b

Browse files
Added a reference to the preceding snapshot in an iteration
1 parent 04ad5ca commit f23f87b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Sources/CodableDatastore/Persistence/Disk Persistence/Snapshot/SnapshotIteration.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ struct SnapshotIteration: Codable, Equatable, Identifiable {
3030
/// The iteration this one replaces.
3131
var precedingIteration: SnapshotIterationIdentifier?
3232

33+
/// The snapshot the preceding iteration belongs to.
34+
///
35+
/// When set, the specified snapshot should be referenced to load the ``precedingIteration`` from. When `nil`, the current snapshot should be used.
36+
var precedingSnapshot: SnapshotIdentifier?
37+
3338
/// The iterations that replace this one.
3439
///
3540
/// If changes branched at this point in time, there may be more than one iteration to choose from. In this case, the first entry will be the oldest successor, while the last entry will be the most recent.

Tests/CodableDatastoreTests/SnapshotIterationTests.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,48 @@ final class SnapshotIterationTests: XCTestCase, @unchecked Sendable {
8989
decoder.dateDecodingStrategy = .iso8601WithMilliseconds
9090
_ = try decoder.decode(SnapshotIteration.self, from: data)
9191
}
92+
93+
func testDecodingOptionalPrecedingSnapshotIdentifiers() throws {
94+
let data = Data("""
95+
{
96+
"addedDatastoreRoots" : [
97+
{
98+
"datastoreID" : "Store-FD9BA6F1BD3667C8",
99+
"datastoreRootID" : "2025-02-12 00-00-00-046 44BBE608B9CBF788"
100+
}
101+
],
102+
"addedDatastores" : [
103+
104+
],
105+
"creationDate" : "2025-02-12T00:00:00.057Z",
106+
"dataStores" : {
107+
"Store" : {
108+
"id" : "Store-FD9BA6F1BD3667C8",
109+
"key" : "Store",
110+
"root" : "2024-08-24 09-39-57-775 66004A6BA331B89C"
111+
}
112+
},
113+
"id" : "2025-02-12 00-00-00-057 0130730F8F6A1ACC",
114+
"precedingIteration" : "2025-02-11 23-59-54-727 447A1A1E1CF82177",
115+
"precedingSnapshot" : "2024-04-14 13-09-27-739 A1EEB1A3AF102F15",
116+
"removedDatastoreRoots" : [
117+
{
118+
"datastoreID" : "Store-FD9BA6F1BD3667C8",
119+
"datastoreRootID" : "2025-02-11 23-59-54-721 2AAEA12A38303055"
120+
}
121+
],
122+
"removedDatastores" : [
123+
124+
],
125+
"successiveIterations" : [
126+
127+
],
128+
"version" : "alpha"
129+
}
130+
""".utf8)
131+
132+
let decoder = JSONDecoder()
133+
decoder.dateDecodingStrategy = .iso8601WithMilliseconds
134+
_ = try decoder.decode(SnapshotIteration.self, from: data)
135+
}
92136
}

0 commit comments

Comments
 (0)