Uploaded by Jamie Curdy

Database project

advertisement
LATVIA UNIVERSITY OF LIFE SCIENCES AND TECHNOLOGIES
Faculty of Information Technologies
SANTIS MEDNIEKS
Torrent Site Database
Data base project
Reviewer:
Dr.sc.ing. asoc. prof. G. Vitols
Signature, date
Author:
ID. 22069 S. Mednieks
Signature, date
Jelgava 20XX
CONTENTS
Contents ............................................................................................................................ 2
Specification ...................................................................................................................... 3
1
2
ER model description ............................................................................................... 4
1.1
ER model .......................................................................................................... 4
1.2
Relationship description ................................................................................... 4
Data base description ............................................................................................... 6
2.1
Technical description of the project .................................................................. 6
2.2
Self-learned material and comments ................................................................. 8
Conclusions ....................................................................................................................... 9
References ....................................................................................................................... 10
SPECIFICATION
The aim of this database is to provide a reliable data storage solution for anyone looking
to create their torrent site. It has all the core functionalities a torrent-based system should
have. It enhances user experience and stores data efficiently.
The database enables user account creation and it stores all the necessary data for users
to have personalized interactions on the website. It enables users to upload torrents, share
messages, receive messages, leave comments and form reports.
The comments system promotes user engagement with the community. This allows
users to criticize torrent uploads, leave thankful comments or suggest improvements. The
inclusion of a comments table also helps users to decide if a torrent is worth downloading.
The comments system also works great with the rating system, which is also implemented.
Trackers are a crucial part of any torrent-based system since it creates communication
between peers which is why information related to trackers is also stored.
The messages table allows for a messaging system to be present on a website and it
allows for users to communicate with each other privately, rather than through comments.
In order to filter out bad torrents and take care of the community, an admin team is
required to oversee the operations of the website. The admin team table identifies the users
who have administrative power/tools.
To relieve the workload of the administrative staff, a reports system is also set in place
so users can help the staff team filter out the bad torrents quicker. The table only stores data
on torrent reports. Private messages cannot be reported.
Peers are also a vital part of a torrent-based system. A table is included that stores info
on peers.
3
1 ER MODEL DESCRIPTION
In total the database consists of 11 tables, each having multiple columns to store all the
necessary data.











Peers table (columns: id_peers, id_user, id_torrent, ip_address, parts_downloaded, port)
Admin Team table (columns: id_admin, id_user, id_superior)
UserTorrents table (columns: id_user, id_torrent)
Rating table (columns: id_rating, name)
Users table (columns: id_user, username, email, password_hash, registration_date)
Torrents table (columns: id_torrent, title, id_category, upload_date, description,
download_count, id_rating, file_size)
Messages table (columns: id_message, sender_user_id, receiver_user_id, subject, text,
msg_date)
Comments table (columns: id_comment, id_user, id_torrent, text, comment_date)
Categories table (columns: id_category, name)
Trackers table (columns: id_tracker, id_torrent, ip_address, port, connected_peer_count)
Reports table (columns: id_report, id_user, id_torrent, text, report_date)
1.1 ER model
https://drawsql.app/teams/deeznuts-2/diagrams/torrent-site
All tables except for usertorrents table have been normalized in order to avoid repetitive
input.
1.2 Relationship description
Table users uses a one-to-many relationship with the messages table because 1 user can
send and receive multiple messages. It also has a one-to-many relationship with reports
because 1 user and form multiple reports. The users table also uses a one-to-many relationship
4
with comments the comments table because 1 user can leave multiple comments. The users
table also has a one-to-many relationship with the userstorrents table because it can be
associated with multiple torrents. It also uses a one-to-many relationship with peers because 1
user can be connected to multiple peers.
The admin team table has a one to many, recursive relationship with the id_admin
column, because a higher ranked admin can be in-charge of multiple lower-ranked admins.
The rating table has a one-to-many relationship with torrents because multiple torrents
can be rated the same rating (for ex. 12521 torrents rated “Good”).
The categories table has a one-to-many relationship with the torrents table because 1
category can have multiple torrents under it.
The torrents table has one-to-many relationship with the comments table because 1
torrent can have multiple comments. The torrents table also has a one-to-many relationship
with the peers table because 1 torrent can be associated with multiple peers. It also has a oneto-many relationship with the reports table because 1 torrent can have multiple reports on it.
The trackers table has a one-to-many relationship with the torrents table because 1
tracker can be connected to multiple torrents.
5
2 DATA BASE DESCRIPTION
2.1 Technical description of the project
Table No1. Initial data
Table name
admin_team
peers
usertorrents
rating
users
torrents
comments
messages
reports
categories
trackers
Rows
Inserted 3 rows
Inserted 5 rows
Inserted 5 rows
Inserted 5 rows
Inserted 5 rows
Inserted 5 rows
Inserted 3 rows
Inserted 3 rows
Inserted 3 rows
Inserted 5 rows
Inserted 5 rows
Table No2. Constraints
Table name
admin_team
admin_team
Column name
id_admin
id_user
admin_team
peers
peers
peers
peers
title
id_peers
id_users
id_torrent
ip_address
peers
ip_address
peers
peers
peers
peers
usertorrents
usertorrents
rating
rating
rating
users
users
users
users
users
users
users
users
parts_downloaded
parts_downloaded
port
port
id_user
id_torrent
id_rating
name
name
user_id
username
username
username
email
email
password_hash
registration_date
users
registration_date
Constraint
Value cannot be null
Value cannot be null
Value cannot be null
Value cannot be null
Value cannot be null
Value cannot be null
Value cannot be null
IP address must only contain numbers and dots
(full stops)
Value cannot be null
Parts downloaded cannot be lower than 0
Value cannot be null
Port value must be between 1024 and 65535.
Value cannot be null
Value cannot be null
Value cannot be null
Value must be unique
Value cannot be null
Value cannot be null
Value cannot be null
Username cannot be lower than 3 characters
Value must be unique
Value cannot be null
Value must be unique
Value cannot be null
Value cannot be null
Registration date cannot be newer than the
current date
6
torrents
torrents
torrents
torrents
torrents
torrents
torrents
torrents
torrents
torrents
comments
comments
comments
comments
comments
comments
messages
messages
messages
messages
messages
messages
reports
reports
reports
reports
reports
reports
categories
categories
categories
trackers
trackers
trackers
trackers
trackers
trackers
trackers
id_torrent
title
title
id_category
upload_date
upload_date
download_count
download_count
id_rating
file_size
id_comment
id_user
id_user
text
comment_date
comment_date
id_message
sender_id_user
receiver_user_id
text
msg_date
msg_date
id_report
id_user
id_torrent
text
report_date
report_date
id_category
name
name
id_tracker
id_torrent
ip_address
connected_peer_count
connected_peer_count
port
port
Value cannot be null
Value cannot be null
Title must be 6 characters long or longer
Value cannot be null
Value cannot be null
Upload date cannot be newer than current date
Value cannot be null
Download count cannot be smaller than 0
Value cannot be null
Value cannot be null
Value cannot be null
Value cannot be null
Value cannot be null
Value cannot be null
Value cannot be null
Comment date cannot be newer than current date
Value cannot be null
Value cannot be null
Value cannot be null
Value cannot be null
Value cannot be null
Message date cannot be newer than current date
Value cannot be null
Value cannot be null
Value cannot be null
Value cannot be null
Value cannot be null
Report date cannot be newer than current date
Value cannot be null
Value cannot be null
Value must be unique
Value cannot be null
Value cannot be null
Value cannot be null
Value cannot be null
Connected peer count cannot be lower than 0
Value cannot be null
Max port value can be 65535
Table No3. Sequences
Sequence name
admin_team_id_admin_seq
categories_id_category_seq
comments_id_comment_seq
messages_id_message_seq
peers_id_peers_seq
rating_id_rating_seq
reports_id_report_seq
torrents_id_torrent_seq
trackers_id_tracker_seq
users_user_id_seq
Table and column name
Used for admin_team.id_admin
Used for categories.id_category
Used for comments.id_comment
Used for messages.id_message
Used for peers.id_peers
Used for rating.id_rating
Used for reports.id_report
Used for torrents id_torrent
Used for trackers.id_tracker
Used for users.user_id
7
Table No4. Queries
Query name
categories_torre
nt_count_view
low_rated_torre
nts_view
most_reported_to
rrents_view
Code
File:
categories_torren
t_count_view.sql
File:
low_rated_torrent
s_view.sql
File:most_reporte
d_torrents_view.s
ql.sql
top_rated_categor File:top_rated_ca
ies_view
tegories_view.sql
torrent_comment
s
File:torrent_comm
ents.sql
tracker_torrents_
view
File:torrent_comm
ents.sql
user_activity_vie
w
File:user_activit
y_view.sql
Explanation
Retrieves all categories and how many torrents are
associated with each category.
Retrieves torrents that are rated 2 (Bad) and lower
Retrieves the most reported torrents with their
report count and orders it in descending order.
Retrieves categories and their average ratings of
popular torrents that have at least 5000
downloads.
Retrieves torrent titles and their respective
category along with their comment count and the
latest comment date.
Retrieves a list of trackers and their associated
torrent count.
Retrieves a list of all users and their activity such
as uploaded torrent count, comment count, report
count and message count.
Table No5. Functions
Function name
update_torrent_
name
Code
File: f01.sql
get_top_torrents File: f02.sql
admin_check
File: f03.sql
Explanation
Allows the user to change a name of a torrent by
inputting the ID of the torrent and the new title for
the torrent,
Allows the user to input 2 dates and the function
will show the top uploaded torrents between the 2
chosen dates.
Allows the user to insert the ID of another user
and the function will find out if the user is an
admin. It will display either ‘t’ or ‘f’ (true or
false) to indicate whenever the user is an admin or
not.
2.2 Self-learned material and comments
During this project I just used skills developed during lectures and I did not learn
anything extra, though I had to do extra research on how torrent-based systems work since I
had no prior knowledge on the topic. Other theoretical knowledge came from the lecture
slides.
8
CONCLUSIONS
The developed database can be used for torrent sites if minor adjustments are made as
per request from interested clients. It boasts a variety of core tables and columns, though
bigger-scale torrent sites might require a more complex structure and more major adjustments.
I learned that functions can make data retrieval way quicker. They can be made,
modified and deleted to anyone’s liking, making them overall powerful and pretty much
necessary if finding specific information is required on a daily basis.
The biggest issue with PostgreSQL management system is the inability to modify
constraints after they have been created. Other than that, I did not find any more restrictions
while working on this project.
9
REFERENCES
[1]
Class lectures
Download