refactor: architecture foundations (status type, schema versioning, shared mock) #107

Merged
lerko merged 3 commits from refactor/arch-foundations into main 2026-06-11 20:20:24 +00:00
Owner

Summary

Phase 5a of the review-findings backlog — three foundational items that make larger refactors safer.

Commit 1 — typed Status constants:

  • New models.Status type with constants (StatusUp, StatusDown, StatusPending, StatusLate, StatusStale, StatusSSLExp)
  • IsBroken() predicate replaces duplicate isBroken lambda (monitor.go) and isDown function (sla.go)
  • ~150 bare string comparisons replaced across 16 files
  • Adding a new status (e.g. DEGRADED) now requires one constant, not grep-and-pray

Commit 2 — schema_version migration table:

  • Proper schema_version table tracks applied migrations by number
  • Replaces error-string-matching approach that broke on non-English Postgres locales
  • Fresh databases seed at baseline version (CREATE TABLE already includes all columns)
  • CREATE TABLE updated to include regions (sites) and node_id (check_history)
  • DeleteAlert now nulls sites.alert_id before deleting, preventing dangling refs

Commit 3 — shared storetest.BaseMock:

  • New internal/store/storetest/mock.go with full Store interface + optional Func field overrides
  • 6 test files embed BaseMock, override only what they need
  • Removes ~400 lines of duplicated stub methods
  • Adding a Store method now edits 1 file instead of 6

Test plan

  • go test -race ./... — all pass
  • golangci-lint — 0 issues
  • Schema version: Init is idempotent (existing tests run twice implicitly)
  • No bare "UP"/"DOWN" remaining in non-test, non-checker code
## Summary Phase 5a of the review-findings backlog — three foundational items that make larger refactors safer. **Commit 1 — typed Status constants:** - New `models.Status` type with constants (StatusUp, StatusDown, StatusPending, StatusLate, StatusStale, StatusSSLExp) - `IsBroken()` predicate replaces duplicate `isBroken` lambda (monitor.go) and `isDown` function (sla.go) - ~150 bare string comparisons replaced across 16 files - Adding a new status (e.g. DEGRADED) now requires one constant, not grep-and-pray **Commit 2 — schema_version migration table:** - Proper `schema_version` table tracks applied migrations by number - Replaces error-string-matching approach that broke on non-English Postgres locales - Fresh databases seed at baseline version (CREATE TABLE already includes all columns) - CREATE TABLE updated to include `regions` (sites) and `node_id` (check_history) - `DeleteAlert` now nulls `sites.alert_id` before deleting, preventing dangling refs **Commit 3 — shared storetest.BaseMock:** - New `internal/store/storetest/mock.go` with full Store interface + optional Func field overrides - 6 test files embed BaseMock, override only what they need - Removes ~400 lines of duplicated stub methods - Adding a Store method now edits 1 file instead of 6 ## Test plan - [x] `go test -race ./...` — all pass - [x] `golangci-lint` — 0 issues - [x] Schema version: Init is idempotent (existing tests run twice implicitly) - [x] No bare `"UP"`/`"DOWN"` remaining in non-test, non-checker code
lerko added 3 commits 2026-06-11 20:12:44 +00:00
Replace ~150 bare status string comparisons with typed models.Status
constants (StatusUp, StatusDown, StatusPending, StatusLate, StatusStale,
StatusSSLExp). Single IsBroken() method replaces the duplicated
isBroken lambda in monitor.go and isDown function in sla.go.

Adding a new status value (e.g. DEGRADED) now requires one constant
definition instead of grep-and-pray across 16 files.

CheckResult.Status stays string — the checker is the boundary between
raw protocol results and typed status. Cast happens at the edge in
handleStatusChange.
Replace the error-string-matching migration runner with a proper
schema_version table. Migrations are now numbered and recorded;
only unapplied versions run. Fresh databases seed at baseline
version (CREATE TABLE already includes all columns).

CREATE TABLE statements updated to include regions (sites) and
node_id (check_history) — previously only added via ALTER.

DeleteAlert now nulls sites.alert_id before deleting, preventing
dangling references that caused every incident to hit the error
path instead of alerting.
refactor(store): shared storetest.BaseMock replaces 5 duplicated mocks
CI / test (pull_request) Successful in 1m57s
CI / lint (pull_request) Successful in 1m16s
CI / vulncheck (pull_request) Successful in 1m1s
2b357341c8
New internal/store/storetest/mock.go provides BaseMock implementing
the full Store interface with no-op defaults and optional Func field
overrides. Each test file embeds BaseMock and shadows only the methods
it needs.

Removes ~400 lines of duplicated stub methods across 6 test files.
Adding a Store method now requires one addition (BaseMock) instead
of editing 6 files.
lerko merged commit 2b357341c8 into main 2026-06-11 20:20:24 +00:00
lerko deleted branch refactor/arch-foundations 2026-06-11 20:20:24 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: lerkolabs/uptop#107