Re: core data migration - delete old store
Re: core data migration - delete old store
- Subject: Re: core data migration - delete old store
- From: Roland King <email@hidden>
- Date: Fri, 22 Jul 2011 00:16:37 +0800
Great - thanks for this - gets me started, I've found the documentation quite dense and soon I have to pitch in and just give it a go (I have a model I need to update in my test app and I really don't want to toss the data).
I need to hunt around the NSManagedObjectModel class a bit more, clearly, there are methods there I don't know enough about. I assume there are ways to enumerate the models in the bundle, figure out which one is the 'current' one and which one may match the store, will go read the class docs when they've finished d/l'ing. I saw some of the methods for making an on-the-fly migration, I'll try those out too see if they work.
I think lightweight is going to do it for this change. One attribute deleted, one entity added, one mapping added, one attribute added (with a default). It's not a bad way to get my feet wet with migration actually, I can afford to bungle it up, I can save the sqlite file before I start and give it few cracks. Ok that's the weekend!
On Jul 21, 2011, at 9:35 PM, Dave Fernandes wrote:
> Yes, if you want the file deleted you have to do it yourself. There are certainly cases where you would not want to delete the file. For example for a document, the user may want to keep that archive around in case they need to revert to a previous version of the app, or share it with someone else. In that case, they should be informed when the file is going to be migrated, and they should be the one to delete the old version.
>
> You can check whether the store needs to be migrated using -[NSManagedObjectModel isConfiguration:compatibleWithStoreMetadata:]; first get the current model and then check whether it is compatible with metadata from the store you want to open.
>
> Lightweight migration also cannot handle all types of model changes. So, when you start to support multiple model versions, it might be a good idea to check if you *can* migrate from version x to version y using +[NSMappingModel inferredMappingModelForSourceModel:destinationModel:error:]. You may end up with cases where you have to use your own mapping model for some migrations.
>
> Dave
>
> On 2011-07-21, at 8:31 AM, Roland King wrote:
>
>> I suppose I had to get to core data migration one day … :(
>>
>> I've read the documentation a couple of times and it says that the default migration process finishes by renaming the old store to the same thing with a tilde prefix. Does that mean you, the programmer, are responsible for deleting it again afterwards or is there a piece I've missed where eventually it does get cleaned up? I was thinking that if you use automatic migration, you don't even know when the store has been migrated and that you should thus go look for a tilde version and remove it. If that's the case I wondered how many apps have upgraded their core data stores and left the old one sitting there taking up the same amount of space. _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden