Xiao Yao
Xiao Yao

Reputation: 33

Migrating with custom policy in Magical Record

I'm updating one of my applications that uses Core Data for the data management. In this current version, I implemented Magic Record and also updated the data model. The data model will not be able to use automatic migration so I need to implement manual migration. I am confused as to how to do this with Magic Record.

I looked into the source code for Magic Record and from the looks of it, there are no implementations of supporting a migration manager when trying to create a persistent store coordinator.

When the DEBUG flag is set to true, the application deletes the incompatible version and creates a new database with the current version. However, this does not migrate all the data. From the docs, it looks like this feature is implemented so that we don't have to constantly delete older versions by removing the app and reinstalling, so that makes sense.

So does Magic Record support migration managers? I have thought about adding it to the source code, but I don't want to modify the library.

Upvotes: 3

Views: 1354

Answers (2)

Shmidt
Shmidt

Reputation: 16684

I asked the authors of MagicalRecord and got the following answer:

I just added this to the experimental branch. Have a look at the MagicalRecord class method

+setupCoreDataStackWIthManuallyMigratingStoreNamed:

Let me know how it works out for you. Also in the experimental branch are some other features that need to migrate (pun!) back to the master branch, so let me know if you find anything else there as well.

Upvotes: 2

Olaf
Olaf

Reputation: 3042

You don't need to modify MagicalRecord. Just trigger your migration manager before you setup the MagicalRecord stack.

  • At application start detect if you need a migration.
  • If a migration is needed then run the migration manager. A good example is in SO 5995231
  • When finished or when no migration is needed then start up the MagicalRecord stack.

Upvotes: 1

Related Questions