Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation
import CoreData

@objc(Booking)
public class Booking: NSManagedObject {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Foundation
import CoreData

extension Booking {

@NSManaged public var bookingID: Int64
@NSManaged public var siteID: Int64
@NSManaged public var parentID: Int64
@NSManaged public var productID: Int64
@NSManaged public var orderID: Int64
@NSManaged public var resourceID: Int64
@NSManaged public var allDay: Bool
@NSManaged public var cost: String?
@NSManaged public var customerID: Int64
@NSManaged public var dateCreated: Date?
@NSManaged public var dateModified: Date?
@NSManaged public var endDate: Date?
@NSManaged public var startDate: Date?
@NSManaged public var googleCalendarEventID: String?
@NSManaged public var orderItemID: Int64
@NSManaged public var statusKey: String?
@NSManaged public var localTimezone: String?

}
4 changes: 4 additions & 0 deletions Modules/Sources/Storage/Model/MIGRATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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

## Model 127 (Release 23.4.0.0)
- @itsmeichigo 2025-09-23
- Added new `Booking` entity.

## Model 126 (Release 23.3.0.0)
- @rafaelkayumov 2025-09-15
- Added `isGarden` attribute to `Site` entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>Model 126.xcdatamodel</string>
<string>Model 127.xcdatamodel</string>
</dict>
</plist>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Foundation
import Storage


// MARK: - Storage.Booking: ReadOnlyConvertible
//
extension Storage.Booking: ReadOnlyConvertible {

/// Updates the Storage.Booking with the a ReadOnly.
///
public func update(with booking: Yosemite.Booking) {
siteID = booking.siteID
bookingID = booking.bookingID
allDay = booking.allDay
cost = booking.cost
customerID = booking.customerID
dateCreated = booking.dateCreated
dateModified = booking.dateModified
endDate = booking.endDate
googleCalendarEventID = booking.googleCalendarEventID
orderID = booking.orderID
orderItemID = booking.orderItemID
parentID = booking.parentID
productID = booking.productID
resourceID = booking.resourceID
startDate = booking.startDate
statusKey = booking.statusKey
localTimezone = booking.localTimezone
}

/// Returns a ReadOnly version of the receiver.
///
public func toReadOnly() -> Yosemite.Booking {
Booking(siteID: siteID,
bookingID: bookingID,
allDay: allDay,
cost: cost ?? "",
customerID: customerID,
dateCreated: dateCreated ?? Date(),
dateModified: dateModified ?? Date(),
endDate: endDate ?? Date(),
googleCalendarEventID: googleCalendarEventID,
orderID: orderID,
orderItemID: orderItemID,
parentID: parentID,
productID: productID,
resourceID: resourceID,
startDate: startDate ?? Date(),
statusKey: statusKey ?? "",
localTimezone: localTimezone ?? "")
}
}
3 changes: 3 additions & 0 deletions Modules/Sources/Yosemite/Model/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public typealias BlazeTargetLanguage = Networking.BlazeTargetLanguage
public typealias BlazeTargetOptions = Networking.BlazeTargetOptions
public typealias BlazeTargetLocation = Networking.BlazeTargetLocation
public typealias BlazeTargetTopic = Networking.BlazeTargetTopic
public typealias Booking = Networking.Booking
public typealias CreateBlazeCampaign = Networking.CreateBlazeCampaign
public typealias FallibleCancelable = Hardware.FallibleCancelable
public typealias CommentStatus = Networking.CommentStatus
Expand Down Expand Up @@ -265,6 +266,8 @@ public typealias StorageBlazeCampaignListItem = Storage.BlazeCampaignListItem
public typealias StorageBlazeTargetDevice = Storage.BlazeTargetDevice
public typealias StorageBlazeTargetLanguage = Storage.BlazeTargetLanguage
public typealias StorageBlazeTargetTopic = Storage.BlazeTargetTopic
// periphery:ignore - will be used later
public typealias StorageBooking = Storage.Booking
public typealias StorageCardReaderType = Storage.CardReaderType
public typealias StorageCoupon = Storage.Coupon
public typealias StorageCustomer = Storage.Customer
Expand Down
34 changes: 34 additions & 0 deletions Modules/Tests/StorageTests/CoreData/MigrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2755,6 +2755,32 @@ final class MigrationTests: XCTestCase {
let updatedCategory = migratedLabel.value(forKey: "hazmatCategory") as? String
XCTAssertEqual(updatedCategory, category)
}

func test_migrating_126_to_127_adds_new_booking_entity() throws {
// Given
let sourceContainer = try startPersistentContainer("Model 126")
let sourceContext = sourceContainer.viewContext

try sourceContext.save()

// Confidence Check. Booking should not exist in Model 126
XCTAssertNil(NSEntityDescription.entity(forEntityName: "Booking", in: sourceContext))

// When
let targetContainer = try migrate(sourceContainer, to: "Model 127")
let targetContext = targetContainer.viewContext

// Then
XCTAssertEqual(try targetContext.count(entityName: "Booking"), 0)

let booking = insertBooking(to: targetContext)
XCTAssertNoThrow(try targetContext.save())

XCTAssertEqual(try targetContext.count(entityName: "Booking"), 1)
let insertedBooking = try XCTUnwrap(targetContext.firstObject(ofType: Booking.self))
XCTAssertEqual(insertedBooking, booking)
XCTAssertEqual(insertedBooking.parentID, 0) // default value
}
}

// MARK: - Persistent Store Setup and Migrations
Expand Down Expand Up @@ -3679,4 +3705,12 @@ private extension MigrationTests {
"id": "test-address"
])
}

@discardableResult
func insertBooking(to context: NSManagedObjectContext) -> NSManagedObject {
context.insert(entityName: "Booking", properties: [
"siteID": 1,
"bookingID": 23
])
}
}