Skip to content

Commit e48cf1b

Browse files
committed
Simplified WAL checkpointing
1 parent 87fa949 commit e48cf1b

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

CoreDataMigration-Example/CoreData/Migration/CoreDataMigrationModel.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ class CoreDataMigrationModel {
169169

170170
return [step] + nextStep
171171
}
172+
173+
// MARK: - Metadata
174+
175+
static func migrationModelCompatibleWithStoreMetadata(_ metadata: [String : Any]) -> CoreDataMigrationModel? {
176+
let compatibleMigrationModel = CoreDataMigrationModel.all.first {
177+
$0.managedObjectModel().isConfiguration(withName: nil, compatibleWithStoreMetadata: metadata)
178+
}
179+
180+
return compatibleMigrationModel
181+
}
172182
}
173183

174184
// MARK: - Source

CoreDataMigration-Example/CoreData/Migration/CoreDataMigrator.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,12 @@ class CoreDataMigrator {
8080
// MARK: - WAL
8181

8282
func forceWALCheckpointingForStore(at storeURL: URL) {
83-
guard let metadata = NSPersistentStoreCoordinator.metadata(at: storeURL) else {
84-
return
85-
}
86-
87-
let migrationVersionModel = CoreDataMigrationModel.all.first {
88-
$0.managedObjectModel().isConfiguration(withName: nil, compatibleWithStoreMetadata: metadata)
89-
}
90-
91-
guard let currentCoreDataStoreMigrationVersionModel = migrationVersionModel else {
83+
guard let metadata = NSPersistentStoreCoordinator.metadata(at: storeURL), let migrationModel = CoreDataMigrationModel.migrationModelCompatibleWithStoreMetadata(metadata) else {
9284
return
9385
}
9486

9587
do {
96-
let model = currentCoreDataStoreMigrationVersionModel.managedObjectModel()
88+
let model = migrationModel.managedObjectModel()
9789
let persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: model)
9890

9991
let options = [NSSQLitePragmasOption: ["journal_mode": "DELETE"]]

0 commit comments

Comments
 (0)