import SwiftData struct WorkoutsMigrationPlan: SchemaMigrationPlan { static var schemas: [VersionedSchema.Type] = [ SchemaV1.self, SchemaV2.self ] static var stages: [MigrationStage] = [ // Migration from V1 to V2: Add status field to WorkoutLog MigrationStage.custom( fromVersion: SchemaV1.self, toVersion: SchemaV2.self, willMigrate: { context in // Get all WorkoutLog instances let workoutLogs = try? context.fetch(FetchDescriptor()) // Update each WorkoutLog with appropriate status based on completed flag workoutLogs?.forEach { workoutLog in // If completed is true, set status to .completed, otherwise set to .notStarted workoutLog.status = workoutLog.completed ? WorkoutStatus.completed : WorkoutStatus.notStarted } }, didMigrate: { _ in // No additional actions needed after migration } ) ] }