mirror of
https://github.com/thegeneralist01/archivr
synced 2026-07-22 03:05:32 +02:00
fix(core): delete_entry correctly nulls FK for child entries
archive_run_items.produced_entry_id has no ON DELETE action so it must be manually nulled before the entry row is deleted. The old query used WHERE root_entry_id = entry_id, which finds descendants of a root but returns nothing when entry_id IS a child (children have no sub-children, so no row has root_entry_id = child_id). The DELETE then failed under foreign_keys=ON. Fix: add OR produced_entry_id = ?1 so the entry's own run_item FK is always cleared before deletion, regardless of whether it is a root or a child. The subtree subquery is kept for the root-deletion case where all child run_items also need nulling.
This commit is contained in:
parent
c800a395c7
commit
d07e4d7ac9
3 changed files with 22 additions and 4 deletions
|
|
@ -1638,12 +1638,15 @@ pub fn delete_entry(conn: &Connection, entry_uid: &str) -> Result<bool> {
|
|||
// shared blobs with any subtree member, excluding every subtree ID simultaneously.
|
||||
cascade_cached_bytes_after_subtree_delete(conn, &subtree_ids)?;
|
||||
|
||||
// Null the FK that has no ON DELETE action (covers root and all descendants).
|
||||
// Null the FK that has no ON DELETE action. Must cover:
|
||||
// - The entry itself (child entry: root_entry_id = playlist root, not self)
|
||||
// - All descendants (root entry: children have root_entry_id = entry_id)
|
||||
conn.execute(
|
||||
"UPDATE archive_run_items SET produced_entry_id = NULL
|
||||
WHERE produced_entry_id IN (
|
||||
SELECT id FROM archived_entries WHERE root_entry_id = ?1
|
||||
)",
|
||||
WHERE produced_entry_id = ?1
|
||||
OR produced_entry_id IN (
|
||||
SELECT id FROM archived_entries WHERE root_entry_id = ?1
|
||||
)",
|
||||
[entry_id],
|
||||
)?;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue