From 98aafbdb15b76b641feb5e543f0a171d978fbc11 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Mon, 30 Jun 2025 10:48:24 +0700 Subject: [PATCH] add createdVia attribute to CD. New CD model 123 --- Modules/Sources/Storage/Model/MIGRATIONS.md | 4 + .../Model/Order+CoreDataProperties.swift | 1 + .../.xccurrentversion | 2 +- .../Model 123.xcdatamodel/contents | 1070 +++++++++++++++++ .../CoreData/MigrationTests.swift | 35 + 5 files changed, 1111 insertions(+), 1 deletion(-) create mode 100644 Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 123.xcdatamodel/contents diff --git a/Modules/Sources/Storage/Model/MIGRATIONS.md b/Modules/Sources/Storage/Model/MIGRATIONS.md index dea6f2a70d6..05c4bd2ad48 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 123 (Release 22.8.0.0) +- @iamgabrielma 2025-06-30 + - Added `createdVia` attribute to `Order` entity. + ## Model 122 (Release 22.7.0.0) - @itsmeichigo 2025-06-20 - Added `shipmentID` attribute to `ShippingLabel` entity. diff --git a/Modules/Sources/Storage/Model/Order+CoreDataProperties.swift b/Modules/Sources/Storage/Model/Order+CoreDataProperties.swift index 599f2d35850..144cbfe87c0 100644 --- a/Modules/Sources/Storage/Model/Order+CoreDataProperties.swift +++ b/Modules/Sources/Storage/Model/Order+CoreDataProperties.swift @@ -20,6 +20,7 @@ extension Order { @NSManaged public var billingPostcode: String? @NSManaged public var billingState: String? @NSManaged public var chargeID: String? + @NSManaged public var createdVia: String? @NSManaged public var currency: String? @NSManaged public var customerID: Int64 @NSManaged public var customerNote: String? diff --git a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion index e1488c4dd38..1bc10c7c9f6 100644 --- a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion +++ b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - Model 122.xcdatamodel + Model 123.xcdatamodel diff --git a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 123.xcdatamodel/contents b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 123.xcdatamodel/contents new file mode 100644 index 00000000000..f0744730c63 --- /dev/null +++ b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 123.xcdatamodel/contents @@ -0,0 +1,1070 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Modules/Tests/StorageTests/CoreData/MigrationTests.swift b/Modules/Tests/StorageTests/CoreData/MigrationTests.swift index 8120bd1b9b6..cff1d2c6a33 100644 --- a/Modules/Tests/StorageTests/CoreData/MigrationTests.swift +++ b/Modules/Tests/StorageTests/CoreData/MigrationTests.swift @@ -3363,6 +3363,41 @@ final class MigrationTests: XCTestCase { let updatedShipmentID = migratedLabel.value(forKey: "shipmentID") as? String XCTAssertEqual(updatedShipmentID, id) } + + func test_migrating_from_122_to_123_adds_new_attribute_createdVia_to_order() throws { + // Given + let sourceContainer = try startPersistentContainer("Model 122") + let sourceContext = sourceContainer.viewContext + + let object = sourceContext.insert(entityName: "Order", properties: [ + "orderID": 123, + "statusKey": "" // statusKey is a required value, unrelated to this migration + ]) + try sourceContext.save() + + // `createdVia` should not be present in model 122 + XCTAssertNil(object.entity.attributesByName["createdVia"], "Precondition. Attribute does not exist.") + + // When + let targetContainer = try migrate(sourceContainer, to: "Model 123") + + // Then + let targetContext = targetContainer.viewContext + let migratedObject = try XCTUnwrap(targetContext.first(entityName: "Order")) + + // `createdVia` should be present in model 123 + XCTAssertNotNil(migratedObject.entity.attributesByName["createdVia"]) + + // `createdVia` value should default as nil in model 123 + let value = migratedObject.value(forKey: "createdVia") as? String + XCTAssertNil(value) + + // `createdVia` must be settable + migratedObject.setValue("pos-rest-api", forKey: "createdVia") + try targetContext.save() + let updatedValue = migratedObject.value(forKey: "createdVia") as? String + XCTAssertEqual(updatedValue, "pos-rest-api") + } } // MARK: - Persistent Store Setup and Migrations