Skip to content

Commit 2bd2e0a

Browse files
committed
Add migration description and tests
1 parent 21ec58e commit 2bd2e0a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Modules/Sources/Storage/Model/MIGRATIONS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This file documents changes in the WCiOS Storage data model. Please explain any changes to the data model as well as any custom migrations.
44

5+
## Model 129 (Release X.X.X.X)
6+
- @rafaelkayumov 2025-10-17
7+
- Added `attendanceStatusKey` attribute to `Booking` entity.
8+
59
## Model 128 (Release 23.5.0.0)
610
- @itsmeichigo 2025-10-14
711
- Added `BookingOrderInfo` entity.

Modules/Tests/StorageTests/CoreData/MigrationTests.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,6 +2281,37 @@ final class MigrationTests: XCTestCase {
22812281
let insertedResource = try XCTUnwrap(targetContext.first(entityName: "BookingResource"))
22822282
XCTAssertEqual(insertedResource, resource)
22832283
}
2284+
2285+
func test_migrating_from_128_to_129_adds_new_attendanceStatusKey_attribute_to_booking() throws {
2286+
// Given
2287+
let sourceContainer = try startPersistentContainer("Model 128")
2288+
let sourceContext = sourceContainer.viewContext
2289+
2290+
let booking = insertBooking(to: sourceContext)
2291+
try sourceContext.save()
2292+
2293+
XCTAssertNil(booking.entity.attributesByName["attendanceStatusKey"], "Precondition. Attribute does not exist.")
2294+
2295+
// When
2296+
let targetContainer = try migrate(sourceContainer, to: "Model 129")
2297+
2298+
// Then
2299+
let targetContext = targetContainer.viewContext
2300+
let migratedBooking = try XCTUnwrap(targetContext.first(entityName: "Booking"))
2301+
2302+
// `attendanceStatusKey` should be present in `migratedBooking`
2303+
XCTAssertNotNil(migratedBooking.entity.attributesByName["attendanceStatusKey"])
2304+
2305+
// `attendanceStatusKey` value should default as nil in model 129
2306+
let value = migratedBooking.value(forKey: "attendanceStatusKey") as? String
2307+
XCTAssertNil(value)
2308+
2309+
// `attendanceStatusKey` must be settable
2310+
migratedBooking.setValue("checked_in", forKey: "attendanceStatusKey")
2311+
try targetContext.save()
2312+
let updatedValue = migratedBooking.value(forKey: "attendanceStatusKey") as? String
2313+
XCTAssertEqual(updatedValue, "checked_in")
2314+
}
22842315
}
22852316

22862317
// MARK: - Persistent Store Setup and Migrations

0 commit comments

Comments
 (0)