Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions src/admin/transfer_crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
schema::{crate_owners, crates, users},
};

use crate::tasks::spawn_blocking;
use diesel::prelude::*;
use diesel_async::{AsyncPgConnection, RunQueryDsl};

#[derive(clap::Parser, Debug)]
#[command(
Expand All @@ -21,22 +21,21 @@
}

pub async fn run(opts: Opts) -> anyhow::Result<()> {
spawn_blocking(move || {
let conn = &mut db::oneoff_connection()?;
transfer(opts, conn)?;
Ok(())
})
.await
let mut conn = db::oneoff_async_connection().await?;
transfer(opts, &mut conn).await?;
Ok(())

Check warning on line 26 in src/admin/transfer_crates.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/transfer_crates.rs#L24-L26

Added lines #L24 - L26 were not covered by tests
}

fn transfer(opts: Opts, conn: &mut PgConnection) -> anyhow::Result<()> {
async fn transfer(opts: Opts, conn: &mut AsyncPgConnection) -> anyhow::Result<()> {

Check warning on line 29 in src/admin/transfer_crates.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/transfer_crates.rs#L29

Added line #L29 was not covered by tests
let from: User = users::table
.filter(users::gh_login.eq(opts.from_user))
.first(conn)?;
.first(conn)
.await?;

Check warning on line 33 in src/admin/transfer_crates.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/transfer_crates.rs#L32-L33

Added lines #L32 - L33 were not covered by tests

let to: User = users::table
.filter(users::gh_login.eq(opts.to_user))
.first(conn)?;
.first(conn)
.await?;

Check warning on line 38 in src/admin/transfer_crates.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/transfer_crates.rs#L37-L38

Added lines #L37 - L38 were not covered by tests

if from.gh_id != to.gh_id {
println!("====================================================");
Expand All @@ -47,7 +46,7 @@
println!("from: {:?}", from.gh_id);
println!("to: {:?}", to.gh_id);

if !dialoguer::confirm("continue?")? {
if !dialoguer::async_confirm("continue?").await? {

Check warning on line 49 in src/admin/transfer_crates.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/transfer_crates.rs#L49

Added line #L49 was not covered by tests
return Ok(());
}
}
Expand All @@ -56,7 +55,7 @@
"Are you sure you want to transfer crates from {} to {}?",
from.gh_login, to.gh_login
);
if !dialoguer::confirm(&prompt)? {
if !dialoguer::async_confirm(&prompt).await? {

Check warning on line 58 in src/admin/transfer_crates.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/transfer_crates.rs#L58

Added line #L58 was not covered by tests
return Ok(());
}

Expand All @@ -65,22 +64,30 @@
.filter(crate_owners::owner_kind.eq(OwnerKind::User));
let crates: Vec<Crate> = Crate::all()
.filter(crates::id.eq_any(crate_owners.select(crate_owners::crate_id)))
.load(conn)?;
.load(conn)
.await?;

Check warning on line 68 in src/admin/transfer_crates.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/transfer_crates.rs#L67-L68

Added lines #L67 - L68 were not covered by tests

for krate in crates {
let owners = krate.owners(conn)?;
if owners.len() != 1 {
let num_owners: i64 = crate_owners::table
.count()
.filter(crate_owners::deleted.eq(false))
.filter(crate_owners::crate_id.eq(krate.id))
.get_result(conn)
.await?;

Check warning on line 76 in src/admin/transfer_crates.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/transfer_crates.rs#L71-L76

Added lines #L71 - L76 were not covered by tests

if num_owners != 1 {

Check warning on line 78 in src/admin/transfer_crates.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/transfer_crates.rs#L78

Added line #L78 was not covered by tests
println!("warning: not exactly one owner for {}", krate.name);
}
}

if !dialoguer::confirm("commit?")? {
if !dialoguer::async_confirm("commit?").await? {

Check warning on line 83 in src/admin/transfer_crates.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/transfer_crates.rs#L83

Added line #L83 was not covered by tests
return Ok(());
}

diesel::update(crate_owners)
.set(crate_owners::owner_id.eq(to.id))
.execute(conn)?;
.execute(conn)
.await?;

Check warning on line 90 in src/admin/transfer_crates.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/transfer_crates.rs#L89-L90

Added lines #L89 - L90 were not covered by tests

Ok(())
}
Loading