diff --git a/Sources/LegacySQLiteStore.swift b/Sources/LegacySQLiteStore.swift index 27eed59..23daff9 100644 --- a/Sources/LegacySQLiteStore.swift +++ b/Sources/LegacySQLiteStore.swift @@ -86,6 +86,11 @@ public final class LegacySQLiteStore: LocalStorage { public var localStorageOptions: LocalStorageOptions + public func cs_finalizeStorageAndWait(soureModelHint: NSManagedObjectModel) throws { + + fatalError() + } + public func cs_eraseStorageAndWait(metadata: [String: Any], soureModelHint: NSManagedObjectModel?) throws { fatalError() diff --git a/Sources/SQLiteStore.swift b/Sources/SQLiteStore.swift index 42c6505..b50c29f 100644 --- a/Sources/SQLiteStore.swift +++ b/Sources/SQLiteStore.swift @@ -205,6 +205,22 @@ public final class SQLiteStore: LocalStorage { return storeOptions } + /** + Called by the `DataStack` to perform checkpoint operations on the storage. For `SQLiteStore`, this converts the database's WAL journaling mode to DELETE to force a checkpoint. + */ + public func cs_finalizeStorageAndWait(soureModelHint: NSManagedObjectModel) throws { + + _ = try withExtendedLifetime(NSPersistentStoreCoordinator(managedObjectModel: soureModelHint)) { (coordinator: NSPersistentStoreCoordinator) in + + try coordinator.addPersistentStore( + ofType: type(of: self).storeType, + configurationName: self.configuration, + at: fileURL, + options: [NSSQLitePragmasOption: ["journal_mode": "DELETE"]] + ) + } + } + /** 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. */ diff --git a/Sources/StorageInterface.swift b/Sources/StorageInterface.swift index 86de874..3ddaa0a 100644 --- a/Sources/StorageInterface.swift +++ b/Sources/StorageInterface.swift @@ -141,6 +141,11 @@ public protocol LocalStorage: StorageInterface { */ func dictionary(forOptions options: LocalStorageOptions) -> [AnyHashable: Any]? + /** + Called by the `DataStack` to perform checkpoint operations on the storage. (SQLite stores for example, can convert the database's WAL journaling mode to DELETE to force a checkpoint) + */ + func cs_finalizeStorageAndWait(soureModelHint: NSManagedObjectModel) throws + /** 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) */