Skip to content

refactor: clean database layer — DriftChatDatabase, v1 schema, InMemoryChatDatabase - #5

Merged
SimiPrambos merged 12 commits into
mainfrom
feat/database-adaptor
May 22, 2026
Merged

SimiPrambos merged 12 commits into
mainfrom
feat/database-adaptor

Conversation

@SimiPrambos

Copy link
Copy Markdown
Owner

Summary

Cleans up the database layer that had accumulated migration history from previous project iterations and makes the database testable and replaceable.

  • Rename ChatDatabaseImpl → DriftChatDatabase and its file to drift_chat_database.dart for clarity
  • Reset schema to a clean v1 baseline — removes all onUpgrade migration history (schemaVersion 1→8 had no live users)
  • Export InMemoryChatDatabase from lib/testing.dart — a full in-memory ChatDatabase implementation SDK consumers can use in their own tests without touching SQLite
  • Remove FakeChatDatabase from internal test helpers, replaced by InMemoryChatDatabase
  • Make ChatConfig.databasePath optional (defaults to '') — no longer required when using a custom ChatDatabase via ChatRegistry.custom(); throws ArgumentError if omitted when using DriftChatDatabase
  • Add beta notice to README

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactor / cleanup

Testing

  • Added unit tests
  • Updated existing tests
  • Manually tested

New test/chat_registry_test.dart covers:

  • ChatConfig() constructs without databasePath
  • databasePath defaults to empty string
  • createDatabase() throws ArgumentError when path empty and no custom DB
  • createDatabase() returns the custom DB when provided

All 146 tests pass.

Checklist

  • dart analyze passes with no issues
  • flutter test passes
  • CHANGELOG.md updated
  • Documentation updated if needed
  • No breaking changes (or breaking changes are documented)

Note on breaking changes: ChatConfig.databasePath changes from required to optional. Existing call sites that pass databasePath explicitly continue to compile unchanged. ChatConfig.withEncryption parameter order changed — encryptionKey is now first (required params before optional). Callers using named arguments are unaffected.

Related issues

SimiPrambos and others added 12 commits May 21, 2026 17:26
Renames the Drift database implementation class and file to better
communicate the underlying technology, and regenerates the .g.dart file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Promotes the in-memory ChatDatabase pattern to a first-class public API
so consumers can use it in their own tests without depending on internal
test helpers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nMemoryChatDatabase

- Move `failed` to lowest rank in _statusOrder so it never overwrites read/delivered on dedup
- Add _emitStarredMessages() helper, called from updateMessage when isStarred changes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove the ~600-line FakeChatDatabase class from test_helpers.dart and
replace all usages in test files with InMemoryChatDatabase from
lib/testing.dart, which is now the canonical in-memory test double.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
databasePath now defaults to '' so tests and custom-database setups can
omit it. ChatRegistry.createDatabase throws ArgumentError when the path
is empty and no custom database is provided, making the misconfiguration
explicit at runtime instead of silently failing deeper in Drift.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ePath

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@SimiPrambos
SimiPrambos merged commit baf2c87 into main May 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant