35 lines
1.1 KiB
Swift
35 lines
1.1 KiB
Swift
import SwiftData
|
|
import Foundation
|
|
|
|
struct WorkoutsMigrationPlan: SchemaMigrationPlan {
|
|
static var schemas: [VersionedSchema.Type] = SchemaVersion.schemas
|
|
|
|
static var stages: [MigrationStage] = [
|
|
MigrationStage.custom(
|
|
fromVersion: SchemaV1.self,
|
|
toVersion: SchemaV1.self,
|
|
willMigrate: { context in
|
|
print("migrating from v1 to v1")
|
|
let workouts = try? context.fetch(FetchDescriptor<Workout>())
|
|
workouts?.forEach { workout in
|
|
if let status = workout.status {
|
|
|
|
} else {
|
|
workout.status = .notStarted
|
|
}
|
|
|
|
// if let endDate = workout.end {
|
|
//
|
|
// } else {
|
|
// workout.end = Date()
|
|
// }
|
|
workout.end = Date()
|
|
}
|
|
},
|
|
didMigrate: { _ in
|
|
// No additional actions needed after migration
|
|
}
|
|
)
|
|
]
|
|
}
|