Automatic Lightweight Migrations Unsupported? #52

Closed
opened 2025-12-29 15:23:08 +01:00 by adam · 4 comments
Owner

Originally created by @colinmorelli on GitHub (Apr 26, 2016).

Apologies if I'm missing something here and there's a clear option I can add to support this behavior, but it looks like CoreStore doesn't automatically perform lightweight migrations. While introducing a change that simply added a few columns to an existing model, restarting the application results in error code 3 (MappingModelNotFound)

I don't believe I should need a mapping model for this change, but I don't see any capability of adjusting that behavior.

Originally created by @colinmorelli on GitHub (Apr 26, 2016). Apologies if I'm missing something here and there's a clear option I can add to support this behavior, but it looks like CoreStore doesn't automatically perform lightweight migrations. While introducing a change that simply added a few columns to an existing model, restarting the application results in error code 3 (MappingModelNotFound) I don't believe I should need a mapping model for this change, but I don't see any capability of adjusting that behavior.
adam added the question label 2025-12-29 15:23:08 +01:00
adam closed this issue 2025-12-29 15:23:08 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Apr 27, 2016):

You don't need a mapping model for lightweight migrations, but you do need to satisfy two conditions to tell CoreStore to do migrations, regardless if lightweight or not, for you:

1.) Declare the migration chain of versions when you initialize your DataStack:

CoreStore.defaultStack = DataStack(migrationChain: 
    ["MyAppModel", "MyAppModelV2", "MyAppModelV3", "MyAppModelV4"])

2.) Use the asynchronous DataStack.addSQLiteStore(....:completion:) method variants instead of the synchronous DataStack.addSQLiteStoreAndWait(...) methods.

@JohnEstropia commented on GitHub (Apr 27, 2016): You don't need a mapping model for lightweight migrations, but you do need to satisfy two conditions to tell CoreStore to do migrations, regardless if lightweight or not, for you: 1.) Declare the migration chain of versions when you initialize your `DataStack`: ``` swift CoreStore.defaultStack = DataStack(migrationChain: ["MyAppModel", "MyAppModelV2", "MyAppModelV3", "MyAppModelV4"]) ``` 2.) Use the asynchronous `DataStack.addSQLiteStore(....:completion:)` method variants instead of the synchronous `DataStack.addSQLiteStoreAndWait(...)` methods.
Author
Owner

@colinmorelli commented on GitHub (Apr 27, 2016):

Ah, didn't realize that was required for lightweight. I guess that leads to the next question: does this mean you have to explicitly create model versions even when performing lightweight migrations? Definitely best practice for a released app, but it seems like it could hinder development (albeit slightly).

I'm fine with creating new versions if that's the best way to go about it, it's not really a tedious process. But it would be nice to be able to support lightweight migrations without new model versions (as is the case with addPersistentStoreWithType:configuration:URL:options:error using the NSMigratePersistentStoresAutomaticallyOption option).

Also, excellent job with this library. It makes core data work exactly the way I want it to (read: it makes it not suck to work with).

@colinmorelli commented on GitHub (Apr 27, 2016): Ah, didn't realize that was required for lightweight. I guess that leads to the next question: does this mean you have to explicitly create model versions even when performing lightweight migrations? Definitely best practice for a released app, but it seems like it could hinder development (albeit slightly). I'm fine with creating new versions if that's the best way to go about it, it's not really a tedious process. But it would be nice to be able to support lightweight migrations without new model versions (as is the case with addPersistentStoreWithType:configuration:URL:options:error using the NSMigratePersistentStoresAutomaticallyOption option). Also, excellent job with this library. It makes core data work exactly the way I want it to (read: it makes it not suck to work with).
Author
Owner

@JohnEstropia commented on GitHub (Apr 27, 2016):

A small tweak with the MigrationChain logic can probably let you do this, but I'm not sure if it's OK to encourage it. If you have version A that can migrate lightweight-ly to B, and B to C, it does not guarantee that A to C can as well.

Keeping a history of your models also lets you keep track of the state of your users' existing stores so you can debug problems later on.

Thanks for the feedback, though. I'll close this issue but if you have any other questions feel free to ask :)

@JohnEstropia commented on GitHub (Apr 27, 2016): A small tweak with the `MigrationChain` logic can probably let you do this, but I'm not sure if it's OK to encourage it. If you have version A that can migrate lightweight-ly to B, and B to C, it does not guarantee that A to C can as well. Keeping a history of your models also lets you keep track of the state of your users' existing stores so you can debug problems later on. Thanks for the feedback, though. I'll close this issue but if you have any other questions feel free to ask :)
Author
Owner

@JakeSteam commented on GitHub (Jan 3, 2018):

Just a follow-up note for anyone who finds this looking for a simple transition guide: Step 2 in John's comment above is technically optional, will just give users a rough time.

@JakeSteam commented on GitHub (Jan 3, 2018): Just a follow-up note for anyone who finds this looking for a simple transition guide: Step 2 in John's comment above is technically optional, will just give users a rough time.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#52