wip
This commit is contained in:
@ -2,10 +2,28 @@ import SwiftData
|
||||
|
||||
struct WorkoutsMigrationPlan: SchemaMigrationPlan {
|
||||
static var schemas: [VersionedSchema.Type] = [
|
||||
SchemaV1.self
|
||||
SchemaV1.self,
|
||||
SchemaV2.self
|
||||
]
|
||||
|
||||
static var stages: [MigrationStage] = [
|
||||
// Add migration stages here in the future
|
||||
// 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<WorkoutLog>())
|
||||
|
||||
// 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
|
||||
}
|
||||
)
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user