Rama 1.6.0: dedup CloudKit-safe (WIP: StableID + UUIDs estables en defaults)
Funde 1.5.1 en 1.6.0. Parte 1 dedup (prevención): StableID (UUIDv5 namespace+nombre), Account.defaultAccountStableID, Category.stableID(for:) + asignación en createDefaultCategories. Pendiente: asignar en repos + limpieza de duplicados existentes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L2p3gUZRNWW388rWFRjiU7
This commit is contained in:
@@ -46,6 +46,11 @@ public class Account: NSManagedObject, Identifiable {
|
||||
|
||||
extension Account {
|
||||
static let defaultAccountName = "Default"
|
||||
|
||||
/// Deterministic UUID for the auto-created "Default" account, so every device
|
||||
/// creates it as the SAME CloudKit record instead of a per-device duplicate.
|
||||
/// See StableID.
|
||||
static let defaultAccountStableID = StableID.v5("account:default")
|
||||
}
|
||||
|
||||
// MARK: - Computed Properties
|
||||
|
||||
@@ -92,9 +92,17 @@ extension Category {
|
||||
("ETFs", "#EC4899", "chart.bar.fill")
|
||||
]
|
||||
|
||||
/// Deterministic UUID for a default category, so every device creates each
|
||||
/// default category as the SAME CloudKit record instead of a per-device
|
||||
/// duplicate. Only meaningful for the built-in default names. See StableID.
|
||||
static func stableID(for name: String) -> UUID {
|
||||
StableID.v5("category:\(name.lowercased())")
|
||||
}
|
||||
|
||||
static func createDefaultCategories(in context: NSManagedObjectContext) {
|
||||
for (index, categoryData) in defaultCategories.enumerated() {
|
||||
let category = Category(context: context)
|
||||
category.id = stableID(for: categoryData.name)
|
||||
category.name = categoryData.name
|
||||
category.colorHex = categoryData.colorHex
|
||||
category.icon = categoryData.icon
|
||||
|
||||
Reference in New Issue
Block a user