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
23 changes: 11 additions & 12 deletions src/bin/transfer-crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ fn transfer(tx: &postgres::transaction::Transaction) {
let from = User::find_by_login(tx, &from).unwrap();
let to = User::find_by_login(tx, &to).unwrap();

if from.gh_avatar != to.gh_avatar {
if from.gh_id != to.gh_id {
println!("====================================================");
println!("WARNING");
println!("");
println!("this may not be the same github user, different avatar urls");
println!("this may not be the same github user, different github IDs");
println!("");
println!("from: {:?}", from.gh_avatar);
println!("to: {:?}", to.gh_avatar);
println!("from: {:?}", from.gh_id);
println!("to: {:?}", to.gh_id);

get_confirm("continue?");
}
Expand All @@ -67,29 +67,28 @@ fn transfer(tx: &postgres::transaction::Transaction) {
);
get_confirm("continue");


let stmt = tx.prepare(
"SELECT * FROM crate_owners
WHERE owner_id = $1
AND owner_kind = $2",
).unwrap();
let rows = stmt.query(&[&from.id, &(OwnerKind::User as i32)]).unwrap();

for row in rows.iter() {
let id: i32 = row.get("id");
let krate = Crate::find(tx, row.get("crate_id")).unwrap();
println!("transferring {}", krate.name);
let owners = krate.owners_old(tx).unwrap();
if owners.len() != 1 {
println!("warning: not exactly one owner for {}", krate.name);
}
let n = tx.execute(
"UPDATE crate_owners SET owner_id = $1
WHERE id $2",
&[&to.id, &id],
).unwrap();
assert_eq!(n, 1);
}

tx.execute(
"UPDATE crate_owners SET owner_id = $1
WHERE owner_id = $2",
&[&to.id, &from.id],
).unwrap();

get_confirm("commit?");
}

Expand Down