mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-17 23:13:52 +01:00
fix RecreateStoreOnModelMismatch option not working when an existing xcdatamodel gets updated without adding a new version
This commit is contained in:
@@ -263,7 +263,7 @@ public final class DataStack {
|
||||
URL: fileURL,
|
||||
options: storeOptions
|
||||
)
|
||||
try _ = self.model[metadata].flatMap(storage.eraseStorageAndWait)
|
||||
_ = try storage.eraseStorageAndWait(soureModel: self.model[metadata])
|
||||
|
||||
try self.createPersistentStoreFromStorage(
|
||||
storage,
|
||||
@@ -359,7 +359,7 @@ public final class DataStack {
|
||||
URL: cacheFileURL,
|
||||
options: storeOptions
|
||||
)
|
||||
try _ = self.model[metadata].flatMap(storage.eraseStorageAndWait)
|
||||
_ = try storage.eraseStorageAndWait(soureModel: self.model[metadata])
|
||||
|
||||
try self.createPersistentStoreFromStorage(
|
||||
storage,
|
||||
|
||||
@@ -424,11 +424,19 @@ public class ICloudStore: CloudStorage {
|
||||
/**
|
||||
Called by the `DataStack` to perform actual deletion of the store file from disk. Do not call directly! The `sourceModel` argument is a hint for the existing store's model version. For `SQLiteStore`, this converts the database's WAL journaling mode to DELETE before deleting the file.
|
||||
*/
|
||||
public func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel) throws {
|
||||
public func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel?) throws {
|
||||
|
||||
// TODO: check if attached to persistent store
|
||||
|
||||
let cacheFileURL = self.cacheFileURL
|
||||
guard let soureModel = soureModel else {
|
||||
|
||||
let fileManager = NSFileManager.defaultManager()
|
||||
try fileManager.removeItemAtURL(cacheFileURL)
|
||||
_ = try fileManager.removeItemAtPath("\(cacheFileURL.absoluteString)-wal")
|
||||
_ = try fileManager.removeItemAtPath("\(cacheFileURL.absoluteString)-shm")
|
||||
return
|
||||
}
|
||||
try cs_autoreleasepool {
|
||||
|
||||
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
|
||||
|
||||
@@ -165,11 +165,19 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore {
|
||||
/**
|
||||
Called by the `DataStack` to perform actual deletion of the store file from disk. Do not call directly! The `sourceModel` argument is a hint for the existing store's model version. For `SQLiteStore`, this converts the database's WAL journaling mode to DELETE before deleting the file.
|
||||
*/
|
||||
public func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel) throws {
|
||||
public func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel?) throws {
|
||||
|
||||
// TODO: check if attached to persistent store
|
||||
|
||||
let fileURL = self.fileURL
|
||||
guard let soureModel = soureModel else {
|
||||
|
||||
let fileManager = NSFileManager.defaultManager()
|
||||
try fileManager.removeItemAtURL(fileURL)
|
||||
_ = try fileManager.removeItemAtPath("\(fileURL.absoluteString)-wal")
|
||||
_ = try fileManager.removeItemAtPath("\(fileURL.absoluteString)-shm")
|
||||
return
|
||||
}
|
||||
try cs_autoreleasepool {
|
||||
|
||||
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
|
||||
|
||||
@@ -162,11 +162,19 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore {
|
||||
/**
|
||||
Called by the `DataStack` to perform actual deletion of the store file from disk. Do not call directly! The `sourceModel` argument is a hint for the existing store's model version. For `SQLiteStore`, this converts the database's WAL journaling mode to DELETE before deleting the file.
|
||||
*/
|
||||
public func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel) throws {
|
||||
public func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel?) throws {
|
||||
|
||||
// TODO: check if attached to persistent store
|
||||
|
||||
let fileURL = self.fileURL
|
||||
guard let soureModel = soureModel else {
|
||||
|
||||
let fileManager = NSFileManager.defaultManager()
|
||||
try fileManager.removeItemAtURL(fileURL)
|
||||
_ = try fileManager.removeItemAtPath("\(fileURL.absoluteString)-wal")
|
||||
_ = try fileManager.removeItemAtPath("\(fileURL.absoluteString)-shm")
|
||||
return
|
||||
}
|
||||
try cs_autoreleasepool {
|
||||
|
||||
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
|
||||
|
||||
@@ -158,7 +158,7 @@ public protocol LocalStorage: StorageInterface {
|
||||
/**
|
||||
Called by the `DataStack` to perform actual deletion of the store file from disk. **Do not call directly!** The `sourceModel` argument is a hint for the existing store's model version. Implementers can use the `sourceModel` to perform necessary store operations. (SQLite stores for example, can convert WAL journaling mode to DELETE before deleting)
|
||||
*/
|
||||
func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel) throws
|
||||
func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel?) throws
|
||||
}
|
||||
|
||||
internal extension LocalStorage {
|
||||
@@ -242,7 +242,7 @@ public protocol CloudStorage: StorageInterface {
|
||||
/**
|
||||
Called by the `DataStack` to perform actual deletion of the store file from disk. **Do not call directly!** The `sourceModel` argument is a hint for the existing store's model version. Implementers can use the `sourceModel` to perform necessary store operations. (Cloud stores for example, can set the NSPersistentStoreRemoveUbiquitousMetadataOption option before deleting)
|
||||
*/
|
||||
func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel) throws
|
||||
func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel?) throws
|
||||
}
|
||||
|
||||
internal extension CloudStorage {
|
||||
|
||||
Reference in New Issue
Block a user