Add machine comfort settings and tighten the document schemas

Machine-based exercises now carry ordered name/value comfort settings
(seat height, back-rest position, ...) on both ExerciseDocument and, as a
plan-time snapshot, WorkoutLogDocument — the optional array doubles as the
machine flag. Editable from the exercise editor's new Machine section and
from the workout row's settings sheet, whose mid-workout edits write back
to the originating split (workout saved first, so seed clone-on-edit
repointing can't clobber the log edit).

Schema tightening rides the same rev: splits bump to v2 (weight-reminder
fields and the unused exercise category removed), workouts to v3 (the
derived `completed` flag removed; status is the single source). Starter
seeds regenerated at v2 with unchanged ULIDs; SwiftData cache schema
bumped to rebuild. SCHEMA.md documents the shapes.

Claude-Session: https://claude.ai/code/session_01LEoff8bXGBS83tK1c55Mf7
This commit is contained in:
2026-07-06 16:29:44 -04:00
parent fce8fa4c17
commit 2c1e4759ae
33 changed files with 1132 additions and 586 deletions
+24 -18
View File
@@ -38,6 +38,11 @@ func deterministicULID(label: String) -> String {
// MARK: - Document shapes (field names must mirror Shared/Model/Documents.swift)
struct MachineSetting: Codable {
var name: String
var value: String
}
struct ExerciseDocument: Codable {
var id: String
var name: String
@@ -47,9 +52,7 @@ struct ExerciseDocument: Codable {
var weight: Int
var loadType: Int
var durationSeconds: Int
var weightLastUpdated: Date?
var weightReminderWeeks: Int
var category: Int?
var machineSettings: [MachineSetting]? = nil
}
struct SplitDocument: Codable {
@@ -67,30 +70,34 @@ struct SplitDocument: Codable {
// MARK: - Seed data (canonical source for Workouts/Resources/StarterSplits/*.json)
struct Ex { let name: String; var weight = 0; var sets = 4; var reps = 10; var load = 1; var dur = 0; var cat = 0 }
struct Ex { let name: String; var weight = 0; var sets = 4; var reps = 10; var load = 1; var dur = 0 }
struct Sp { let name: String; let color: String; let icon: String; let activity: Int; let ex: [Ex] }
let seeds: [Sp] = [
Sp(name: "Upper Body", color: "blue", icon: "figure.strengthtraining.traditional", activity: 0, ex: [
Ex(name: "Lat Pull Down", weight: 110),
Ex(name: "Tricep Press", weight: 100),
Ex(name: "Chest Press", weight: 40),
Ex(name: "Seated Row", weight: 90),
Ex(name: "Shoulder Press", weight: 40),
Ex(name: "Chest Press", weight: 40),
Ex(name: "Tricep Press", weight: 100),
Ex(name: "Arm Curl", weight: 40),
]),
Sp(name: "Core", color: "orange", icon: "figure.core.training", activity: 3, ex: [
Ex(name: "Abdominal", weight: 0),
Ex(name: "Rotary", weight: 0),
Ex(name: "Abdominal", weight: 40),
Ex(name: "Rotary", weight: 40),
]),
Sp(name: "Lower Body", color: "green", icon: "figure.run", activity: 0, ex: [
Ex(name: "Abductor", weight: 140),
Ex(name: "Adductor", weight: 140),
Ex(name: "Leg Press", weight: 160),
Ex(name: "Leg Curl", weight: 70),
Ex(name: "Leg Press", weight: 140),
Ex(name: "Leg Curl", weight: 40),
Ex(name: "Leg Extension", weight: 80),
Ex(name: "Abductor", weight: 130),
Ex(name: "Adductor", weight: 130),
Ex(name: "Calfs", weight: 100),
]),
Sp(name: "Bodyweight Core", color: "teal", icon: "figure.core.training", activity: 3, ex: [
Ex(name: "Cat-Cow", sets: 1, reps: 10, load: 0, cat: 1),
Ex(name: "Dead Bug", sets: 1, reps: 8, load: 0, cat: 1),
Ex(name: "Bird Dog", sets: 1, reps: 8, load: 0, cat: 1),
Ex(name: "Cat-Cow", sets: 1, reps: 10, load: 0),
Ex(name: "Dead Bug", sets: 1, reps: 8, load: 0),
Ex(name: "Bird Dog", sets: 1, reps: 8, load: 0),
Ex(name: "Plank", sets: 3, reps: 0, load: 2, dur: 45),
Ex(name: "Hollow Body Hold", sets: 3, reps: 0, load: 2, dur: 30),
Ex(name: "Side Plank", sets: 3, reps: 0, load: 2, dur: 30),
@@ -113,7 +120,7 @@ try FileManager.default.createDirectory(at: outDir, withIntermediateDirectories:
for (order, sp) in seeds.enumerated() {
let slug = sp.name.lowercased().replacingOccurrences(of: " ", with: "-")
let doc = SplitDocument(
schemaVersion: 1,
schemaVersion: 2,
id: deterministicULID(label: "starter.\(slug)"),
name: sp.name, color: sp.color, systemImage: sp.icon, order: order,
createdAt: fixedDate, updatedAt: fixedDate,
@@ -121,8 +128,7 @@ for (order, sp) in seeds.enumerated() {
ExerciseDocument(
id: deterministicULID(label: "starter.\(slug).ex\(idx)"),
name: e.name, order: idx, sets: e.sets, reps: e.reps, weight: e.weight,
loadType: e.load, durationSeconds: e.dur, weightLastUpdated: nil,
weightReminderWeeks: 2, category: e.cat)
loadType: e.load, durationSeconds: e.dur)
},
activityType: sp.activity)
let data = try encoder.encode(doc)