-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Newly added column is not getting synced after Realm is migrated #175
Comments
Observed that basically any column (it need not be a new column) that is migrated is not synced. Will there be any Realm notifications during migration? Is that why SyncKit is not tracking these changes? |
We are initializing the synchronizers after performing the Realm migration. Looks like this might be the reason why SyncKit is not receiving any notifications. How do you all do migration? Kindly throw some light on this. |
Hi @sskjames, I'm afraid there's currently no logic to handle a migration. In the meantime, if you're in a rush, I would suggest adding the new column to the model, loading the Realm without a custom migration, and manually assigning the values so the changes will be picked up by SyncKit. Then in the future you could do another migration where you drop the old column. But I understand this might not work for your use case |
Hi @mentrena, thank you very much for your feedback. I managed to find a workaround so that the changes are picked up but yes it would be nice if SyncKit provides an easy way to manage this future. Here's how our migration code looks like:
"prepareMigration" code is just how we normally do Realm migration.
We couldn't load the synchronizers before the migration is performed, as the database couldn't be opened. So in the "prepareMigration" phase, we just save the old object details in UserDefaults currently and then later just apply the changes once the synchronizers are initialized. By doing it this way, SyncKit was able to receive notifications and the migrated changes were synced. This workflow would be helpful when the user already has the database locally. In the even of the user's data is not available locally but has to be retrieved from CloudKit, we hook into the excellent RecordProcessingDelegate architechture provided by SyncKit to do the migration. |
Hey @sskjames I'm thinking about your scenario and wondering if what you're doing isn't already the best possible solution. Do you have any idea of what a better solution would look like? In terms of interface. |
Hi @mentrena,
Thank you very much for this amazing library. We are using Realm 10.20.1 + SyncKit 1.3.0.
We recently had to change the data type of a column. But since CloudKit doesn't allow changing a column's data type (once the schema is deployed to Production), we added a new column with the correct data type and added migration scripts to handle this change.
This means once the schema is upgraded, the local Realm database will not have the old column.
Under these circumstances, the value in the new column never gets synced to CloudKit.
Even when I change other columns in the same record, those changes were synced but not the newly added column.
However, when I make an explicit change to that column, it is getting synced as expected.
I even tried calling eraseLocalMetadata after Realm objects are migrated, but the problem remains.
Have I missed something? Do I need to do something after Realm objects are migrated? Appreciate your help and insight.
Thanking in advance,
James
The text was updated successfully, but these errors were encountered: