4.2 KiB
4.2 KiB
V1 Block 20 — SQLite Persistence Adapter Package
Purpose: Implement Drift-based SQLite storage backend.
Note for Codex: Follow tasks exactly; avoid exploratory calls when tasks specify names/files/tests.
Chunk 20.1 — SQLite schema & Drift setup
Recommended level: XHIGH
Status: Complete on 2026-06-26.
Tasks
- Create new Dart package
packages/scheduler_persistence_sqlitewith Drift as dependency. - Define Drift database
SchedulerDbwith tables:tasks,projects,locked_blocks,settings,snapshots. - Fields: follow domain model; include
revision INT,owner_id TEXT. - Add drift migrations using drift_dev build runner; start at schemaVersion=1.
- Generate DAO classes via build_runner.
Acceptance criteria
dart run build_runner build --delete-conflicting-outputscompletes with zero errors.- Generated drift files checked in.
Completed implementation
- Added package
packages/scheduler_persistence_sqlitewith Drift,drift_dev, andbuild_runnerwiring. - Added
SchedulerDbinlib/src/scheduler_db.dartwithschemaVersion = 1andMigrationStrategy(onCreate: createAll). - Added tables for
tasks,projects,locked_blocks,locked_overrides,settings, andsnapshots. - Included owner scope and optimistic revision columns on mutable rows.
- Added generated Drift data classes/accessor mixins in
lib/src/scheduler_db.g.dart. - Added a schema smoke test that opens an in-memory Drift database and checks the expected table names.
Verification
dart pub get: passed.cd packages/scheduler_persistence_sqlite && dart run build_runner build --delete-conflicting-outputs: passed, exit 0; current build_runner warned that the option is ignored.dart format packages/scheduler_persistence_sqlite: passed.cd packages/scheduler_persistence_sqlite && dart analyze: passed, no issues found.dart analyze: passed, no issues found.cd packages/scheduler_persistence_sqlite && dart test: passed, 1 test.dart test: passed, 308 tests.
Chunk 20.2 — SQLite adapter implementation & tests
Recommended level: HIGH
Status: Complete on 2026-06-26.
Tasks
- Implement
SqliteTaskRepositoryetc mapping domain objects to Drift rows with explicit converters. - Use transaction for multi‑record save; ensure optimistic revision by
WHERE revision = ?clause. - Add repository conformance tests reused from block19 suite pointed at SQLite adapter (use
sqflite_ffiin tests).
Acceptance criteria
- SQLite adapter passes full conformance suite with
sqflite_ffion Linux/Windows/mac. - Average write latency in test ≤50ms.
Completed implementation
- Added
SqliteTaskRepository,SqliteProjectRepository,SqliteLockedBlockRepository,SqliteSettingsRepository, andSqliteScheduleSnapshotRepository. - Mapped Drift rows to domain objects through the existing core document mappers and explicit row/JSON converters.
- Implemented duplicate-id checks, owner isolation, deterministic paging, archive behavior, snapshot retention deletion, and typed repository failures.
- Implemented optimistic compare-and-set writes/deletes/archives with
WHERE revision = expectedclauses. - Added SQLite conformance tests using the Block 19 shared suite and an in-memory Drift SQLite executor.
- Added a write-latency test for task inserts and wired SQLite tests into the root test wrapper.
Notes
- Tests use Drift
NativeDatabase.memory()instead ofsqflite_ffi. A sqflite-backed Drift executor would requiredrift_sqflite, which pulls Flutter SDK dependencies into this pure Dart adapter package. - The current repository contracts expose single-record writes. No multi-record repository save method exists yet; future multi-record SQLite writes should use
SchedulerDb.transaction.
Verification
dart pub get: passed.dart format test/scheduler_core_test.dart packages/scheduler_persistence_sqlite: passed.cd packages/scheduler_persistence_sqlite && dart analyze: passed, no issues found.cd packages/scheduler_persistence_sqlite && dart test: passed, 9 tests.dart analyze: passed, no issues found.dart test: passed, 316 tests.scripts/test.sh: not present or not executable.