diff --git a/backend/internal/store/migrations/0004_workout_taxonomy.sql b/backend/internal/store/migrations/0004_workout_taxonomy.sql new file mode 100644 index 0000000..5545a99 --- /dev/null +++ b/backend/internal/store/migrations/0004_workout_taxonomy.sql @@ -0,0 +1,17 @@ +-- The taxonomy is now a fixed, closed set (no more user-created "kinds"). +-- Any prior arbitrary kinds and their classification history are reset: +-- the concept they classified against no longer exists. +DELETE FROM kind_assignments; +DELETE FROM workout_kinds; + +-- Placeholder rule: distance is never negative, so this never matches. +-- Every activity starts in needs_review for every type until real rules +-- are tuned (a follow-up plan, not this migration). +INSERT INTO workout_kinds (name, description, color, rule_json, priority, is_active) VALUES + ('Easy Run', '', '#22c55e', '{"match":"all","conditions":[{"metric":"distance_meters","op":"<","value":0}]}', 0, 1), + ('Long Run', '', '#3b82f6', '{"match":"all","conditions":[{"metric":"distance_meters","op":"<","value":0}]}', 0, 1), + ('Threshold 30''', '', '#f59e0b', '{"match":"all","conditions":[{"metric":"distance_meters","op":"<","value":0}]}', 0, 1), + ('Threshold 60''', '', '#f59e0b', '{"match":"all","conditions":[{"metric":"distance_meters","op":"<","value":0}]}', 0, 1), + ('Tempo', '', '#eab308', '{"match":"all","conditions":[{"metric":"distance_meters","op":"<","value":0}]}', 0, 1), + ('Interval', '', '#ef4444', '{"match":"all","conditions":[{"metric":"distance_meters","op":"<","value":0}]}', 0, 1), + ('MAS Test', '', '#a855f7', '{"match":"all","conditions":[{"metric":"distance_meters","op":"<","value":0}]}', 0, 1); diff --git a/backend/internal/store/store_test.go b/backend/internal/store/store_test.go index 4d548cf..b827df3 100644 --- a/backend/internal/store/store_test.go +++ b/backend/internal/store/store_test.go @@ -96,7 +96,7 @@ func TestKindAssignment_AppendOnlyHistoryAndCurrentView(t *testing.T) { } kindID, err := db.CreateWorkoutKind(ctx, WorkoutKind{ - Name: "Tempo", + Name: "Test Assignment Custom", RuleJSON: `{"match":"all","conditions":[]}`, IsActive: true, }) diff --git a/backend/internal/store/workoutkinds_taxonomy_test.go b/backend/internal/store/workoutkinds_taxonomy_test.go new file mode 100644 index 0000000..cc784df --- /dev/null +++ b/backend/internal/store/workoutkinds_taxonomy_test.go @@ -0,0 +1,36 @@ +package store + +import ( + "context" + "testing" +) + +func TestWorkoutTaxonomy_SeededWithSevenFixedTypes(t *testing.T) { + db := openTestDB(t) + ctx := context.Background() + + kinds, err := db.ListWorkoutKinds(ctx, true) + if err != nil { + t.Fatalf("ListWorkoutKinds: %v", err) + } + if len(kinds) != 7 { + t.Fatalf("expected 7 seeded workout kinds, got %d: %+v", len(kinds), kinds) + } + + wantNames := map[string]bool{ + "Easy Run": false, "Long Run": false, "Threshold 30'": false, "Threshold 60'": false, + "Tempo": false, "Interval": false, "MAS Test": false, + } + for _, k := range kinds { + if _, ok := wantNames[k.Name]; !ok { + t.Errorf("unexpected seeded kind name %q", k.Name) + continue + } + wantNames[k.Name] = true + } + for name, found := range wantNames { + if !found { + t.Errorf("expected seeded kind %q, not found", name) + } + } +}