2.2 KiB
2.2 KiB
TT-002 — Drift Database Schema
Type: Story
Priority: Highest
Labels: database, infrastructure
Depends on: TT-001
Blocks: TT-004, TT-005
Summary
Implement the full Drift database schema in lib/core/database/app_database.dart
including all table definitions, DAOs, and the database connection provider.
Background
The Drift schema is documented in .ai/database.md. The placeholder file
lib/core/database/app_database.dart exists but contains no implementation.
Data Model
Tables
| Table | Key columns |
|---|---|
projects |
id, name, color_value, description, archived_at, created_at |
time_entries |
id, project_id (FK), start_time, end_time, duration_s, note, created_at |
tags |
id, name |
time_entry_tags |
time_entry_id (FK), tag_id (FK) — composite PK |
Acceptance Criteria
- All 4 tables defined as Drift
Tableclasses - Foreign key constraints declared and enforced
AppDatabaseannotated with@DriftDatabase(tables: [...])_openConnection()usesgetApplicationDocumentsDirectory()+NativeDatabase.createInBackgroundschemaVersion= 1, emptyMigrationStrategyscaffold in place- Three DAOs created:
ProjectsDao,TimeEntriesDao,TagsDao - Each DAO has at minimum:
watchAll(),insert(),update(),delete() TimeEntriesDao.getActiveEntry()returns entry whereend_time IS NULL- Riverpod
@Riverpod(keepAlive: true)provider forAppDatabase dart run build_runner buildgenerates schema without errors- Unit test: insert + read a
Projectusing in-memory DB
Files to create / modify
lib/core/database/app_database.dart— full implementationlib/core/database/daos/projects_dao.dartlib/core/database/daos/time_entries_dao.dartlib/core/database/daos/tags_dao.darttest/core/database/app_database_test.dart
Notes
- See
.ai/database.mdfor full schema details - Use
NativeDatabase.memory()in tests — never the real file DB