The April plan for HabitTracker starts with a 5 km run. The app needed to remember the date and the distance. A habit named Running might have a row for Monday and another for Tuesday. In the database there’s a unique index on the pair (HabitId, Date). That gives the app one quantity to update when I change Monday’s entry. The original plan · The habit log index
Now suppose I squat three sets in the same session. The first is a warmup. The next two are at the same weight and one has fewer reps. Grouping by exercise and date would put all three under the same key. The repeated value is meaningful here. If I pick a row from history next week, I want to know which set I picked and how to put those plates back.
Give the new behavior its own schema
The strength migration creates WorkoutSessions and WorkoutSets. The session owns the date and completion time. The set owns its exercise, repetitions, and the original plate configuration. A workout date has a regular index for finding sessions. A set has its own ID and a separate unique client ID so a retry can be recognized without treating two intentional sets as duplicates. The strength migration
That choice let the WPF client keep the existing HTTP boundary. The client could add a workout editor and history view while the API continued to serve the habit screens against the old tables. At startup, the API applies migrations before serving requests. The new version can start against a database already in use and add the schema that it needs. The new tables also have their own lifetime. Deleting a session cascades to its sets. API startup · Workout relationships
Bring an old database to the test
A green test against a fresh database would have told me that both migrations work from scratch. The test I wanted for this change had to start further along. UpgradePreservesExistingHabitData opens a temporary SQLite file, explicitly stops at the April migration, and saves a running habit there. It then starts the new API against that same file. The test asks the server to do three things.
- List habits and return
Original running habit. - Create a workout.
- Return seven statistics points from the old habit endpoint with
range=week.
The first request makes the upgrade observable from a client’s point of view. The second forces the new schema to do real work. The third follows the old record through an additional API path. The fixture inserts a habit definition and checks the statistics endpoint’s shape. An upgrade check for existing daily quantities would need to insert a daily log and assert on the value too. The migration test
Where the change ends
One deployment choice follows from the migration itself. The Down method drops the workout tables. Reversing the schema after logging new workouts would discard those rows. The test gives me confidence in upgrading the SQLite file while preserving the existing habit behavior. A data-preserving rollback would need a separate plan. The migration’s reverse operation
The desktop walkthrough adds a second test of whether the change is finished. Log a set, restart the client, find the unfinished workout, complete it, and pull the setup back into the editor. Opening history after a restart exercises the same boundary that motivated the schema change. Daily Habits can still answer what I recorded on Monday. The workout can answer which set I selected and how to load the bar for it. The desktop workflow test · The Windows demo