From 0cf4d303e48d3a62714939c39c054a7b04031d8b Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 2 Jun 2017 11:32:48 +0900 Subject: [PATCH 1/3] 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: From c0fc57d10cdcd2afd42b3e3fb39e1ad6d0997acc Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 2 Jun 2017 11:34:04 +0900 Subject: [PATCH 2/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 004792b..bc337f7 100644 --- a/README.md +++ b/README.md @@ -460,7 +460,7 @@ CoreStore.defaultStack = DataStack( ) ``` -**`CoreStoreSchema`-based model versions with progressive migration +**`CoreStoreSchema`-based model versions with progressive migration** ```swift typealias Animal = V2.Animal typealias Dog = V2.Dog From ad9520abbca74529c162987c01415515d2e51429 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 2 Jun 2017 13:24:15 +0900 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bc337f7..83203bc 100644 --- a/README.md +++ b/README.md @@ -498,7 +498,7 @@ CoreStore.defaultStack = DataStack( ] ), CoreStoreSchema( - modelVersion: "V1", + modelVersion: "V2", entities: [ Entity("Animal", isAbstract: true), Entity("Dog"),