From c22f661f05091a21b8d4179d625adc9d7e2d6413 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 9 Nov 2023 17:18:53 +0100 Subject: [PATCH] refactor: [#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 --- .../20230921211559_torrust_add_encoding_to_torrent.sql | 2 +- .../20230921211559_torrust_add_encoding_to_torrent.sql | 2 +- src/databases/mysql.rs | 8 ++++---- src/databases/sqlite.rs | 8 ++++---- tests/e2e/web/api/v1/contexts/torrent/asserts.rs | 8 -------- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/migrations/mysql/20230921211559_torrust_add_encoding_to_torrent.sql b/migrations/mysql/20230921211559_torrust_add_encoding_to_torrent.sql index 2250b31c..5ee5af02 100644 --- a/migrations/mysql/20230921211559_torrust_add_encoding_to_torrent.sql +++ b/migrations/mysql/20230921211559_torrust_add_encoding_to_torrent.sql @@ -1 +1 @@ -ALTER TABLE torrust_torrents ADD COLUMN "encoding" TEXT NULL; +ALTER TABLE torrust_torrents ADD COLUMN `encoding` TEXT NULL; diff --git a/migrations/sqlite3/20230921211559_torrust_add_encoding_to_torrent.sql b/migrations/sqlite3/20230921211559_torrust_add_encoding_to_torrent.sql index 1bebfd91..d15b9369 100644 --- a/migrations/sqlite3/20230921211559_torrust_add_encoding_to_torrent.sql +++ b/migrations/sqlite3/20230921211559_torrust_add_encoding_to_torrent.sql @@ -1 +1 @@ -ALTER TABLE "torrust_torrents" ADD COLUMN "encoding" TEXT NULL; \ No newline at end of file +ALTER TABLE "torrust_torrents" ADD COLUMN `encoding` TEXT NULL; \ No newline at end of file diff --git a/src/databases/mysql.rs b/src/databases/mysql.rs index de2739d3..dae509d0 100644 --- a/src/databases/mysql.rs +++ b/src/databases/mysql.rs @@ -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 @@ -471,7 +471,7 @@ impl Database for Mysql { date_uploaded, creation_date, created_by, - encoding + `encoding` ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, UTC_TIMESTAMP(), ?, ?, ?)", ) .bind(uploader_id) @@ -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 @@ -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 diff --git a/src/databases/sqlite.rs b/src/databases/sqlite.rs index 39d8b9b9..434a9048 100644 --- a/src/databases/sqlite.rs +++ b/src/databases/sqlite.rs @@ -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 @@ -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) @@ -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 @@ -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 diff --git a/tests/e2e/web/api/v1/contexts/torrent/asserts.rs b/tests/e2e/web/api/v1/contexts/torrent/asserts.rs index 376f9c82..e268c9d6 100644 --- a/tests/e2e/web/api/v1/contexts/torrent/asserts.rs +++ b/tests/e2e/web/api/v1/contexts/torrent/asserts.rs @@ -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 }