From 138b5bfa049c639b50da5b07b2898af1e963a3cc Mon Sep 17 00:00:00 2001 From: Huong Do Date: Tue, 23 Sep 2025 17:00:36 +0700 Subject: [PATCH 1/5] Add model version 127 --- .../.xccurrentversion | 2 +- .../Model 127.xcdatamodel/contents | 1108 +++++++++++++++++ 2 files changed, 1109 insertions(+), 1 deletion(-) create mode 100644 Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 127.xcdatamodel/contents diff --git a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion index 014e45c214a..b0c2ba22f43 100644 --- a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion +++ b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - Model 126.xcdatamodel + Model 127.xcdatamodel diff --git a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 127.xcdatamodel/contents b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 127.xcdatamodel/contents new file mode 100644 index 00000000000..7540d6924e9 --- /dev/null +++ b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 127.xcdatamodel/contents @@ -0,0 +1,1108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 307e3688fd2340e42d9328ce025107d0dbafb9dd Mon Sep 17 00:00:00 2001 From: Huong Do Date: Tue, 23 Sep 2025 17:09:18 +0700 Subject: [PATCH 2/5] Create new Booking entity --- .../Model/Booking/Booking+CoreDataClass.swift | 9 ++++++ .../Booking/Booking+CoreDataProperties.swift | 31 +++++++++++++++++++ .../Model 127.xcdatamodel/contents | 21 ++++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 Modules/Sources/Storage/Model/Booking/Booking+CoreDataClass.swift create mode 100644 Modules/Sources/Storage/Model/Booking/Booking+CoreDataProperties.swift diff --git a/Modules/Sources/Storage/Model/Booking/Booking+CoreDataClass.swift b/Modules/Sources/Storage/Model/Booking/Booking+CoreDataClass.swift new file mode 100644 index 00000000000..70b5222d273 --- /dev/null +++ b/Modules/Sources/Storage/Model/Booking/Booking+CoreDataClass.swift @@ -0,0 +1,9 @@ +public import Foundation +public import CoreData + +public typealias BookingCoreDataClassSet = NSSet + +@objc(Booking) +public class Booking: NSManagedObject { + +} diff --git a/Modules/Sources/Storage/Model/Booking/Booking+CoreDataProperties.swift b/Modules/Sources/Storage/Model/Booking/Booking+CoreDataProperties.swift new file mode 100644 index 00000000000..cd64ecfb0c4 --- /dev/null +++ b/Modules/Sources/Storage/Model/Booking/Booking+CoreDataProperties.swift @@ -0,0 +1,31 @@ +public import Foundation +public import CoreData + + +public typealias BookingCoreDataPropertiesSet = NSSet + +extension Booking { + + @nonobjc public class func fetchRequest() -> NSFetchRequest { + return NSFetchRequest(entityName: "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? + +} diff --git a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 127.xcdatamodel/contents b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 127.xcdatamodel/contents index 7540d6924e9..1e752320269 100644 --- a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 127.xcdatamodel/contents +++ b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 127.xcdatamodel/contents @@ -1,5 +1,5 @@ - + @@ -62,6 +62,25 @@ + + + + + + + + + + + + + + + + + + + From 2d2baeda88b5ceea1b8234555190d653ea3a7b49 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Tue, 23 Sep 2025 17:23:42 +0700 Subject: [PATCH 3/5] Add ReadOnlyConvertible conformance --- .../Booking/Booking+ReadOnlyConvertible.swift | 52 +++++++++++++++++++ Modules/Sources/Yosemite/Model/Model.swift | 2 + 2 files changed, 54 insertions(+) create mode 100644 Modules/Sources/Yosemite/Model/Booking/Booking+ReadOnlyConvertible.swift diff --git a/Modules/Sources/Yosemite/Model/Booking/Booking+ReadOnlyConvertible.swift b/Modules/Sources/Yosemite/Model/Booking/Booking+ReadOnlyConvertible.swift new file mode 100644 index 00000000000..aa573436a25 --- /dev/null +++ b/Modules/Sources/Yosemite/Model/Booking/Booking+ReadOnlyConvertible.swift @@ -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 ?? "") + } +} diff --git a/Modules/Sources/Yosemite/Model/Model.swift b/Modules/Sources/Yosemite/Model/Model.swift index 3c97dc6f6e9..e7be38a3663 100644 --- a/Modules/Sources/Yosemite/Model/Model.swift +++ b/Modules/Sources/Yosemite/Model/Model.swift @@ -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 @@ -265,6 +266,7 @@ public typealias StorageBlazeCampaignListItem = Storage.BlazeCampaignListItem public typealias StorageBlazeTargetDevice = Storage.BlazeTargetDevice public typealias StorageBlazeTargetLanguage = Storage.BlazeTargetLanguage public typealias StorageBlazeTargetTopic = Storage.BlazeTargetTopic +public typealias StorageBooking = Storage.Booking public typealias StorageCardReaderType = Storage.CardReaderType public typealias StorageCoupon = Storage.Coupon public typealias StorageCustomer = Storage.Customer From 2c4e5037ff780f32a323fafc1cf5ac148d96f298 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Tue, 23 Sep 2025 17:34:07 +0700 Subject: [PATCH 4/5] Add migration test --- Modules/Sources/Storage/Model/MIGRATIONS.md | 4 +++ .../CoreData/MigrationTests.swift | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/Modules/Sources/Storage/Model/MIGRATIONS.md b/Modules/Sources/Storage/Model/MIGRATIONS.md index 4f75348ec89..30662cfe9f2 100644 --- a/Modules/Sources/Storage/Model/MIGRATIONS.md +++ b/Modules/Sources/Storage/Model/MIGRATIONS.md @@ -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. diff --git a/Modules/Tests/StorageTests/CoreData/MigrationTests.swift b/Modules/Tests/StorageTests/CoreData/MigrationTests.swift index 17855577abf..56754b9c05c 100644 --- a/Modules/Tests/StorageTests/CoreData/MigrationTests.swift +++ b/Modules/Tests/StorageTests/CoreData/MigrationTests.swift @@ -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 @@ -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 + ]) + } } From 8d60c5db82616227618ae757bdd7ca029fbcc65c Mon Sep 17 00:00:00 2001 From: Huong Do Date: Tue, 23 Sep 2025 17:51:36 +0700 Subject: [PATCH 5/5] Address periphery violations --- .../Storage/Model/Booking/Booking+CoreDataClass.swift | 6 ++---- .../Model/Booking/Booking+CoreDataProperties.swift | 11 ++--------- Modules/Sources/Yosemite/Model/Model.swift | 1 + 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Modules/Sources/Storage/Model/Booking/Booking+CoreDataClass.swift b/Modules/Sources/Storage/Model/Booking/Booking+CoreDataClass.swift index 70b5222d273..a90b5a15d5c 100644 --- a/Modules/Sources/Storage/Model/Booking/Booking+CoreDataClass.swift +++ b/Modules/Sources/Storage/Model/Booking/Booking+CoreDataClass.swift @@ -1,7 +1,5 @@ -public import Foundation -public import CoreData - -public typealias BookingCoreDataClassSet = NSSet +import Foundation +import CoreData @objc(Booking) public class Booking: NSManagedObject { diff --git a/Modules/Sources/Storage/Model/Booking/Booking+CoreDataProperties.swift b/Modules/Sources/Storage/Model/Booking/Booking+CoreDataProperties.swift index cd64ecfb0c4..d02abc70e58 100644 --- a/Modules/Sources/Storage/Model/Booking/Booking+CoreDataProperties.swift +++ b/Modules/Sources/Storage/Model/Booking/Booking+CoreDataProperties.swift @@ -1,15 +1,8 @@ -public import Foundation -public import CoreData - - -public typealias BookingCoreDataPropertiesSet = NSSet +import Foundation +import CoreData extension Booking { - @nonobjc public class func fetchRequest() -> NSFetchRequest { - return NSFetchRequest(entityName: "Booking") - } - @NSManaged public var bookingID: Int64 @NSManaged public var siteID: Int64 @NSManaged public var parentID: Int64 diff --git a/Modules/Sources/Yosemite/Model/Model.swift b/Modules/Sources/Yosemite/Model/Model.swift index e7be38a3663..f87a23a533d 100644 --- a/Modules/Sources/Yosemite/Model/Model.swift +++ b/Modules/Sources/Yosemite/Model/Model.swift @@ -266,6 +266,7 @@ 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