mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Lightweight migration and initializing CoreStore #207
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @tosbaha on GitHub (Apr 23, 2018).
Hi,
I decided to finally move my statck to CoreStore but I have questions about initializing and doing lightweight migration. I upgraded my model from Kargo to KargoV2 and coded NSEntityMigrationPolicy as I said in issue #142. With my old CoreData code and using
update works without a problem. I also use different URL for sqlite. I have come up with below code and I appreciate if you can tell me whether it is good or not. I also didn't understand the usage of
migrationProcess. What we are doing withlet migrationProcess?@JohnEstropia commented on GitHub (Apr 24, 2018):
@tosbaha Your code looks okay.
It's actually
migrationProgress, and it's an instance of aProgress(NSProgress).If it's
nilit means your store is in the latest version and doesn't need an update. Otherwise you can use thatProgressinstance to track the progress of migrations.@tosbaha commented on GitHub (Apr 24, 2018):
Thanks for the fast reply. I don't need to track to migration process. Since I am doing lightweight migration, is it better to use
dataStack.addStorageordataStack.addStorageAndWait? AFAIK, using asynchronous call helps to not blocking the UI. Library I guess usesListMonitorabstraction for NSFetchedResultsController. Will there be any problem if I use synchronous or asynchronous version?@tosbaha commented on GitHub (Apr 24, 2018):
I tried above code but gives bunch of errors and warnings. I am not sure why it is giving me those. Here is the code and Log.
Logs
FINAL EDIT:
I solved migration problem with using
.allowSynchronousLightweightMigrationflag. However last error related to API violation is related to iOS 11 I guess. I searched and found similar issue in Ensembles framework. It seems in iOS 11, we should also addNSBinaryStoreInsecureDecodingCompatibilityOptiontotrue. I checked the code base and it seems this is not set by library. Here is PR that is merged to Ensembles. https://github.com/drewmccormack/ensembles/pull/260/filesApple forum link https://forums.developer.apple.com/thread/84588
@JohnEstropia commented on GitHub (Apr 25, 2018):
@tosbaha Thanks for pointing that out, I'll check the details of that issue.
@PraLeshik commented on GitHub (Jul 21, 2018):
Hello. In call dataStack.addStorageAndWait we put one storage. Is it source or destination storage? I assume we have to use both ones in call. And I have the same problem with "The model used to open the store is incompatible with the one used to create the store" during migration.
@JohnEstropia commented on GitHub (Jul 23, 2018):
@PraLeshik You need to give the new model to
addStorage. You also need to make sure that you are creating theDataStackusing aCoreStoreSchemathat contains all your old models or Core Data cannot infer your migrations.@PraLeshik commented on GitHub (Jul 23, 2018):
Thanks, @JohnEstropia
Not sure if I use storage initialization in a right way. Still getting error:
Here is my code:
@JohnEstropia commented on GitHub (Jul 23, 2018):
@PraLeshik You'll need to pass BOTH versions to the DataStack. (See:
SchemaHistory)As for your entities, you mentioned that other than
PumpingEventall other entities are the same. Just make sure that you have no relationship changes as well (this includes any entity with relationship toPumpingEvent). If you have any relationship changes, you will need to duplicate those related classes as well.@PraLeshik commented on GitHub (Jul 25, 2018):
@JohnEstropia Thanks for your answer. Still getting error "Attempted to create an entity of type 'UserProfile', but a destination persistent store containing the entity type could not be found.". Is there something wrong in storage initialization?