Skip to content

feat: keep airing in SQLite so it survives a restart - #27

Merged
subpathdev merged 2 commits into
mainfrom
feat/save-airing
Nov 30, 2026
Merged

subpathdev merged 2 commits into
mainfrom
feat/save-airing

Conversation

@subpathdev

Copy link
Copy Markdown
Owner

Why

Airing was kept in memory only, so a restart or release during airing left the room off until someone tapped "Heat again". This is the first part of the away mode: the next PR adds "away until …" on top of the same store. It follows the lab rule for persistence: one SQLite database per service on a PVC, with a backup command.

What changes

  • Controller: saves each room's airing through a small AiringStore port. The value it saves is Airing, created through RestoreAiring, which validates it.
    • A change that can't be saved isn't made. The API answers 500 and the page shows "Not changed: the server couldn't save it".
    • The end of airing goes ahead even if saving fails, so a thermostat never stays off. The store catches up on the next tick.
    • At startup, airing that is still running carries on, airing that ended while the service was down restores at once, and a target held during airing comes back with it.
    • Saved airing for rooms no longer in the config is ignored. A held target outside the allowed range is dropped.
  • internal/sqlite: a pure Go adapter (modernc.org/sqlite).
    • Runs in WAL mode with synchronous=FULL, on one connection.
    • Migrations are embedded in the binary and tracked in PRAGMA user_version. An older binary refuses a newer schema.
    • VACUUM INTO provides the backup.
  • main: now an app struct with two commands: serve (the default) and backup <file>.
  • Config: dataDir is now required.
  • Chart:
    • Adds a PVC through a new persistence block (64Mi by default, kept on uninstall), mounted at config.dataDir (default /data).
    • Adds fsGroup: 65532.
  • OpenAPI: only the 500 descriptions change, so the generated code is unchanged.
  • README: a new "Saved state" section covers what is stored, what losing the file means, and the backup command.

Verification

  • go build ./..., go vet ./..., go test -race ./... pass.
  • golangci-lint v2.15.0 (through podman) reports 0 issues.
  • helm lint and helm template with Helm 4.3.2 (through podman) pass with ci-values.yaml.
  • Tests:
    • controller rules against an in-memory store: saving, rolling back when saving fails, carrying on after a restart, and trimming invalid saved state;
    • the SQLite adapter on a real temp file: round trip, replace and delete, refusing a newer schema, and backup;
    • one reopen test: airing started before a close and reopen ends on time after it, and the restore fires with the held target.
  • Local run against a throwaway Mosquitto (podman, its own base topic, a fake thermostat):
    • airing was saved and survived a restart (starting → active after the fake report);
    • the backup command worked;
    • "Heat again" sent system_mode: heat with the held 22 °C;
    • the row was deleted once the fake thermostat confirmed.
  • Not verified: real thermostats, the cluster, and the PVC on local-path.

Rollout

The first deploy behaves like today's releases: airing running at that moment is lost once more. From then on it survives restarts. Rolling back to an older chart works, because the old binary ignores the volume.

🤖 Generated with Claude Code

subpathdev and others added 2 commits November 30, 2026 11:02
Airing was in memory only, so a restart or release during airing left the
room off until someone tapped "Heat again". Following ADR-0007 (SQLite per
service), the controller now saves each room's airing through a small
AiringStore port, implemented by a SQLite adapter (modernc.org/sqlite):

- A change that can't be saved isn't made; the API answers 500 and the page
  shows "Not changed". Only the end of airing goes ahead without a save, so
  a thermostat never stays off; the store catches up on the next tick.
- At startup, airing still running carries on, airing that ended meanwhile
  restores at once, and a target held during airing comes back with it.
- Versioned migrations are embedded and applied at start.
- `heating-control backup <file>` writes a consistent copy (VACUUM INTO)
  while the service runs.
- The config requires `dataDir`; the chart adds a 64Mi PVC (kept on
  uninstall) mounted there.
- main is an app struct with serve and backup commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
go generate with a newer local Go re-encoded the PNGs; they are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@subpathdev
subpathdev merged commit 3b903f9 into main Nov 30, 2026
6 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