-
Notifications
You must be signed in to change notification settings - Fork 121
[Core Data] Make new Core Data migration path. Remove models below 30 #15987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iamgabrielma
merged 19 commits into
trunk
from
task/WOOMOB-1006-remove-cd-models-1-to-30
Aug 12, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5466c91
Create CoreDataMigratorUtils and tests
iamgabrielma b23e5e9
check for destroyPersistentStore. Extract utils to own file
iamgabrielma 8804c6c
lint
iamgabrielma d72dd96
update oldest supported DB threshold to 30
iamgabrielma 1bd0ede
remove models 1 to 29
iamgabrielma 5f4e8fe
updat ManagedObjectModelsInventoryTests
iamgabrielma 67ba1af
remove mapping models below 30 and related migration tests
iamgabrielma 5439a99
lint
iamgabrielma 65144c7
update docs
iamgabrielma 91088d0
update tests that rely on state from removed models
iamgabrielma 41ffc50
Merge branch 'trunk' into task/WOOMOB-1006-remove-cd-models-1-to-30
iamgabrielma d1d463b
remove duplication due to wrapper
iamgabrielma 66da437
update var names to match model name
iamgabrielma dc6431f
Restore test case when when migrating to the same model version
iamgabrielma 6080964
simplify shouldDestroyPersistentStore check
iamgabrielma 08de9bf
update model names to fit their number
iamgabrielma f544d68
lint
iamgabrielma 35a6fd2
Update Modules/Sources/Storage/CoreData/CoreDataIterativeMigrator.swift
iamgabrielma 644059f
Merge branch 'trunk' into task/WOOMOB-1006-remove-cd-models-1-to-30
iamgabrielma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Modules/Sources/Storage/CoreData/CoreDataMigratorUtils.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import CoreData | ||
|
|
||
| struct CoreDataMigratorUtils { | ||
| /// Finds the ModelVersion that corresponds to the given NSManagedObjectModel | ||
| static func findSourceVersion(for sourceModel: NSManagedObjectModel, | ||
| in modelsInventory: ManagedObjectModelsInventory) -> ManagedObjectModelsInventory.ModelVersion? { | ||
| do { | ||
| let allModels = try modelsInventory.models(for: modelsInventory.versions) | ||
| for (index, model) in allModels.enumerated() { | ||
| if model.isEqual(sourceModel) { | ||
| return modelsInventory.versions[index] | ||
| } | ||
| } | ||
| } catch { | ||
| DDLogError("[CoreDataMigratorUtils] Error loading models for version detection: \(error)") | ||
| } | ||
| return nil | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Trying to ensure that it can return a deleted version. When I printed out
modelsInventory.versionswhen launching the app inCoreDataManager.migrateDataModelIfNecessary, the versions are 30+; andmodelsInventory.models(for:)maps the versions. Can a deleted version be returned, and thus be matched to a source model?If it's not possible, I think the code can be simplified by not having to compare with the oldest model version constant, since the available models in
modelsInventory.versionsalready imply the oldest version. If it makes sense,shouldDestroyPersistentStorecan return true when a model version cannot be found, when this function returns nil.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very good catch, and excellent suggestion. We can just rely on the existence of the model rather than having to check the version, which simplifies the logic and allows us to remove some. Updated here: 6080964