-
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.
feat!: [#97] make torrent category optional
The JSON response can now contain a `null` value for the `category`: ```json { "data": { "torrent_id": 1, "uploader": "josecelano", "info_hash": "E8564469C258B1373BC2D5749FB83B1BF83D68A0", "title": "Ubuntu", "description": null, "category": null, "upload_date": "2023-06-27 11:35:09", "file_size": 1261707713, "seeders": 0, "leechers": 0, "files": [ { "path": [ "NNN.url" ], "length": 114, "md5sum": null }, { "path": [ "XXX.url" ], "length": 121, "md5sum": null }, { "path": [ "XXX.avi" ], "length": 1261707478, "md5sum": null } ], "trackers": [ "udp://tracker:6969", ], "magnet_link": "magnet:?xt=urn:btih:E8564469C258B1373BC2D5749FB83B1BF83D68A0&dn=Ubuntu&tr=udp%3A%2F%2Ftracker%3A6969e", "tags": [] } } ```
- Loading branch information
1 parent
c27a5a9
commit 21a1f16
Showing
5 changed files
with
45 additions
and
5 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
migrations/mysql/20230627103405_torrust_allow_null_categories.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,6 @@ | ||
-- Step 1: Allow null categories for torrents | ||
ALTER TABLE torrust_torrents MODIFY category_id INTEGER NULL; | ||
|
||
-- Step 2: Set torrent category to NULL when category is deleted | ||
ALTER TABLE `torrust_torrents` DROP FOREIGN KEY `torrust_torrents_ibfk_2`; | ||
ALTER TABLE `torrust_torrents` ADD CONSTRAINT `torrust_torrents_ibfk_2` FOREIGN KEY (`category_id`) REFERENCES `torrust_categories` (`category_id`) ON DELETE SET NULL; |
28 changes: 28 additions & 0 deletions
28
migrations/sqlite3/20230627103405_torrust_allow_null_categories.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,28 @@ | ||
-- Step 1: Create a new table with the new structure | ||
CREATE TABLE IF NOT EXISTS "torrust_torrents_new" ( | ||
"torrent_id" INTEGER NOT NULL, | ||
"uploader_id" INTEGER NOT NULL, | ||
"category_id" INTEGER NULL, | ||
"info_hash" TEXT NOT NULL UNIQUE, | ||
"size" INTEGER NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"pieces" TEXT NOT NULL, | ||
"piece_length" INTEGER NOT NULL, | ||
"private" BOOLEAN DEFAULT NULL, | ||
"root_hash" INT NOT NULL DEFAULT 0, | ||
"date_uploaded" TEXT NOT NULL, | ||
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 rows from the current 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) | ||
SELECT torrent_id, uploader_id, category_id, info_hash, size, name, pieces, piece_length, private, root_hash, date_uploaded | ||
FROM torrust_torrents; | ||
|
||
-- Step 3: Delete the current table | ||
DROP TABLE torrust_torrents; | ||
|
||
-- Step 1: Rename the new table | ||
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