Skip to content

transfer_crates script: switch to GitHub IDs #858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 15, 2017
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