caiyue1993 / IceCream

Sync Realm Database with CloudKit
MIT License
1.94k stars 245 forks source link

Migration succeeds when app is offline but when becomes online, local objects are replaced with iCloud objects due to which local objects lose data #271

Open mibrahim025 opened 1 year ago

mibrahim025 commented 1 year ago

I had recipient and phonenumber objects like these.

@objc class Recipient: Object { @Persisted(primaryKey: true) var rec_id = "" @Persisted var firstName = "" @Persisted var lastName = "" @Persisted var phoneNumbersList = List() @Persisted var email = "" @Persisted var isDeleted = false // IceCream requirement }

@objc class PhoneNumber: Object { @Persisted(primaryKey: true) var id = "" @Persisted var number = "" @Persisted var isDeleted = false // IceCream requirement }

I changed the schema to this. i.e. removed the phoneNumberList property and added phoneNumber as string only.

@objc public class Recipient: Object { @Persisted(primaryKey: true) var rec_id = "" @Persisted var firstName = "" @Persisted var lastName = "" @Persisted var phoneNumber = "" @Persisted var email = "" @Persisted public var isDeleted = false // IceCream requirement }

Old records on icloud have phonenumberList property populated and phoneNumber property is nil.

Now in the new version of the app, i have done migration correctly and it works but when the app is offline. When it becomes online, the migrated records again are replaced with the fetched records from icloud whose phoneNumber property is nil and my app starts missing phoneNumbers. How can i solve this?

rosday commented 1 year ago

I am having a similar problem