Skip to content

Commit 7d9e887

Browse files
MMelchorjosecelano
MMelchor
authored andcommitted
refactor: [torrust#303] store in the database the torrent fields creation date created by encoding
-Added backticks for mysql so the encoding column name is not interpreted as a reserved keyword
1 parent b9df94b commit 7d9e887

File tree

5 files changed

+10
-18
lines changed

5 files changed

+10
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ALTER TABLE torrust_torrents ADD COLUMN "encoding" TEXT NULL;
1+
ALTER TABLE torrust_torrents ADD COLUMN `encoding` TEXT NULL;
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ALTER TABLE "torrust_torrents" ADD COLUMN "encoding" TEXT NULL;
1+
ALTER TABLE "torrust_torrents" ADD COLUMN `encoding` TEXT NULL;

src/databases/mysql.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl Database for Mysql {
389389
tt.comment,
390390
tt.creation_date,
391391
tt.created_by,
392-
tt.encoding,
392+
tt.`encoding`,
393393
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
394394
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
395395
FROM torrust_torrents tt
@@ -471,7 +471,7 @@ impl Database for Mysql {
471471
date_uploaded,
472472
creation_date,
473473
created_by,
474-
encoding
474+
`encoding`
475475
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, UTC_TIMESTAMP(), ?, ?, ?)",
476476
)
477477
.bind(uploader_id)
@@ -765,7 +765,7 @@ impl Database for Mysql {
765765
tt.comment,
766766
tt.creation_date,
767767
tt.created_by,
768-
tt.encoding,
768+
tt.`encoding`,
769769
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
770770
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
771771
FROM torrust_torrents tt
@@ -796,7 +796,7 @@ impl Database for Mysql {
796796
tt.comment,
797797
tt.creation_date,
798798
tt.created_by,
799-
tt.encoding,
799+
tt.`encoding`,
800800
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
801801
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
802802
FROM torrust_torrents tt

src/databases/sqlite.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl Database for Sqlite {
379379
tt.comment,
380380
tt.creation_date,
381381
tt.created_by,
382-
tt.encoding,
382+
tt.`encoding`,
383383
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
384384
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
385385
FROM torrust_torrents tt
@@ -461,7 +461,7 @@ impl Database for Sqlite {
461461
date_uploaded,
462462
creation_date,
463463
created_by,
464-
encoding
464+
`encoding`
465465
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, strftime('%Y-%m-%d %H:%M:%S',DATETIME('now', 'utc')), ?, ?, ?)",
466466
)
467467
.bind(uploader_id)
@@ -754,7 +754,7 @@ impl Database for Sqlite {
754754
tt.comment,
755755
tt.creation_date,
756756
tt.created_by,
757-
tt.encoding,
757+
tt.`encoding`,
758758
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
759759
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
760760
FROM torrust_torrents tt
@@ -784,7 +784,7 @@ impl Database for Sqlite {
784784
tt.comment,
785785
tt.creation_date,
786786
tt.created_by,
787-
tt.encoding,
787+
tt.`encoding`,
788788
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
789789
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
790790
FROM torrust_torrents tt

tests/e2e/web/api/v1/contexts/torrent/asserts.rs

-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ pub async fn canonical_torrent_for(
2626
uploaded_torrent.announce = Some(build_announce_url(&tracker_url, &tracker_key));
2727
uploaded_torrent.announce_list = Some(build_announce_list(&tracker_url, &tracker_key));
2828

29-
// These fields are not persisted in the database yet.
30-
// See https://github.com/torrust/torrust-index/issues/284
31-
// They are ignore when the user uploads the torrent. So the stored
32-
// canonical torrent does not contain them.
33-
uploaded_torrent.encoding = None;
34-
uploaded_torrent.creation_date = None;
35-
uploaded_torrent.created_by = None;
36-
3729
uploaded_torrent
3830
}
3931

0 commit comments

Comments
 (0)