0
votes

I have successfully versioned my core data model for a forthcoming version 1.1 of my app, using lightweight migration. I have a question about the maintainability of this approach.

If I again version my model in v1.2 of my app, and a user updates from v1.0 to 1.2, will the two migrations be applied successfully in sequence? That is, if I keep the versions of the model around, will the migrations be cumulative?

1

1 Answers

3
votes

If both migrations are lightweight then there's no need to apply both in sequence. Since lightweight migrations can occur on:

  • Simple addition of a new attribute
  • Removal of an attribute
  • A non-optional attribute becoming optional
  • An optional attribute becoming non-optional, and defining a default value
  • Renaming an entity or property

In the final case you supply the name used in the store (the 'canonical name'). That's the property name by default, so it ends up being whatever the property was called in the first version of your data model. You can then change the property name arbitrarily as long as you leave the canonical name alone.

So the net effect is that there's no sequence of events in which Core Data can figure out how to migrate from version 1 to version 2 and from version 2 to version 3 but not directly from version 1 to version 3.

Conversely, if you specify manual mappings via a mapping model then you'll either have to write code to apply all the manual mappings cumulatively or provide O(n^2) mappings as your data model advances.