From 0cf4d303e48d3a62714939c39c054a7b04031d8b Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 2 Jun 2017 11:32:48 +0900 Subject: [PATCH] Added README sample on how to version CoreStoreObjects --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/README.md b/README.md index e87be33..004792b 100644 --- a/README.md +++ b/README.md @@ -460,6 +460,55 @@ CoreStore.defaultStack = DataStack( ) ``` +**`CoreStoreSchema`-based model versions with progressive migration +```swift +typealias Animal = V2.Animal +typealias Dog = V2.Dog +typealias Person = V2.Person +enum V2 { + class Animal: CoreStoreObject { + // ... + } + class Dog: Animal { + // ... + } + class Person: CoreStoreObject { + // ... + } +} +enum V1 { + class Animal: CoreStoreObject { + // ... + } + class Dog: Animal { + // ... + } + class Person: CoreStoreObject { + // ... + } +} + +CoreStore.defaultStack = DataStack( + CoreStoreSchema( + modelVersion: "V1", + entities: [ + Entity("Animal", isAbstract: true), + Entity("Dog"), + Entity("Person") + ] + ), + CoreStoreSchema( + modelVersion: "V1", + entities: [ + Entity("Animal", isAbstract: true), + Entity("Dog"), + Entity("Person") + ] + ), + migrationChain: ["V1", "V2"] +) +``` + ### Starting migrations We have seen `addStorageAndWait(...)` used to initialize our persistent store. As the method name's *~AndWait* suffix suggests though, this method blocks so it should not do long tasks such as store migrations. In fact CoreStore will only attempt a synchronous **lightweight** migration if you explicitly provide the `.allowSynchronousLightweightMigration` option: