-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #516: Refactor BEP 30 implmentation
7390616 refactor: [#301] add independent field root_hash in DB for BEP-30 torrents (Jose Celano) 4d7091d refactor: [#301] rename table field root_hash to is_bep_30 (Jose Celano) Pull request description: Refactor BEP 30 implementation to make it clearer and simplify implementation. - [x] Rename table field `torrust_torrents::root_hash` to `is_bep_30`. It's not the `root hash` value in BEP 30. It's a flag for BEP 30 torrents. - [x] Don't reuse `torrust_torrents::pieces` field for BEP 30 torrents. Add a new field `root_hash`. BEP 30: https://www.bittorrent.org/beps/bep_0030.html ACKs for top commit: josecelano: ACK 7390616 Tree-SHA512: 44404db360e60951856ff04570a48ab4d4adb8db98e26a1e31409bd86bee2b281fb5b95bbaf726c3089920eb4e720c4093661633f13d4fd8370dd0e5480c4dbd
- Loading branch information
Showing
10 changed files
with
183 additions
and
56 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
migrations/mysql/20240305110750_torrust_bep_rename_root_hash_to_is_bep_30.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE torrust_torrents CHANGE COLUMN root_hash is_bep_30 BOOLEAN NOT NULL DEFAULT FALSE; |
4 changes: 4 additions & 0 deletions
4
migrations/mysql/20240305120015_torrust_add_independent_root_hash_field.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ALTER TABLE torrust_torrents ADD COLUMN root_hash LONGTEXT; | ||
|
||
-- Make `pieces` nullable. BEP 30 torrents does have this field. | ||
ALTER TABLE torrust_torrents MODIFY COLUMN pieces LONGTEXT; |
1 change: 1 addition & 0 deletions
1
migrations/sqlite3/20240305110750_torrust_bep_rename_root_hash_to_is_bep_30.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE torrust_torrents RENAME COLUMN root_hash TO is_bep_30; |
77 changes: 77 additions & 0 deletions
77
migrations/sqlite3/20240305120015_torrust_add_independent_root_hash_field.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
-- add field `root_hash` and make `pieces` nullable | ||
CREATE TABLE | ||
"torrust_torrents_new" ( | ||
"torrent_id" INTEGER NOT NULL, | ||
"uploader_id" INTEGER NOT NULL, | ||
"category_id" INTEGER, | ||
"info_hash" TEXT NOT NULL UNIQUE, | ||
"size" INTEGER NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"pieces" TEXT, | ||
"root_hash" TEXT, | ||
"piece_length" INTEGER NOT NULL, | ||
"private" BOOLEAN DEFAULT NULL, | ||
"is_bep_30" INT NOT NULL DEFAULT 0, | ||
"date_uploaded" TEXT NOT NULL, | ||
"source" TEXT DEFAULT NULL, | ||
"comment" TEXT, | ||
"creation_date" BIGINT, | ||
"created_by" TEXT, | ||
"encoding" TEXT, | ||
FOREIGN KEY ("uploader_id") REFERENCES "torrust_users" ("user_id") ON DELETE CASCADE, | ||
FOREIGN KEY ("category_id") REFERENCES "torrust_categories" ("category_id") ON DELETE SET NULL, | ||
PRIMARY KEY ("torrent_id" AUTOINCREMENT) | ||
); | ||
|
||
-- Step 2: Copy data from the old table to the new table | ||
INSERT INTO | ||
torrust_torrents_new ( | ||
torrent_id, | ||
uploader_id, | ||
category_id, | ||
info_hash, | ||
size, | ||
name, | ||
pieces, | ||
piece_length, | ||
private, | ||
root_hash, | ||
date_uploaded, | ||
source, | ||
comment, | ||
creation_date, | ||
created_by, | ||
encoding | ||
) | ||
SELECT | ||
torrent_id, | ||
uploader_id, | ||
category_id, | ||
info_hash, | ||
size, | ||
name, | ||
CASE | ||
WHEN is_bep_30 = 0 THEN pieces | ||
ELSE NULL | ||
END, | ||
piece_length, | ||
private, | ||
CASE | ||
WHEN is_bep_30 = 1 THEN pieces | ||
ELSE NULL | ||
END, | ||
date_uploaded, | ||
source, | ||
comment, | ||
creation_date, | ||
created_by, | ||
encoding | ||
FROM | ||
torrust_torrents; | ||
|
||
-- Step 3: Drop the old table | ||
DROP TABLE torrust_torrents; | ||
|
||
-- Step 4: Rename the new table to the original name | ||
ALTER TABLE torrust_torrents_new | ||
RENAME TO torrust_torrents; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.