This commit is contained in:
2025-07-17 07:04:38 -04:00
parent 2d0e327334
commit f63bb0ba41
25 changed files with 592 additions and 92 deletions

View File

@ -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
}
)
]
}