Skip to content

Conversation

@da2ce7
Copy link
Contributor

@da2ce7 da2ce7 commented Feb 6, 2026

@josecelano a simple demo of what a basic update of the sql tables would look like

I can confirm that the torrents table only includes torrents that have at least one download.

Add CHECK constraint to ensure the `completed` column in the `torrents`
table is always >= 1, preventing invalid zero values. This change
reflects the semantic meaning that a torrent entry should only exist
once it has been completed at least once.

Changes:
- Add migration scripts for both SQLite and MySQL to:
  - Delete any existing rows with completed = 0
  - Add CHECK constraint (completed >= 1)
  - Change default value from 0 to 1
- Update hardcoded table creation SQL in database drivers to include
  the new constraint and default value
- Document the new constraint in migrations README with complete
  table schema reference for all 4 tracker tables
- Update module documentation to clarify permanent keys support

The migration handles SQLite's limitation by recreating the table,
while MySQL can add the constraint directly (requires MySQL 8.0.16+).
Migrate the `whitelist` table to `whitelist_v1` with optimized storage
and indexing. This change removes the unnecessary auto-increment `id`
column and uses `info_hash` directly as the PRIMARY KEY, improving
both storage efficiency and query performance.

Database-specific optimizations:
- **SQLite**: Use `WITHOUT ROWID` optimization since info_hash is
  already a suitable primary key (40-char hex string). This eliminates
  the hidden rowid column and reduces storage overhead.
- **MySQL**: Store info_hash as `BINARY(20)` instead of `VARCHAR(40)`,
  reducing storage from 40 bytes to 20 bytes per entry and improving
  index performance.

Changes:
- Add migration scripts for both SQLite and MySQL to:
  - Create new `whitelist_v1` table with optimized schema
  - Migrate existing data (converting hex to binary for MySQL)
  - Drop old `whitelist` table
- Update hardcoded table creation SQL in database drivers to match
  new schema
- Update all whitelist queries to use `whitelist_v1` table name
- Update MySQL driver to use binary storage with `UNHEX()`/bytes()
  for info_hash operations
- Document the new schema in migrations README with storage format
  details for both databases

The migration preserves all existing whitelist data while improving
storage efficiency and query performance for whitelist lookups.
Rename the `torrents` table to `completed_v1` with improved storage
efficiency and semantic clarity. This change removes the unnecessary
auto-increment `id` column, uses `info_hash` directly as the PRIMARY
KEY, and renames the `completed` column to `count` for better clarity.

Database-specific optimizations:
- **SQLite**: Use `WITHOUT ROWID` optimization since info_hash is
  already a suitable primary key (40-char hex string). This eliminates
  the hidden rowid column and reduces storage overhead.
- **MySQL**: Store info_hash as `BINARY(20)` instead of `VARCHAR(40)`,
  reducing storage from 40 bytes to 20 bytes per entry and improving
  index performance.

Changes:
- Add migration scripts for both SQLite and MySQL to:
  - Create new `completed_v1` table with optimized schema
  - Migrate existing data (converting hex to binary for MySQL)
  - Drop old `torrents` table
- Update hardcoded table creation SQL in database drivers to match
  new schema
- Update all torrent download queries to use `completed_v1` table name
  and `count` column name
- Update MySQL driver to use binary storage with `UNHEX()`/bytes()
  for info_hash operations
- Document the new schema in migrations README with storage format
  details for both databases

The migration preserves all existing torrent download data while
improving storage efficiency and query performance. The new table name
`completed_v1` better reflects its purpose of tracking download
completion counts.
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