Skip to content

Commit 66d5d92

Browse files
Merge pull request #858 from vignesh-sankaran/transfer_crates
transfer_crates script: switch to GitHub IDs
2 parents 9265367 + b183833 commit 66d5d92

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/bin/transfer-crates.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ fn transfer(tx: &postgres::transaction::Transaction) {
4848
let from = User::find_by_login(tx, &from).unwrap();
4949
let to = User::find_by_login(tx, &to).unwrap();
5050

51-
if from.gh_avatar != to.gh_avatar {
51+
if from.gh_id != to.gh_id {
5252
println!("====================================================");
5353
println!("WARNING");
5454
println!("");
55-
println!("this may not be the same github user, different avatar urls");
55+
println!("this may not be the same github user, different github IDs");
5656
println!("");
57-
println!("from: {:?}", from.gh_avatar);
58-
println!("to: {:?}", to.gh_avatar);
57+
println!("from: {:?}", from.gh_id);
58+
println!("to: {:?}", to.gh_id);
5959

6060
get_confirm("continue?");
6161
}
@@ -67,29 +67,28 @@ fn transfer(tx: &postgres::transaction::Transaction) {
6767
);
6868
get_confirm("continue");
6969

70-
7170
let stmt = tx.prepare(
7271
"SELECT * FROM crate_owners
7372
WHERE owner_id = $1
7473
AND owner_kind = $2",
7574
).unwrap();
7675
let rows = stmt.query(&[&from.id, &(OwnerKind::User as i32)]).unwrap();
76+
7777
for row in rows.iter() {
78-
let id: i32 = row.get("id");
7978
let krate = Crate::find(tx, row.get("crate_id")).unwrap();
8079
println!("transferring {}", krate.name);
8180
let owners = krate.owners_old(tx).unwrap();
8281
if owners.len() != 1 {
8382
println!("warning: not exactly one owner for {}", krate.name);
8483
}
85-
let n = tx.execute(
86-
"UPDATE crate_owners SET owner_id = $1
87-
WHERE id $2",
88-
&[&to.id, &id],
89-
).unwrap();
90-
assert_eq!(n, 1);
9184
}
9285

86+
tx.execute(
87+
"UPDATE crate_owners SET owner_id = $1
88+
WHERE owner_id = $2",
89+
&[&to.id, &from.id],
90+
).unwrap();
91+
9392
get_confirm("commit?");
9493
}
9594

0 commit comments

Comments
 (0)