@@ -73,27 +73,21 @@ fileprivate let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, catego
73
73
NSInferMappingModelAutomaticallyOption: true ,
74
74
NSMigratePersistentStoresAutomaticallyOption: true
75
75
]
76
- // migrate legacy stores when possible; legacyStoreFile
77
- // XXX: Error handling sufficient here?
78
- let oldURL = SBAppDelegate . legacyStoreFileName
76
+ // check if the model needs a migration; we let Core Data do lightweight migrations and let us handle heavyweight,
77
+ // but we should probably invalidate object IDs in the defaults DB. migration should handle OIDs in the store.
78
+ // if we were doing the migration manually we could try to convert the ID, but we don't have this control with
79
+ // NSMigratePersistentStoresAutomaticallyOption.
79
80
let newURL = SBAppDelegate . storeFileName
80
- if FileManager . default. fileExists ( atPath: oldURL. path) && !FileManager. default. fileExists ( atPath: newURL. path) {
81
- let oldStore = try ! self . persistentStoreCoordinator. addPersistentStore ( type: . xml,
82
- configuration: nil ,
83
- at: oldURL,
84
- options: storeOpts)
85
- // It's OK to ignore the return value, since it mutates the coordinator to include it
86
- _ = try ! self . persistentStoreCoordinator. migratePersistentStore ( oldStore,
87
- to: newURL,
88
- options: storeOpts,
89
- type: . sqlite)
90
- } else {
91
- // usual path, we aren't converting, but just using modern store
92
- _ = try ! self . persistentStoreCoordinator. addPersistentStore ( type: . sqlite,
93
- configuration: nil ,
94
- at: newURL,
95
- options: storeOpts)
81
+ if let metadata = try ? NSPersistentStoreCoordinator . metadataForPersistentStore ( type: . sqlite, at: newURL) ,
82
+ !self . managedObjectModel. isConfiguration ( withName: nil , compatibleWithStoreMetadata: metadata) {
83
+ // SBDatabaseController defaults to local music for now
84
+ UserDefaults . standard. removeObject ( forKey: " LastViewedResource " )
96
85
}
86
+ // we no longer migrate from Submariner 1.x stores. use 3.1.1 or older first beforehand
87
+ _ = try ! self . persistentStoreCoordinator. addPersistentStore ( type: . sqlite,
88
+ configuration: nil ,
89
+ at: newURL,
90
+ options: storeOpts)
97
91
98
92
// #MARK: Init Core Data (managed object store)
99
93
// must be main queue for SwiftUI
@@ -160,12 +154,6 @@ fileprivate let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, catego
160
154
161
155
// #MARK: - Application Files/Directories
162
156
163
- static var legacyStoreFileName : URL {
164
- let libraryURL = FileManager . default. urls ( for: . libraryDirectory, in: . userDomainMask) . last!
165
- let storeURL = libraryURL. appendingPathComponent ( " Submariner.storedata " )
166
- return storeURL
167
- }
168
-
169
157
@objc static var musicDirectory : URL {
170
158
let path = FileManager . default. urls ( for: . musicDirectory, in: . userDomainMask) . last!. appendingPathComponent ( " Submariner/Music " )
171
159
if !FileManager. default. fileExists ( atPath: path. path) {
0 commit comments