View Single Post
  #4  
Old 5th September 2025, 17:03
mogo mogo is offline
Coder
 
Join Date: Jun 2020
P2P
Posts: 195
Default
You’re using utf8mb4_unicode_ci → the right choice for Cyrillic and emojis.

Almost everywhere you have ON DELETE CASCADE → related records will be automatically cleaned up.

You have unique keys for username, email, passkey, info_hash → prevents duplicates.

In peers you have UNIQUE (torrent_id, peer_id) → exactly as it should be.

Possible improvements:

1. Length of peer_id
In the BitTorrent protocol, peer_id is exactly 20 bytes. It’s better to use BINARY(20) instead of VARCHAR(20), because VARCHAR counts characters while peer_id often contains binary data.

peer_id BINARY(20) NOT NULL

2. IP address
ip VARCHAR(45) is fine for IPv6, but if you want better optimization:

You could use VARBINARY(16) (to store both IPv4 and IPv6 in binary form).

This also makes indexing by IP more efficient.

3. Password
In users you left an example hash. It’s better for the password column to be CHAR(60) instead of VARCHAR(255), because bcrypt hashes are always 60 characters long.

password CHAR(60) NOT NULL

4. user_settings (PRIMARY KEY)
Here you have user_id INT PRIMARY KEY. This means a strict 1:1 relationship between users and user_settings. That’s fine, but if one day you decide to add more settings (like language, timezone, etc.), you’ll either need to add new columns or switch to a key/value model.

5. site_settings (setting_value TEXT)
If you’re storing numeric values (like max_image_size), it might be more convenient to use VARCHAR(255) or even INT instead of TEXT.

6. FOREIGN KEYS without ON DELETE
In some places, like forum_topics and forum_posts, there’s no ON DELETE CASCADE. So if you delete a forum, the topics will remain “orphaned.” Same with topics → posts. Maybe you left it this way intentionally, but if you want automatic cleanup:
FOREIGN KEY (forum_id) REFERENCES forums(id) ON DELETE CASCADE,
FOREIGN KEY (topic_id) REFERENCES forum_topics(id) ON DELETE CASCADE

7. Indexes
For faster lookups, you might add:
CREATE INDEX idx_torrents_name ON torrents(name);
CREATE INDEX idx_comments_torrent_id ON comments(torrent_id);
CREATE INDEX idx_forum_topics_forum_id ON forum_topics(forum_id);
CREATE INDEX idx_forum_posts_topic_id ON forum_posts(topic_id);
Overall, the structure is very well done and can be used directly for a tracker/forum system.

Nice work. Keep up the good work.
Regards
Reply With Quote
The Following User Says Thank You to mogo For This Useful Post:
Windocx (15th September 2025)