Clarifications about data migrations

Hi all,

I feel pretty comfortable with Core Data, however I’d need some clarifications in understanding how data migrations within different model versions work. I am using an SQLite store and my app is written in Swift.

I know that unfortunately Core Data does not support progressive migrations, however I haven’t found any references to understand wether that’s the case for lightweight migrations as well. In addition, what should happen in the following scenario?

Let model be at version 1. Let some model changes be introduced in version 2 and let they require a m_0 data migration to be performed by using a mapping model.

Now let some more model changes be introduced in version 3 and let a lightweight migration m_1 be needed.

1. Supposing that user has version 1 of the model and current version is 3, will both m_0 and m_1 migrations be performed?

2. If not, should I provide a mapping model from version 1 to version 3?

3. In general, how do you deal with data schema changes in the long term? I am not happy about the idea of creating custom mapping models between each version combination, I consider it a waste of time. There should be something more effective!

As far as I can tell, your premise is incorrect as far as lightweight migration goes. For lightweight migration, given two database schema the framework constructs a mapping for you whether you're going from version 1 to version 3, or version 2 to version 3. The key is to make sure that you keep all of your schema versions, so that the framework can work through all of the intermediate versions.


You don't supply custom mapping models when you're using lightweight migration.


Also, Core Data will do progressive migrations, if you write the code to tell it to do so. But that's extra lines of code not included in the standard templates, because it's more work to loop through each progressive model.

Clarifications about data migrations
 
 
Q