Search code examples
simperium

"Importing" existing data to Simperium


When an existing database is opened and simperium is started afterwards, existing entities are not loaded to the server. Only newly created entities are loaded.

Is it possible to add Simperium to an existing database and upload all not yet loaded entities to the server? I'm thinking about adding Simperium to an existing app where the current data has to be uploaded on first start.


Solution

  • This is intended to be supported (and has been done in the app Simplenote), but it's possible there is something not working.

    When your app starts, do you see a log message that says "Simperium managing X MyEntity instances" for the existing entity that you expect Simperium to see? And does X match the number of existing objects in your database?

    Simperium performs a validation step on startup. If any existing objects that are detected in your model as being SPManagedObject subclasses are lacking a valid simperiumKey, one will get created.

    Currently this validation process isn't automatically saving the new keys that are generated. Have you tried to save your context after Simperium starts for the first time to see if that triggers an update?

    Also, if it's helpful, there's an undocumented method called getSimperiumKeyFromLegacyKey that you can implement on your object subclasses if you have an existing unique ID that you'd like to preserve in Simperium during this validation process.