Skip to content

Commit

Permalink
refactor: [#303] store in the database the torrent fields creation da…
Browse files Browse the repository at this point in the history
…te created by encoding

    -Added backticks for mysql so the encoding column name is not interpreted as a reserved keyword
  • Loading branch information
mario-nt committed Nov 9, 2023
1 parent c3d69f4 commit c22f661
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE torrust_torrents ADD COLUMN "encoding" TEXT NULL;
ALTER TABLE torrust_torrents ADD COLUMN `encoding` TEXT NULL;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE "torrust_torrents" ADD COLUMN "encoding" TEXT NULL;
ALTER TABLE "torrust_torrents" ADD COLUMN `encoding` TEXT NULL;
8 changes: 4 additions & 4 deletions src/databases/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl Database for Mysql {
tt.comment,
tt.creation_date,
tt.created_by,
tt.encoding,
tt.`encoding`,
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
FROM torrust_torrents tt
Expand Down Expand Up @@ -471,7 +471,7 @@ impl Database for Mysql {
date_uploaded,
creation_date,
created_by,
encoding
`encoding`
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, UTC_TIMESTAMP(), ?, ?, ?)",
)
.bind(uploader_id)
Expand Down Expand Up @@ -765,7 +765,7 @@ impl Database for Mysql {
tt.comment,
tt.creation_date,
tt.created_by,
tt.encoding,
tt.`encoding`,
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
FROM torrust_torrents tt
Expand Down Expand Up @@ -796,7 +796,7 @@ impl Database for Mysql {
tt.comment,
tt.creation_date,
tt.created_by,
tt.encoding,
tt.`encoding`,
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
FROM torrust_torrents tt
Expand Down
8 changes: 4 additions & 4 deletions src/databases/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl Database for Sqlite {
tt.comment,
tt.creation_date,
tt.created_by,
tt.encoding,
tt.`encoding`,
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
FROM torrust_torrents tt
Expand Down Expand Up @@ -461,7 +461,7 @@ impl Database for Sqlite {
date_uploaded,
creation_date,
created_by,
encoding
`encoding`
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, strftime('%Y-%m-%d %H:%M:%S',DATETIME('now', 'utc')), ?, ?, ?)",
)
.bind(uploader_id)
Expand Down Expand Up @@ -754,7 +754,7 @@ impl Database for Sqlite {
tt.comment,
tt.creation_date,
tt.created_by,
tt.encoding,
tt.`encoding`,
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
FROM torrust_torrents tt
Expand Down Expand Up @@ -784,7 +784,7 @@ impl Database for Sqlite {
tt.comment,
tt.creation_date,
tt.created_by,
tt.encoding,
tt.`encoding`,
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
FROM torrust_torrents tt
Expand Down
8 changes: 0 additions & 8 deletions tests/e2e/web/api/v1/contexts/torrent/asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ pub async fn canonical_torrent_for(
uploaded_torrent.announce = Some(build_announce_url(&tracker_url, &tracker_key));
uploaded_torrent.announce_list = Some(build_announce_list(&tracker_url, &tracker_key));

// These fields are not persisted in the database yet.
// See https://github.com/torrust/torrust-index/issues/284
// They are ignore when the user uploads the torrent. So the stored
// canonical torrent does not contain them.
uploaded_torrent.encoding = None;
uploaded_torrent.creation_date = None;
uploaded_torrent.created_by = None;

uploaded_torrent
}

Expand Down

0 comments on commit c22f661

Please sign in to comment.