feat(core): local persistence layer for events, samples & insights - #7
Open
shroominic wants to merge 1 commit into
Open
feat(core): local persistence layer for events, samples & insights#7shroominic wants to merge 1 commit into
shroominic wants to merge 1 commit into
Conversation
Introduce a pure-Dart HealthRepository abstraction in cgm_core covering HealthEvent, Activity/Sleep/HeartRate samples, and a new AiInsight model, with add/update/delete, query-by-window (half-open) + type filtering, and bulk insert for imports. Ships an in-memory implementation plus a reusable contract test suite. The Flutter app provides a concrete SqfliteHealthRepository (sqflite chosen over hive/isar: relational + query-friendly so window/type filters are index-backed, scales to many imported rows, and gives explicit schema migration hooks). Stays fully local; CGM reading history keeps its existing shared_preferences persistence untouched. - cgm_core: AiInsight model, HealthRepository + TimeWindow, InMemory impl - app: SqfliteHealthRepository (versioned schema + onCreate/onUpgrade), openHealthRepository() opener, FFI-backed in-process tests (no device) - adds sqflite/path/path_provider (+ sqflite_common_ffi dev dep) Unblocks journaling, on-device AI insights, and HealthKit import. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #5 (
feat/health-data-models). Rebase tomainafter #5 merges, then this PR's base can move tomain.What & why
The storage foundation that journaling, on-device AI insights, and HealthKit import build on. Builds directly on the
cgm_coredomain models from #5.Store chosen: sqflite (relational)
Picked over hive/isar because the repository's core access pattern is "records of type X in time window [a, b)". SQLite indexes the timestamp/type columns and answers those queries in SQL rather than scanning every record in Dart, it scales comfortably to the many activity/heart-rate rows a HealthKit import produces, and it exposes explicit schema-version migration hooks (
onCreate/onUpgrade). It's the lowest-risk, most idiomatic on-device Flutter store. Stays fully local — no cloud sync. The existing CGM reading history keeps itsshared_preferencespersistence, untouched.Repository API (
HealthRepository, pure Dart incgm_core)init()(runs migrations, idempotent),close(),clear().upsertEvent/upsertEvents(bulk) /deleteEvent/getEvent/queryEvents({window, types}).upsert*,delete*({window})(returns rows removed),query*({window[, types]}).upsertInsight/deleteInsight/queryInsights({window, categories}).TimeWindow— half-open[start, end), either bound optional; composes for paging.New
AiInsightmodel added tocgm_core(it didn't exist yet): id, createdAt, category, title/body, optional derivation window, confidence, model, tags; implementsTimelineEntry(newTimelineEntryKind.aiInsight); full JSON round-trip.Implementations
InMemoryHealthRepository(incgm_core) — for tests / ephemeral use.SqfliteHealthRepository(in the app) — versioned schema (schemaVersion = 1) with a forward-migration chain shared byonCreateandonUpgrade; filterable columns (epoch-ms timestamps, type/category keys) promoted out of a JSONdatacolumn and indexed.openHealthRepository()opens it in the app-documents dir.Tests (no device/simulator needed)
runHealthRepositoryContractTestssuite verifying round-trip, half-open window queries, type/category filtering, bulk insert, delete-by-window, replace-by-id, and clear — run against the in-memory impl.flutter testruns the same contract againstSqfliteHealthRepositoryviasqflite_common_ffi(in-process SQLite), plus migration/idempotent-init tests.cgm_core:dart analyzeclean, 42 tests pass. App:flutter analyzeclean (only a pre-existing unrelated info), 30 tests pass,flutter build ios --simulator --debugbuilds clean (pods resolve).Unblocks
Journaling (events), on-device AI insights (persisted history), and HealthKit/Health Connect import (bulk sample insert).
🤖 Generated with Claude Code