Skip to content

Commit

Permalink
Fix deleting crates to only remove owner relationships when deleting …
Browse files Browse the repository at this point in the history
…an entire crate
  • Loading branch information
Nemo157 authored and Joshua Nelson committed Aug 1, 2020
1 parent 8c97d88 commit cab5014
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/db/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ fn get_id(conn: &Connection, name: &str) -> Result<i32, Error> {

// metaprogramming!
// WARNING: these must be hard-coded and NEVER user input.
const METADATA: [(&str, &str); 5] = [
const METADATA: &[(&str, &str)] = &[
("author_rels", "rid"),
("owner_rels", "cid"),
("keyword_rels", "rid"),
("builds", "rid"),
("compression_rels", "release"),
Expand All @@ -60,7 +59,7 @@ const METADATA: [(&str, &str); 5] = [
fn delete_version_from_database(conn: &Connection, name: &str, version: &str) -> Result<(), Error> {
let crate_id = get_id(conn, name)?;
let transaction = conn.transaction()?;
for &(table, column) in &METADATA {
for &(table, column) in METADATA {
transaction.execute(
&format!("DELETE FROM {} WHERE {} IN (SELECT id FROM releases WHERE crate_id = $1 AND version = $2)", table, column),
&[&crate_id, &version],
Expand Down Expand Up @@ -96,7 +95,7 @@ fn delete_crate_from_database(conn: &Connection, name: &str, crate_id: i32) -> R
"DELETE FROM sandbox_overrides WHERE crate_name = $1",
&[&name],
)?;
for &(table, column) in &METADATA {
for &(table, column) in METADATA {
transaction.execute(
&format!(
"DELETE FROM {} WHERE {} IN (SELECT id FROM releases WHERE crate_id = $1)",
Expand All @@ -105,6 +104,7 @@ fn delete_crate_from_database(conn: &Connection, name: &str, crate_id: i32) -> R
&[&crate_id],
)?;
}
transaction.execute("DELETE FROM owner_rels WHERE cid = $1;", &[&crate_id])?;
transaction.execute("DELETE FROM releases WHERE crate_id = $1;", &[&crate_id])?;
transaction.execute("DELETE FROM crates WHERE id = $1;", &[&crate_id])?;

Expand Down

0 comments on commit cab5014

Please sign in to comment.