The images below are displaying the only difference between the two schemas:
This is the migration plan:
enum ImpactMigrationPlan: SchemaMigrationPlan {
static var schemas: [any VersionedSchema.Type] {
[
ImpactSchemaV1.self,
ImpactSchemaV1_1.self,
ImpactSchemaV2.self,
ImpactSchemaV3.self,
ImpactSchemaV4.self,
ImpactSchemaV5.self,
ImpactSchemaV6.self,
ImpactSchemaV7.self,
ImpactSchemaV8.self
]
}
static var stages: [MigrationStage] {
[migrateV1toV1_1, migrateV1_1toV2, migrateV2toV3, migrateV3toV4, migrateV4toV5, migrateV5toV6, migrateV6toV7, migrateV7toV8]
}
....
static let migrateV7toV8 = MigrationStage.custom(
fromVersion: ImpactSchemaV7.self,
toVersion: ImpactSchemaV8.self,
willMigrate: { context in
Logger.application.info("Will migrate to stage 8")
}, didMigrate: { context in
Logger.application.info("Did migrate to stage 8")
})
And this is how the model container is built in the app:
var modelContainer: ModelContainer = {
let modelContainer: ModelContainer
let schema = Schema(versionedSchema: ImpactSchemaV8.self)
let config = ModelConfiguration(cloudKitDatabase: .none)
do {
modelContainer = try ModelContainer(
for: schema,
migrationPlan: ImpactMigrationPlan.self,
configurations: config
)
} catch {
Logger().error("Error creating model container: \(error.localizedDescription)")
preconditionFailure("Failed to create model container")
}
return modelContainer
}()