Skip to content

SI-27: Move Driver enum from configuration to primitives, remove duplicate in tracker-core#1921

Merged
josecelano merged 2 commits into
torrust:developfrom
josecelano:1908-si-27-move-driver-to-primitives
Jun 19, 2026
Merged

SI-27: Move Driver enum from configuration to primitives, remove duplicate in tracker-core#1921
josecelano merged 2 commits into
torrust:developfrom
josecelano:1908-si-27-move-driver-to-primitives

Conversation

@josecelano

Copy link
Copy Markdown
Member

Description

Implements SI-27 (sub-issue of EPIC #1669, issue #1908).

Moves the Driver enum (Sqlite3, MySQL, PostgreSQL) from torrust-tracker-configuration
to torrust-tracker-primitives, removes the duplicate copy in torrust-tracker-core, and
eliminates the pointless identity mapping between the two.

Changes

Package Change
primitives New driver.rs module with unified Driver enum (Serialize, Deserialize, Display, Hash, Ord, as_str(), FromStr)
configuration Removed Driver enum definition and pub type Driver re-export; imports from primitives
tracker-core Removed duplicate Driver enum (~60 lines); removed identity mapping in setup.rs; imports from primitives
persistence-benchmark Added explicit torrust-tracker-primitives dep; updated all imports
src/console (root crate) Updated E2E config builder import; added primitives dep

Acceptance criteria

  • Driver defined once in primitives, consumed by all packages
  • No duplicate in tracker-core
  • No mapping code between identical enums
  • cargo test --workspace — all 2232 tests pass
  • cargo machete — no new unused deps
  • linter all — pass
  • DEC-14 recorded in DECISIONS.md

Closes #1908

…es, remove duplicate in tracker-core

This moves the cross-cutting Driver enum (Sqlite3, MySQL, PostgreSQL) to
torrust-tracker-primitives, eliminating the duplicate copy in tracker-core
and the identity mapping in setup.rs.

- Add Driver enum with Serialize, Deserialize, Display, Hash, Ord,
  as_str(), and FromStr in packages/primitives/src/driver.rs
- Re-export from packages/primitives/src/lib.rs
- Remove Driver definition from packages/configuration/src/v2_0_0/database.rs
- Remove pub type Driver re-export from packages/configuration/src/lib.rs
- Remove duplicate Driver enum from packages/tracker-core/src/databases/driver/mod.rs
- Simplify packages/tracker-core/src/databases/setup.rs (no identity mapping)
- Update all consumers to import torrust_tracker_primitives::Driver
- Record DEC-14 in docs/issues/open/1669-overhaul-packages/DECISIONS.md
- Update issue spec torrust#1908 acceptance criteria

Implements SI-27 of EPIC torrust#1669.
Copilot AI review requested due to automatic review settings June 19, 2026 07:06
@josecelano josecelano self-assigned this Jun 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements SI-27 by centralizing the Driver enum (Sqlite3/MySQL/PostgreSQL) into torrust-tracker-primitives, removing duplicate definitions and simplifying consumers across the workspace.

Changes:

  • Added packages/primitives::Driver (new module + re-export) and updated consumers to import it.
  • Removed the duplicated Driver enum from tracker-core and simplified database initialization logic accordingly.
  • Updated benchmark tooling, console E2E config builder, and docs/decisions to reflect the new ownership.

Reviewed changes

Copilot reviewed 23 out of 24 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/console/ci/qbittorrent_e2e/tracker/config_builder.rs Switches Driver import to primitives for E2E config building.
packages/tracker-core/src/error.rs Updates tests/imports to use primitives Driver.
packages/tracker-core/src/databases/setup.rs Removes identity mapping and uses primitives Driver for DB selection.
packages/tracker-core/src/databases/error.rs Switches DB error typing/tests to primitives Driver.
packages/tracker-core/src/databases/driver/mod.rs Removes duplicate Driver enum definition from tracker-core.
packages/tracker-core/src/authentication/handler.rs Updates tests/imports to use primitives Driver.
packages/primitives/src/lib.rs Adds driver module and re-exports Driver.
packages/primitives/src/driver.rs Introduces unified Driver enum + parsing/serialization/display/tests.
packages/primitives/Cargo.toml Enables derive_more display feature; adds serde_json dev-dependency.
packages/persistence-benchmark/src/bin/persistence_benchmark/runner.rs Switches benchmark CLI to primitives Driver.
packages/persistence-benchmark/src/bin/persistence_benchmark/reporting.rs Switches reporting + tests to primitives Driver.
packages/persistence-benchmark/src/bin/persistence_benchmark/operations.rs Switches operations to primitives Driver.
packages/persistence-benchmark/src/bin/persistence_benchmark/driver_bench/mod.rs Switches bench driver selection to primitives Driver.
packages/persistence-benchmark/src/bin/persistence_benchmark/driver_bench/database/sqlite.rs Uses primitives Driver when building benchmark config.
packages/persistence-benchmark/src/bin/persistence_benchmark/driver_bench/database/postgres.rs Uses primitives Driver when building benchmark config.
packages/persistence-benchmark/src/bin/persistence_benchmark/driver_bench/database/mysql.rs Uses primitives Driver when building benchmark config.
packages/persistence-benchmark/src/bin/persistence_benchmark/driver_bench/database/mod.rs Switches DB initialization routing to primitives Driver.
packages/persistence-benchmark/Cargo.toml Adds explicit dependency on primitives.
packages/configuration/src/v2_0_0/database.rs Imports primitives Driver instead of defining it locally.
packages/configuration/src/lib.rs Removes Driver type alias re-export.
docs/issues/open/1908-1669-si-27-move-driver-enum-to-primitives.md Updates verification checklist for SI-27.
docs/issues/open/1669-overhaul-packages/DECISIONS.md Adds DEC-14 documenting the move of Driver to primitives.
Cargo.toml Adds root-crate dependency on primitives.
Cargo.lock Records dependency graph changes (including serde_json).
Comments suppressed due to low confidence (1)

packages/tracker-core/src/databases/setup.rs:100

  • driver is a &Driver, but the match arms use non-reference patterns (Driver::Sqlite3, etc.). This does not type-check; either match on *driver (owned/cloned) or use reference patterns (&Driver::...).
    let driver = &config.database.driver;

    match driver {
        Driver::Sqlite3 => {
            let db = Arc::new(Sqlite::new(&config.database.path).expect("Database driver build failed."));
            db.create_database_tables().await.expect("Could not create database tables.");
            build_database_stores(db)
        }
        Driver::MySQL => {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/issues/open/1669-overhaul-packages/DECISIONS.md Outdated
Comment thread docs/issues/open/1669-overhaul-packages/DECISIONS.md Outdated
Comment thread docs/issues/open/1908-1669-si-27-move-driver-enum-to-primitives.md Outdated
…y PR review

Corrects three documentation issues identified by copilot-pull-request-reviewer:
- DECISIONS.md: CLI parity claim incorrectly mentioned clap::ValueEnum (actually FromStr/as_str())
- DECISIONS.md: trade-off listed clap dependency that was never added (actually serde_json dev-dep)
- Issue spec checklist: said 're-exported from configuration' but re-export was removed
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.42%. Comparing base (6544933) to head (79eb106).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1921      +/-   ##
===========================================
+ Coverage    79.22%   79.42%   +0.19%     
===========================================
  Files          326      327       +1     
  Lines        22981    23024      +43     
  Branches     22981    23024      +43     
===========================================
+ Hits         18207    18287      +80     
+ Misses        4508     4476      -32     
+ Partials       266      261       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@josecelano

Copy link
Copy Markdown
Member Author

ACK 79eb106

@josecelano josecelano merged commit 4022cc4 into torrust:develop Jun 19, 2026
26 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.

SI-27: Move Driver enum from configuration to primitives (EPIC #1669)

2 participants