From d87d9d3dd56e7c3952114255103f05a2c610a5ff Mon Sep 17 00:00:00 2001 From: alexandrev-tibco Date: Wed, 22 Jul 2026 09:56:33 +0200 Subject: [PATCH] Debug helper: initializeCloudKitSchema (opt-in por launch arg -InitializeCloudKitSchema) Materializa el modelo completo en el esquema de Development de CloudKit para poder desplegar a Production los campos que nunca se exportaron (monthlyContribution, allocationTarget). Sin ellos, Production rechaza los registros y el export falla en bloque (CKErrorPartialFailure). Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01LZFmGhbWzibhApev3C4554 --- PortfolioJournal/Models/CoreDataStack.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/PortfolioJournal/Models/CoreDataStack.swift b/PortfolioJournal/Models/CoreDataStack.swift index cc77ffe..a9749c9 100644 --- a/PortfolioJournal/Models/CoreDataStack.swift +++ b/PortfolioJournal/Models/CoreDataStack.swift @@ -192,6 +192,24 @@ class CoreDataStack: ObservableObject { print("Core Data failed to load: \(error), \(error.userInfo)") } else { print("Core Data loaded successfully at: \(description.url?.path ?? "unknown")") + #if DEBUG + // Dev-only, opt-in: push the FULL model schema to the Development CloudKit + // environment so optional fields that were never exported by a Debug run + // (e.g. monthlyContribution on InvestmentSource, allocationTarget on Category) + // get materialised — otherwise they can't be deployed to Production and every + // Production export rejects those records (bare CKErrorPartialFailure). + // Run ONCE from Xcode with launch arg -InitializeCloudKitSchema, watch for the + // ✅ log, then deploy to Production in the CloudKit Console and remove the arg. + if ProcessInfo.processInfo.arguments.contains("-InitializeCloudKitSchema"), + let ckContainer = container as? NSPersistentCloudKitContainer { + do { + try ckContainer.initializeCloudKitSchema(options: []) + print("✅ CloudKit schema initialized in Development. Now open the CloudKit Console → Deploy Schema Changes → Production.") + } catch { + print("❌ initializeCloudKitSchema failed: \(error)") + } + } + #endif } DispatchQueue.main.async { self?.isLoaded = true