refactor(store): context propagation + Postgres TIMESTAMPTZ #106

Merged
lerko merged 2 commits from refactor/store-context into main 2026-06-11 19:16:53 +00:00
Owner

Summary

Phase 4 of the review-findings backlog — store hardening.

Commit 1 — context propagation (28 files):

  • All 44 Store interface methods take context.Context (Close excluded)
  • All 54 db.Query/Exec/QueryRow calls → *Context variants
  • DeleteSite/ImportData use BeginTx(ctx) instead of Begin()
  • RunCheck + all sub-checks accept parent context — HTTP checks inherit shutdown cancellation
  • dbWrite.exec takes ctx so the writer goroutine can cancel stuck operations
  • Context sources: engine ctx for goroutines, r.Context() for HTTP handlers, context.Background() for init/TUI

Commit 2 — Postgres TIMESTAMPTZ:

  • All 8 TIMESTAMP columns → TIMESTAMPTZ in CREATE TABLE
  • 8 ALTER COLUMN ... TYPE TIMESTAMPTZ migration statements for existing databases
  • Prevents timezone-shifted instants on non-UTC Postgres servers

Test plan

  • go test -count=1 ./... — all pass (CGO=0)
  • go test -race ./... — all pass (CGO=1)
  • golangci-lint — 0 issues
  • Zero db.Query(/db.Exec(/db.QueryRow( remaining (all *Context)
  • All 5 mock stores updated
## Summary Phase 4 of the review-findings backlog — store hardening. **Commit 1 — context propagation (28 files):** - All 44 Store interface methods take `context.Context` (Close excluded) - All 54 `db.Query`/`Exec`/`QueryRow` calls → `*Context` variants - `DeleteSite`/`ImportData` use `BeginTx(ctx)` instead of `Begin()` - `RunCheck` + all sub-checks accept parent context — HTTP checks inherit shutdown cancellation - `dbWrite.exec` takes ctx so the writer goroutine can cancel stuck operations - Context sources: engine ctx for goroutines, `r.Context()` for HTTP handlers, `context.Background()` for init/TUI **Commit 2 — Postgres TIMESTAMPTZ:** - All 8 `TIMESTAMP` columns → `TIMESTAMPTZ` in CREATE TABLE - 8 `ALTER COLUMN ... TYPE TIMESTAMPTZ` migration statements for existing databases - Prevents timezone-shifted instants on non-UTC Postgres servers ## Test plan - [x] `go test -count=1 ./...` — all pass (CGO=0) - [x] `go test -race ./...` — all pass (CGO=1) - [x] `golangci-lint` — 0 issues - [x] Zero `db.Query(`/`db.Exec(`/`db.QueryRow(` remaining (all *Context) - [x] All 5 mock stores updated
lerko added 2 commits 2026-06-11 19:00:21 +00:00
Every Store interface method (except Close) now takes context.Context
as first parameter. All 54 db.Query/Exec/QueryRow calls in SQLStore
replaced with their *Context variants. DB operations now respect
cancellation and deadlines.

Context sources by caller:
- Engine dbWriter/poll/pruner: engine ctx from Start()
- HTTP handlers: r.Context()
- config.Apply/Export: caller-provided ctx
- TUI/main.go init: context.Background()

RunCheck and all sub-checks (HTTP/ping/port/DNS) accept parent ctx.
HTTP checks now inherit shutdown cancellation instead of rooting in
context.Background(). dbWrite.exec takes ctx so the writer goroutine
can cancel stuck DB operations.

DeleteSite/ImportData use BeginTx(ctx) instead of Begin().
fix(store): migrate Postgres timestamps to TIMESTAMPTZ
CI / test (pull_request) Successful in 1m54s
CI / lint (pull_request) Successful in 1m17s
CI / vulncheck (pull_request) Successful in 56s
c3ae0bd80a
All 8 TIMESTAMP columns in Postgres CREATE TABLE statements changed to
TIMESTAMPTZ. Migration ALTER TYPE statements added for existing databases
(converts assuming stored values are UTC).

Prevents timezone-shifted instants on non-UTC Postgres servers, which
would skew SLA math and maintenance-window checks. SQLite unaffected —
DATETIME is typeless.
lerko merged commit c3ae0bd80a into main 2026-06-11 19:16:53 +00:00
lerko deleted branch refactor/store-context 2026-06-11 19:16:53 +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#106