From 0795e4099f74dfe161633bf2d38cbaecfc82805a Mon Sep 17 00:00:00 2001 From: Marcel Date: Thu, 26 Mar 2026 11:12:21 +0100 Subject: [PATCH] fix(delete): add cascade deletes and fix SvelteKit named action conflict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add V14 migration: ON DELETE CASCADE for document_tags and document_receivers so deleting a document removes its join-table rows automatically - Rename default form action to 'update' in the edit page — SvelteKit forbids mixing a default action with named actions (was causing 500 on delete) Co-Authored-By: Claude Sonnet 4.6 --- ...4__add_cascade_delete_to_document_join_tables.sql | 12 ++++++++++++ .../src/routes/documents/[id]/edit/+page.server.ts | 2 +- frontend/src/routes/documents/[id]/edit/+page.svelte | 8 +++++++- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 backend/src/main/resources/db/migration/V14__add_cascade_delete_to_document_join_tables.sql diff --git a/backend/src/main/resources/db/migration/V14__add_cascade_delete_to_document_join_tables.sql b/backend/src/main/resources/db/migration/V14__add_cascade_delete_to_document_join_tables.sql new file mode 100644 index 00000000..7056a7da --- /dev/null +++ b/backend/src/main/resources/db/migration/V14__add_cascade_delete_to_document_join_tables.sql @@ -0,0 +1,12 @@ +-- Add ON DELETE CASCADE to document_tags and document_receivers so that +-- deleting a document automatically removes its tag and receiver associations. + +ALTER TABLE public.document_tags + DROP CONSTRAINT fkc99c5qjulwx9gru07yrhicgd2, + ADD CONSTRAINT fkc99c5qjulwx9gru07yrhicgd2 + FOREIGN KEY (document_id) REFERENCES public.documents(id) ON DELETE CASCADE; + +ALTER TABLE public.document_receivers + DROP CONSTRAINT fks7t60twjgfmpeqcuc3g0fvjpm, + ADD CONSTRAINT fks7t60twjgfmpeqcuc3g0fvjpm + FOREIGN KEY (document_id) REFERENCES public.documents(id) ON DELETE CASCADE; diff --git a/frontend/src/routes/documents/[id]/edit/+page.server.ts b/frontend/src/routes/documents/[id]/edit/+page.server.ts index bd339151..eaaf86e3 100644 --- a/frontend/src/routes/documents/[id]/edit/+page.server.ts +++ b/frontend/src/routes/documents/[id]/edit/+page.server.ts @@ -41,7 +41,7 @@ export async function load({ } export const actions = { - default: async ({ request, params, fetch }) => { + update: async ({ request, params, fetch }) => { // Raw fetch is used here because FormData multipart bodies are passed through // directly from the browser without transformation. const baseUrl = env.API_INTERNAL_URL || 'http://localhost:8080'; diff --git a/frontend/src/routes/documents/[id]/edit/+page.svelte b/frontend/src/routes/documents/[id]/edit/+page.svelte index b8e8e7d4..cac183a9 100644 --- a/frontend/src/routes/documents/[id]/edit/+page.svelte +++ b/frontend/src/routes/documents/[id]/edit/+page.svelte @@ -64,7 +64,13 @@ function handleDateInput(e: Event) {
{form.error}
{/if} -
+