diff --git a/crates/db/src/lib.rs b/crates/db/src/lib.rs index 4a64f85..c053f5d 100644 --- a/crates/db/src/lib.rs +++ b/crates/db/src/lib.rs @@ -806,7 +806,6 @@ impl Database { pub async fn cleanup_report_units(&self) -> Result<()> { let mut conn = self.pool.acquire().await?; - conn.execute("PRAGMA foreign_keys = OFF").await?; let mut tx = conn.begin().await?; let deleted_reports = sqlx::query!( r#" @@ -817,15 +816,6 @@ impl Database { .execute(&mut *tx) .await? .rows_affected(); - let deleted_report_report_units = sqlx::query!( - r#" - DELETE FROM report_report_units - WHERE report_id NOT IN (SELECT id FROM reports) - "#, - ) - .execute(&mut *tx) - .await? - .rows_affected(); let deleted_report_units = sqlx::query!( r#" DELETE FROM report_units @@ -836,13 +826,11 @@ impl Database { .await? .rows_affected(); tx.commit().await?; - conn.execute("PRAGMA foreign_keys = ON").await?; - if deleted_reports > 0 || deleted_report_units > 0 || deleted_report_report_units > 0 { + if deleted_reports > 0 || deleted_report_units > 0 { tracing::info!( - "Deleted {} orphaned reports, {} orphaned report units and {} orphaned mappings", + "Deleted {} orphaned reports and {} orphaned report units", deleted_reports, deleted_report_units, - deleted_report_report_units, ); } Ok(()) @@ -1112,7 +1100,6 @@ impl Database { pub async fn cleanup_images(&self) -> Result<()> { let mut conn = self.pool.acquire().await?; - conn.execute("PRAGMA foreign_keys = OFF").await?; let mut tx = conn.begin().await?; let deleted_images = sqlx::query!( r#" @@ -1127,7 +1114,6 @@ impl Database { .await? .rows_affected(); tx.commit().await?; - conn.execute("PRAGMA foreign_keys = ON").await?; if deleted_images > 0 { tracing::info!("Deleted {} orphaned images", deleted_images); } diff --git a/crates/github/src/changes.rs b/crates/github/src/changes.rs index 782c1d0..36d5512 100644 --- a/crates/github/src/changes.rs +++ b/crates/github/src/changes.rs @@ -232,7 +232,7 @@ fn output_line(line: &ChangeLine, out: &mut String) { fn generate_changes_list(changes: Vec, out: &mut String) { let mut changes_by_kind = BTreeMap::new(); for change in changes { - changes_by_kind.entry(change.kind.clone()).or_insert(vec![]).push(change); + changes_by_kind.entry(change.kind).or_insert(vec![]).push(change); } for (change_kind, mut changes) in changes_by_kind { let total_changes = changes.len(); diff --git a/crates/web/src/handlers/images.rs b/crates/web/src/handlers/images.rs index 8a7b46d..20d52e0 100644 --- a/crates/web/src/handlers/images.rs +++ b/crates/web/src/handlers/images.rs @@ -131,7 +131,7 @@ pub async fn get_image( fn extract_extension(params: ImageParams) -> (ImageParams, Option) { if let Some((id, ext)) = params.id.rsplit_once('.') { - return (ImageParams { id: id.to_string(), ..params }, Some(ext.to_string())); + return (ImageParams { id: id.to_string() }, Some(ext.to_string())); } (params, None) } diff --git a/crates/web/src/handlers/manage.rs b/crates/web/src/handlers/manage.rs index f6ca263..6a76031 100644 --- a/crates/web/src/handlers/manage.rs +++ b/crates/web/src/handlers/manage.rs @@ -694,9 +694,7 @@ pub async fn delete_commit( session: Session, Form(form): Form, ) -> Result { - let Some(info) = - state.db.get_project_info(¶ms.owner, ¶ms.repo, None).await? - else { + let Some(info) = state.db.get_project_info(¶ms.owner, ¶ms.repo, None).await? else { return Err(AppError::Status(StatusCode::NOT_FOUND)); }; if !current_user.can_manage_repo(info.project.id) { diff --git a/migrations/20_cascade_delete_reports.sql b/migrations/20_cascade_delete_reports.sql new file mode 100644 index 0000000..c7e9161 --- /dev/null +++ b/migrations/20_cascade_delete_reports.sql @@ -0,0 +1,28 @@ +PRAGMA foreign_keys = off; + +ALTER TABLE report_report_units + RENAME TO report_report_units_old; + +CREATE TABLE report_report_units +( + report_id INTEGER NOT NULL, + report_unit_id BLOB NOT NULL, + unit_index INTEGER NOT NULL, -- Index of the report unit in the report + PRIMARY KEY (report_id, report_unit_id, unit_index), + FOREIGN KEY (report_id) REFERENCES reports (id) ON DELETE CASCADE, + FOREIGN KEY (report_unit_id) REFERENCES report_units (id) +); + +DROP INDEX report_report_units_report_id_index; +DROP INDEX report_report_units_report_unit_id_index; + +CREATE INDEX report_report_units_report_id_index ON report_report_units (report_id); +CREATE INDEX report_report_units_report_unit_id_index ON report_report_units (report_unit_id); + +INSERT INTO report_report_units +SELECT * +FROM report_report_units_old; + +DROP TABLE report_report_units_old; + +PRAGMA foreign_keys = on; \ No newline at end of file