Repository navigation
Description
Goal
Decompose the monolithic Database trait into four focused context traits while keeping Database as the unified driver contract, and write an ADR to record the decision.
Background
packages/tracker-core/src/databases/mod.rs defines a single Database trait with 19 methods covering four unrelated concerns: schema management, torrent metrics, whitelist, and authentication keys. This makes the trait long and conflates distinct responsibilities in one place.
Two options were considered:
-
Replace
Databasewith four independent traits — consumers holdArc<dyn WhitelistStore>etc. directly. Clean interface segregation, but it loses the single place that tells a new driver implementor exactly what to build, and it changes every consumer at once. -
Keep
Databaseas an aggregate supertrait (chosen) — the four narrow traits exist independently;Databaseis defined as:pub trait Database: Sync + Send + SchemaMigrator + TorrentMetricsStore + WhitelistStore + AuthKeyStore {}
A blanket impl means any type that implements all four narrow traits automatically satisfies
Database. Existing consumers (Arc<Box<dyn Database>>) are untouched.
Tasks
- Write ADR:
docs/adrs/<timestamp>_keep_database_as_aggregate_supertrait.md - Introduce
SchemaMigratortrait indatabases/schema.rs - Introduce
TorrentMetricsStoretrait indatabases/torrent_metrics.rs - Introduce
WhitelistStoretrait indatabases/whitelist.rs - Introduce
AuthKeyStoretrait indatabases/auth_keys.rs - Introduce
Databaseaggregate supertrait + blanket impl indatabases/database.rs - Update SQLite driver to implement the four narrow traits
- Update MySQL driver to implement the four narrow traits
- Update
mod.rsto declare new submodules and re-export traits/mocks
Acceptance Criteria
- ADR is written and added to
docs/adrs/index.md. - Four narrow traits exist in separate files under
databases/. -
Databaseis an empty aggregate supertrait with a blanket impl. - Both drivers (
Sqlite,Mysql) compile through the blanket impl with no manualimpl Database for <Driver>block. - No existing consumer file (
persisted.rs,downloads.rs, etc.) is changed. -
#[automock]is on the four narrow traits;MockDatabaseis removed. - No behavior change — existing tests pass without modification.
-
cargo test --workspace --all-targetspasses. -
linter allexits with code0.
References
- Part of EPIC: Overhaul persistence #1525
- Spec file:
docs/issues/1525-04-split-persistence-traits.md - Reference PR: feat: rework persistence for async sqlx backends and PostgreSQL support #1695
- Reference implementation branch:
josecelano:pr-1684-review packages/tracker-core/src/databases/mod.rs— current monolithicDatabasetrait
Activity
josecelano commentedon Apr 29, 2026
The new trait names were proposed in this PR by @DamnCrab. It was planned in the original Overhaul persistence EPIC
docs(1525-04): rename spec and link to GitHub issue #1713
Merge #1714: feat(tracker-core): split Database trait into four narro…
chore(issues): archive closed issue specs to docs/issues/closed
feat(tracker-core): split Database trait into four narrow persistence…