Skip to content

Commit

Permalink
Merge pull request #858 from vignesh-sankaran/transfer_crates
Browse files Browse the repository at this point in the history
transfer_crates script: switch to GitHub IDs
  • Loading branch information
carols10cents authored Jul 15, 2017
2 parents 9265367 + b183833 commit 66d5d92
Showing 1 changed file with 11 additions and 12 deletions.
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

0 comments on commit 66d5d92

Please sign in to comment.