mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-30 06:11:50 +02:00
fix RecreateStoreOnModelMismatch option not working when an existing xcdatamodel gets updated without adding a new version
This commit is contained in:
@@ -308,7 +308,7 @@ public protocol LocalStorage: StorageInterface {
|
|||||||
var mappingModelBundles: [NSBundle] { get }
|
var mappingModelBundles: [NSBundle] { get }
|
||||||
var localStorageOptions: LocalStorageOptions { get }
|
var localStorageOptions: LocalStorageOptions { get }
|
||||||
func storeOptionsForOptions(options: LocalStorageOptions) -> [String: AnyObject]?
|
func storeOptionsForOptions(options: LocalStorageOptions) -> [String: AnyObject]?
|
||||||
func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel) throws
|
func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel?) throws
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
If you have custom `NSIncrementalStore` or `NSAtomicStore` subclasses, you can implement this protocol and use it similarly to `SQLiteStore`.
|
If you have custom `NSIncrementalStore` or `NSAtomicStore` subclasses, you can implement this protocol and use it similarly to `SQLiteStore`.
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ public extension DataStack {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
try _ = self.model[metadata].flatMap(storage.eraseStorageAndWait)
|
_ = try storage.eraseStorageAndWait(soureModel: self.model[metadata])
|
||||||
try self.addStorageAndWait(storage)
|
try self.addStorageAndWait(storage)
|
||||||
|
|
||||||
GCDQueue.Main.async {
|
GCDQueue.Main.async {
|
||||||
@@ -388,7 +388,7 @@ public extension DataStack {
|
|||||||
URL: cacheFileURL,
|
URL: cacheFileURL,
|
||||||
options: storeOptions
|
options: storeOptions
|
||||||
)
|
)
|
||||||
try _ = self.model[metadata].flatMap(storage.eraseStorageAndWait)
|
_ = try storage.eraseStorageAndWait(soureModel: self.model[metadata])
|
||||||
|
|
||||||
try self.createPersistentStoreFromStorage(
|
try self.createPersistentStoreFromStorage(
|
||||||
storage,
|
storage,
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreObjectiveCT
|
|||||||
Called by the `CSDataStack` 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 `CSSQLiteStore`, this converts the database's WAL journaling mode to DELETE before deleting the file.
|
Called by the `CSDataStack` 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 `CSSQLiteStore`, this converts the database's WAL journaling mode to DELETE before deleting the file.
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
public func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel, error: NSErrorPointer) -> Bool {
|
public func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel?, error: NSErrorPointer) -> Bool {
|
||||||
|
|
||||||
return bridge(error) {
|
return bridge(error) {
|
||||||
|
|
||||||
|
|||||||
@@ -121,5 +121,5 @@ public protocol CSLocalStorage: CSStorageInterface {
|
|||||||
Called by the `CSDataStack` 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)
|
Called by the `CSDataStack` 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)
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel, error: NSErrorPointer) -> Bool
|
func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel?, error: NSErrorPointer) -> Bool
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ public final class DataStack {
|
|||||||
URL: fileURL,
|
URL: fileURL,
|
||||||
options: storeOptions
|
options: storeOptions
|
||||||
)
|
)
|
||||||
try _ = self.model[metadata].flatMap(storage.eraseStorageAndWait)
|
_ = try storage.eraseStorageAndWait(soureModel: self.model[metadata])
|
||||||
|
|
||||||
try self.createPersistentStoreFromStorage(
|
try self.createPersistentStoreFromStorage(
|
||||||
storage,
|
storage,
|
||||||
@@ -359,7 +359,7 @@ public final class DataStack {
|
|||||||
URL: cacheFileURL,
|
URL: cacheFileURL,
|
||||||
options: storeOptions
|
options: storeOptions
|
||||||
)
|
)
|
||||||
try _ = self.model[metadata].flatMap(storage.eraseStorageAndWait)
|
_ = try storage.eraseStorageAndWait(soureModel: self.model[metadata])
|
||||||
|
|
||||||
try self.createPersistentStoreFromStorage(
|
try self.createPersistentStoreFromStorage(
|
||||||
storage,
|
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.
|
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
|
// TODO: check if attached to persistent store
|
||||||
|
|
||||||
let cacheFileURL = self.cacheFileURL
|
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 {
|
try cs_autoreleasepool {
|
||||||
|
|
||||||
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
|
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.
|
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
|
// TODO: check if attached to persistent store
|
||||||
|
|
||||||
let fileURL = self.fileURL
|
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 {
|
try cs_autoreleasepool {
|
||||||
|
|
||||||
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
|
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.
|
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
|
// TODO: check if attached to persistent store
|
||||||
|
|
||||||
let fileURL = self.fileURL
|
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 {
|
try cs_autoreleasepool {
|
||||||
|
|
||||||
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
|
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)
|
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 {
|
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)
|
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 {
|
internal extension CloudStorage {
|
||||||
|
|||||||
Reference in New Issue
Block a user