Skip to content

Commit

Permalink
feat: [#56] trasnfer torrents (3/4 tables) from v1.0.0 to v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Nov 8, 2022
1 parent ce466a4 commit 30bce3e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v2_0_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@ impl SqliteDatabaseV2_0_0 {
.map(|v| v.last_insert_rowid())
}

pub async fn insert_torrent_info(&self, torrent: &Torrent) -> Result<i64, sqlx::Error> {
query(
"INSERT INTO torrust_torrent_info (torrent_id, title, description)
VALUES (?, ?, ?)",
)
.bind(torrent.torrent_id)
.bind(torrent.title.clone())
.bind(torrent.description.clone())
.execute(&self.pool)
.await
.map(|v| v.last_insert_rowid())
}

pub async fn delete_all_database_rows(&self) -> Result<(), DatabaseError> {
query("DELETE FROM torrust_categories;")
.execute(&self.pool)
Expand Down
14 changes: 13 additions & 1 deletion src/upgrades/from_v1_0_0_to_v2_0_0/upgrader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,19 @@ async fn transfer_torrents(

// [v2] table torrust_torrent_info

// TODO
println!(
"[v2][torrust_torrent_info] adding the torrent info for torrent {:?} ...",
&torrent.torrent_id
);

let id = dest_database.insert_torrent_info(torrent).await;

println!(
"[v2][torrust_torrents] torrent info insert result: {:?}.",
&id
);

println!("Torrents transferred");
}
}

Expand Down

0 comments on commit 30bce3e

Please sign in to comment.