Skip to content

feat(conf): persist /config/ settings across pod restarts (migration v10)#63

Merged
rwlove merged 3 commits into
mainfrom
feat/persist-config
Jul 2, 2026
Merged

feat(conf): persist /config/ settings across pod restarts (migration v10)#63
rwlove merged 3 commits into
mainfrom
feat/persist-config

Conversation

@rwlove

@rwlove rwlove commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

Every setting the /config/ page or PUT /api/config wrote was stored only in the process's atomic Conf holder, so a pod restart silently reset color / pagestep / frequency_days / display_days / autofill / cv_autolog back to the env-var defaults. Users who flipped CV auto-log on had it revert to off on every v0.0.102 rollout.

  • Migration v10: single-row app_config table (CHECK (id = 1))
  • Store gains GetAppConfig / SaveAppConfig (behind store.Store interface)
  • Startup: env vars → overlay persisted row (when present) → conf.Set
  • Save handlers UPSERT after conf.Set; persist failure is a soft-fail so a broken DB doesn't break the UI
  • Not persisted: Pushover creds (env-only), NodePath (env-only)

Migration checklist (per CLAUDE.md)

  • Version 10 appended; sequence 1..10 gap-free; no prior entry modified
  • Fresh empty DB: all 10 apply; schema_version has 10 rows
  • v9 (prod dump) → v10: only v10 applies; row counts unchanged (sets 796, exercises 30, weight 92, health_record 629)
  • Idempotency: re-run reports "schema is up to date"
  • No data loss: additive migration
  • Round-trip: POST /config/ color=light pagestep=25 cvautolog=on, restart with original env, config still reads light/25/true; startup logs loaded persisted config
  • Next pump-v tag: bump to v0.0.103

Test plan

  • go build && go vet && go test -race ./... — 47 tests pass across web/api/treadmill
  • 2 new tests: form save UPSERTS to store, persist failure is soft-fail (redirect still 302)
  • Live restart round-trip against prod dump

🤖 Generated with Claude Code

rwlove and others added 3 commits July 2, 2026 07:51
Adds coverage for functions that took no store/network/time-sensitive
inputs and were previously untested (only healthstats and treadmill
session detector had tests).

- internal/web/colors_test.go: hslToHex anchors (red/green/blue/black/
  white/grey) + always-well-formed sweep, nextExerciseColor determinism
  and small-N distinctness, needsColorBackfill/collectColors edges
- internal/web/index_test.go: buildGroupList first-seen ordering (with
  empty-group edge case), sortExsByFrequency ordering + Place tiebreak
  + window respect
- internal/api/health_test.go: parseHealthEnvelope metadata stripping,
  per-type counts, malformed root, dropped-untimeable records;
  healthRecordFromElement scalar mapping + Extra preservation +
  timestamp stripping from Extra + unmapped-type fallback via
  firstNumeric; firstTime priority, firstNumeric key order
- internal/treadmill/parse_test.go: parseWatts envelope + raw + null-
  value + missing-value (both must NOT synthesise 0 W) + whitespace +
  garbage

45 tests pass across the three packages (~5 before this commit).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…v10)

Every setting the /config/ page or PUT /api/config wrote was stored
only in the process's atomic Conf holder, so a pod restart silently
reset color / pagestep / frequency_days / display_days / autofill /
cv_autolog back to the env-var defaults. The old on-disk YAML config
path was a no-op even before I removed it in PR #45. Users who flipped
CV auto-log on had it revert to off on every v0.0.102 rollout.

Migration v10 adds a single-row app_config table (CHECK (id = 1)) with
one column per persisted setting. Store gains GetAppConfig /
SaveAppConfig. Startup path: env vars → overlay persisted row (when
present) → conf.Set. Save handlers (web + api) UPSERT after conf.Set;
persist failure is a soft-fail (server-side log) so a broken DB
never makes the UI look broken.

Not persisted: Pushover credentials (env-only per Layer 2 invariant on
secrets), NodePath (environment-derived).

Verified against a prod-dump preview:
- Fresh DB → all 10 migrations apply, schema_version has 10 rows
- v9 prod dump → only v10 applies; row counts unchanged; re-run reports
  "schema is up to date"
- Round-trip: POST /config/ color=light pagestep=25 cvautolog=on;
  restart with the ORIGINAL env vars (COLOR=dark PAGESTEP=10
  CVAUTOLOG=false); config still reads light/25/true; "loaded
  persisted config" logged on startup

Bumps to pump-v0.0.103.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
# Conflicts:
#	internal/api/health_test.go
#	internal/web/colors_test.go
#	internal/web/index_test.go
@rwlove rwlove merged commit 88c71b2 into main Jul 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant