fix RecreateStoreOnModelMismatch option not working when an existing xcdatamodel gets updated without adding a new version

This commit is contained in:
John Rommel Estropia
2016-09-10 22:51:33 +09:00
parent 4a34012d58
commit f99d3cc21a
9 changed files with 36 additions and 12 deletions

View File

@@ -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,

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 {