feat(activity): add SQLite schema and cache initialization #288

Merged
fuzzy merged 1 commit from phase01-cache-schema into main 2026-07-07 08:07:04 +00:00
Owner

What

Add internal/activity/cache.go with SQLite database initialization and the daily_activity table schema. This is the persistence layer for the activity view feature.

Schema

daily_activity (
    context_type TEXT NOT NULL,
    context_id   TEXT NOT NULL,
    date         TEXT NOT NULL,
    prs_opened   INTEGER DEFAULT 0,
    prs_closed   INTEGER DEFAULT 0,
    issues_opened INTEGER DEFAULT 0,
    issues_closed  INTEGER DEFAULT 0,
    additions    INTEGER DEFAULT 0,
    deletions    INTEGER DEFAULT 0,
    fetched_at   TEXT NOT NULL,
    PRIMARY KEY (context_type, context_id, date)
)

API

  • Open(dbPath) — opens or creates SQLite DB, runs idempotent migration
  • Close() — closes the connection
  • migrate() — creates table + index on (context_type, context_id, fetched_at)

Dependencies

Added modernc.org/sqlite (pure Go, no CGO) for zero-dependency builds.

Why

Foundation for caching pre-aggregated daily activity data. The table design matches the cache strategy defined in activity.md: past dates are immutable, current date has 5-minute TTL.

References: #176, #170, #171

Testing

  • 13 subtests: open in-memory, invalid path rejected, table/index creation, idempotent migration, close/double-close, plus existing type tests
  • golangci-lint run ./internal/activity/ — 0 issues
  • go vet ./internal/activity/ — 0 issues
  • go test ./... — all pass
## What Add `internal/activity/cache.go` with SQLite database initialization and the `daily_activity` table schema. This is the persistence layer for the activity view feature. ### Schema ``` daily_activity ( context_type TEXT NOT NULL, context_id TEXT NOT NULL, date TEXT NOT NULL, prs_opened INTEGER DEFAULT 0, prs_closed INTEGER DEFAULT 0, issues_opened INTEGER DEFAULT 0, issues_closed INTEGER DEFAULT 0, additions INTEGER DEFAULT 0, deletions INTEGER DEFAULT 0, fetched_at TEXT NOT NULL, PRIMARY KEY (context_type, context_id, date) ) ``` ### API - **Open(dbPath)** — opens or creates SQLite DB, runs idempotent migration - **Close()** — closes the connection - **migrate()** — creates table + index on (context_type, context_id, fetched_at) ### Dependencies Added `modernc.org/sqlite` (pure Go, no CGO) for zero-dependency builds. ## Why Foundation for caching pre-aggregated daily activity data. The table design matches the cache strategy defined in `activity.md`: past dates are immutable, current date has 5-minute TTL. References: #176, #170, #171 ## Testing - [x] 13 subtests: open in-memory, invalid path rejected, table/index creation, idempotent migration, close/double-close, plus existing type tests - [x] `golangci-lint run ./internal/activity/` — 0 issues - [x] `go vet ./internal/activity/` — 0 issues - [x] `go test ./...` — all pass
feat(activity): add shared data types for activity cache
All checks were successful
Test and Release / test (pull_request) Successful in 3m45s
Test and Release / lint (pull_request) Successful in 4m19s
a5459799c1
- ContextType enum (user, repo, org)
- DailyActivity struct with all metrics
- ActivityWindow struct containing 7-day data
- CurrentDateTTL constant (5 min)
- Table-driven tests for all types and zero values

Ref: #181, #177, #178, #179, #180
fuzzy force-pushed phase01-cache-schema from a5459799c1
All checks were successful
Test and Release / test (pull_request) Successful in 3m45s
Test and Release / lint (pull_request) Successful in 4m19s
to bb28038a99
All checks were successful
Test and Release / lint (pull_request) Successful in 2m26s
Test and Release / test (pull_request) Successful in 4m5s
2026-07-07 08:02:49 +00:00
Compare
the.auditor left a comment

Review

Result: Approved — no blocking issues.

Summary: Adds internal/activity/cache.go with SQLite database initialization (Open, Close, migrate) and daily_activity table schema. Uses modernc.org/sqlite (pure Go, no CGO). 13 subtests pass covering in-memory open, invalid path, table/index creation, idempotent migration, and close safety. Also includes ROADMAP2.md (full project plan) and activity.md (design document).

Non-blocking issues filed:

  • #289 — Add SQLite PRAGMA settings (WAL, foreign_keys) and SetMaxOpenConns(1)
  • #290 — Document fetched_at TEXT format and Cache concurrency safety

Checklist:

  • Correctness: SQLite open/migrate/close logic correct
  • Completeness: Schema matches types.go, index on (context_type, context_id, fetched_at)
  • Test coverage: 13 subtests covering open, migrate, close, edge cases
  • Error handling: Errors wrapped with context, cleanup on failure
  • Performance: No issues (pure Go SQLite, migrations only on open)
  • Maintainability: Clean, minimal, follows Go conventions
## Review **Result: Approved** — no blocking issues. **Summary:** Adds `internal/activity/cache.go` with SQLite database initialization (`Open`, `Close`, `migrate`) and `daily_activity` table schema. Uses `modernc.org/sqlite` (pure Go, no CGO). 13 subtests pass covering in-memory open, invalid path, table/index creation, idempotent migration, and close safety. Also includes `ROADMAP2.md` (full project plan) and `activity.md` (design document). **Non-blocking issues filed:** - #289 — Add SQLite PRAGMA settings (WAL, foreign_keys) and `SetMaxOpenConns(1)` - #290 — Document `fetched_at` TEXT format and `Cache` concurrency safety **Checklist:** - Correctness: ✅ SQLite open/migrate/close logic correct - Completeness: ✅ Schema matches types.go, index on (context_type, context_id, fetched_at) - Test coverage: ✅ 13 subtests covering open, migrate, close, edge cases - Error handling: ✅ Errors wrapped with context, cleanup on failure - Performance: ✅ No issues (pure Go SQLite, migrations only on open) - Maintainability: ✅ Clean, minimal, follows Go conventions
fuzzy self-assigned this 2026-07-07 08:05:52 +00:00
fuzzy removed their assignment 2026-07-07 08:05:56 +00:00
fuzzy scheduled this pull request to auto merge when all checks succeed 2026-07-07 08:06:04 +00:00
fuzzy merged commit bb28038a99 into main 2026-07-07 08:07:04 +00:00
fuzzy deleted branch phase01-cache-schema 2026-07-07 08:07:07 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/steeper!288
No description provided.