Skip to content

Commit 43940d5

Browse files
committed
Fix deleting crates to only remove owner relationships when deleting an entire crate
1 parent 0da6269 commit 43940d5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/db/delete.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ fn get_id(conn: &Connection, name: &str) -> Result<i32, Error> {
4949

5050
// metaprogramming!
5151
// WARNING: these must be hard-coded and NEVER user input.
52-
const METADATA: [(&str, &str); 5] = [
52+
const METADATA: &[(&str, &str)] = &[
5353
("author_rels", "rid"),
54-
("owner_rels", "cid"),
5554
("keyword_rels", "rid"),
5655
("builds", "rid"),
5756
("compression_rels", "release"),
@@ -60,7 +59,7 @@ const METADATA: [(&str, &str); 5] = [
6059
fn delete_version_from_database(conn: &Connection, name: &str, version: &str) -> Result<(), Error> {
6160
let crate_id = get_id(conn, name)?;
6261
let transaction = conn.transaction()?;
63-
for &(table, column) in &METADATA {
62+
for &(table, column) in METADATA {
6463
transaction.execute(
6564
&format!("DELETE FROM {} WHERE {} IN (SELECT id FROM releases WHERE crate_id = $1 AND version = $2)", table, column),
6665
&[&crate_id, &version],
@@ -96,7 +95,7 @@ fn delete_crate_from_database(conn: &Connection, name: &str, crate_id: i32) -> R
9695
"DELETE FROM sandbox_overrides WHERE crate_name = $1",
9796
&[&name],
9897
)?;
99-
for &(table, column) in &METADATA {
98+
for &(table, column) in METADATA {
10099
transaction.execute(
101100
&format!(
102101
"DELETE FROM {} WHERE {} IN (SELECT id FROM releases WHERE crate_id = $1)",
@@ -105,6 +104,7 @@ fn delete_crate_from_database(conn: &Connection, name: &str, crate_id: i32) -> R
105104
&[&crate_id],
106105
)?;
107106
}
107+
transaction.execute("DELETE FROM owner_rels WHERE cid = $1;", &[&crate_id])?;
108108
transaction.execute("DELETE FROM releases WHERE crate_id = $1;", &[&crate_id])?;
109109
transaction.execute("DELETE FROM crates WHERE id = $1;", &[&crate_id])?;
110110

0 commit comments

Comments
 (0)