forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a new feature. It allow creating permanent keys (keys that do not expire). THis is an example for making a request to the endpoint using curl: ```console curl -X POST http://localhost:1212/api/v1/keys?token=MyAccessToken \ -H "Content-Type: application/json" \ -d '{ "key": null, "seconds_valid": null }' ``` NOTICE: both the `key` and the `seconds_valid` fields can be null. - If `key` is `null` a new random key will be generated. You can use an string with a pre-generated key like `Xc1L4PbQJSFGlrgSRZl8wxSFAuMa2110`. That will allow users to migrate to the Torrust Tracker wihtout forcing the users to re-start downloading/seeding with new keys. - If `seconds_valid` is `null` the key will be permanent. Otherwise it will expire after the seconds specified in this value.
- Loading branch information
1 parent
8d3fe72
commit 6bcccd7
Showing
20 changed files
with
455 additions
and
167 deletions.
There are no files selected for viewing
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,5 @@ | ||
# Database Migrations | ||
|
||
We don't support automatic migrations yet. The tracker creates all the needed tables when it starts. The SQL sentences are hardcoded in each database driver. | ||
|
||
The migrations in this folder were introduced to add some new changes (permanent keys) and to allow users to migrate to the new version. In the future, we will remove the hardcoded SQL and start using a Rust crate for database migrations. For the time being, if you are using the initial schema described in the migration `20240730183000_torrust_tracker_create_all_tables.sql` you will need to run all the subsequent migrations manually. |
21 changes: 21 additions & 0 deletions
21
migrations/mysql/20240730183000_torrust_tracker_create_all_tables.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,21 @@ | ||
CREATE TABLE | ||
IF NOT EXISTS whitelist ( | ||
id integer PRIMARY KEY AUTO_INCREMENT, | ||
info_hash VARCHAR(40) NOT NULL UNIQUE | ||
); | ||
|
||
CREATE TABLE | ||
IF NOT EXISTS torrents ( | ||
id integer PRIMARY KEY AUTO_INCREMENT, | ||
info_hash VARCHAR(40) NOT NULL UNIQUE, | ||
completed INTEGER DEFAULT 0 NOT NULL | ||
); | ||
|
||
CREATE TABLE | ||
IF NOT EXISTS `keys` ( | ||
`id` INT NOT NULL AUTO_INCREMENT, | ||
`key` VARCHAR(32) NOT NULL, | ||
`valid_until` INT (10) NOT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE (`key`) | ||
); |
1 change: 1 addition & 0 deletions
1
migrations/mysql/20240730183500_torrust_tracker_keys_valid_until_nullable.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 `keys` CHANGE `valid_until` `valid_until` INT (10); |
19 changes: 19 additions & 0 deletions
19
migrations/sqlite/20240730183000_torrust_tracker_create_all_tables.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,19 @@ | ||
CREATE TABLE | ||
IF NOT EXISTS whitelist ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
info_hash TEXT NOT NULL UNIQUE | ||
); | ||
|
||
CREATE TABLE | ||
IF NOT EXISTS torrents ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
info_hash TEXT NOT NULL UNIQUE, | ||
completed INTEGER DEFAULT 0 NOT NULL | ||
); | ||
|
||
CREATE TABLE | ||
IF NOT EXISTS keys ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
key TEXT NOT NULL UNIQUE, | ||
valid_until INTEGER NOT NULL | ||
); |
12 changes: 12 additions & 0 deletions
12
migrations/sqlite/20240730183500_torrust_tracker_keys_valid_until_nullable.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,12 @@ | ||
CREATE TABLE | ||
IF NOT EXISTS keys_new ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
key TEXT NOT NULL UNIQUE, | ||
valid_until INTEGER | ||
); | ||
|
||
INSERT INTO keys_new SELECT * FROM `keys`; | ||
|
||
DROP TABLE `keys`; | ||
|
||
ALTER TABLE keys_new RENAME TO `keys`; |
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.