Skip to content

Fix owner_rels.cid foreign key reference #926

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
Aug 1, 2020
Merged
Changes from 1 commit
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
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])?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to say you only do this for deleting a crate, not a version, then I realized that's the right behavior and it was just buggy before 😅

transaction.execute("DELETE FROM releases WHERE crate_id = $1;", &[&crate_id])?;
transaction.execute("DELETE FROM crates WHERE id = $1;", &[&crate_id])?;

Expand Down