Skip to content

1525-07: Align Rust and database types #1721

Closed

Description

@josecelano

Goal

Widen the download-counter type in Rust from u32 to u64 and widen the corresponding database columns from INTEGER (32-bit, MySQL) to BIGINT (64-bit), delivered as a versioned sqlx migration so the change is explicit, testable, and tracked as a forward schema change.

Spec

docs/issues/1525-07-align-rust-and-db-types.md

Parent issue

Part of the persistence overhaul EPIC: #1525

Tasks

  • Task 1 — Add migration files (20260409120000_torrust_tracker_widen_download_counters.sql for both sqlite/ and mysql/)
  • Task 2 — Widen NumberOfDownloads from u32 → u64, update SwarmMetadata.downloaded, add decode_counter/encode_counter helpers to both drivers, fix all cascade compilation errors
  • Task 3 — Add tests: MySQL column widening round-trip, SQLite no-op, encode_counter error on values above i64::MAX

Acceptance Criteria

  • packages/tracker-core/migrations/sqlite/20260409120000_torrust_tracker_widen_download_counters.sql exists and is a comment-only no-op.
  • packages/tracker-core/migrations/mysql/20260409120000_torrust_tracker_widen_download_counters.sql exists and widens torrents.completed and torrent_aggregate_metrics.value to BIGINT.
  • NumberOfDownloads = u64 in packages/primitives/src/lib.rs.
  • SwarmMetadata.downloaded uses NumberOfDownloads; bare u32 is removed from that field.
  • Both driver files use explicit decode_counter / encode_counter helpers for all counter-column reads and writes.
  • encode_counter returns an error (not a panic, not silent truncation) for values above i64::MAX.
  • A test verifies round-trip of a value larger than u32::MAX for each backend.
  • A test verifies the encode error path for values above i64::MAX.
  • No as u32 casts or compiler-suppression attributes introduced by this subissue.
  • cargo test --workspace --all-targets passes.
  • linter all exits with code 0.

References

Activity

  1. self-assigned this
    on Apr 30, 2026
  2. added a commit that references this issue on Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions