Question

I'm implementing a migration of my CoreData store, where I replace a string attribute with a BOOL attribute: when the string was "0", the bool should be "YES", and in all other cases the bool should be "NO". Sounds simple enough, but I think I still need to add a mapping model. I added that in Xcode, and implemented createDestinationInstancesForSourceInstance:

- (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sInstance entityMapping: (NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error
{
   NSManagedObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:[mapping destinationEntityName] inManagedObjectContext:[manager destinationContext]];

   NSString *oldValue = [sInstance valueForKey: @"oldString"];
   NSNumber *newValue = @(NO);

   if ([oldValue integerValue] == 0)
      newValue = @(YES);

   [newObject setValue: newValue forKey: @"newBool"];

   [manager associateSourceInstance:sInstance withDestinationInstance:newObject forEntityMapping:mapping];

   return YES;
}

However this never gets called.

Since I'm using MagicalRecord, I also am using:

[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed: @"storename.sqlite"];

I read I also need to use: NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: @(YES), NSInferMappingModelAutomaticallyOption: @(NO)}; when I init my store, but how do I use that with MagicalRecord?

UPDATE: So MR uses MR_autoMigrationOptions to set the migration options. Is there any way to modify these to support a manual migration ?

Was it helpful?

Solution

In order to perform a manual migration you will need to use:

[MagicalRecord setupManuallyMigratingStackWithSQLiteStoreNamed: @"storename.sqlite"];

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top