mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
CustomSchemaMappingProvider hangs and errors #364
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 @jeanetienne on GitHub (Jun 25, 2021).
Hi John & Contributors, thanks for providing such a valuable tool, making CoreData much more palatable, high level and swifty!
I am using CoreStore 8.0.1 and I can't find a way to make a custom migration work.
It seems to hang for a veeery long time (7+ minutes in iOS Simulator), and I get an error:
When I only try to do a
V1toV2migration and I let CoreStore infer all the migration (deleting a table and deleting a column), it works fine. As soon as I add aV2toV3migration with theCustomSchemaMappingProvider, it exhibits this behaviour (hanging for 7 min and erroring).Let me know if you need more details. I would appreciate any help understanding this problem! Thank you!
(I renamed my entities and table names, but everything else is the same)
Setup Details
Project
Schema
Database setup
Simulator output
Surprisingly this error output make it look like the migration from
V1toV2has a problem, when in fact this migration works fine when I comment out anything related toV3🤔 ...Thanks!
@JohnEstropia commented on GitHub (Jun 25, 2021):
@jeanetienne I see. I think your data is simply too large and is hitting
memoryperformance limits. Note thatNSCocoaErrorDomain (134090)isNSPersistentStoreTimeoutError.Unfortunately, Core Data's migration methods don't do well with large migrations like this since Core Data runs migrations in one transaction pass, which means the migrating
NSManagedObjectContextwill eat up large amounts of memory.I had a project where I had to handle something like this. What I did was create a new empty
DataStackfor the new model (yourV3), and manually move over chunks of data from the originalDataStack(yourV2). I don't think there's much we can do on CoreStore's side, since migration logic depends on how models need to be transformed to the new model.@jeanetienne commented on GitHub (Jun 25, 2021):
Thanks @JohnEstropia for the reply.
That's surprising, I only have 11 tables in total, and when running this above example, no table had more than 40 records... The whole sqlite file is 78KB... Could this be caused by something else?
So there's nothing wrong from the setup or the way the schema/migrations are implemented?
@JohnEstropia commented on GitHub (Jun 25, 2021):
I see, then it isn't a memory error.
I took a closer look at your models and it looks like you are reusing entities in multiple versions:
The strings (
"MyTable_01"etc) should stay the same, but I have never reused the same entity in multiple versions. I don't think that is supported.In your case, even if
MyEntity_01didn't change across models try to create a new type for it for every new version.Let me know how that works for you.
@jeanetienne commented on GitHub (Jun 25, 2021):
Oh, interesting! I'll give that a try now. Thanks for the suggestion!
@jeanetienne commented on GitHub (Jun 25, 2021):
@JohnEstropia you were right on target 🎯
That was it. The migration took ~2.4s in the simulator once I reshuffled my schema by separating each entity versions so I don't reuse them between version.
Thanks for the help!
🙏
@JohnEstropia commented on GitHub (Jun 25, 2021):
That's great to hear!