From f28c8a73b7a0623cdd5d20276f64d5cdb452a1cd Mon Sep 17 00:00:00 2001 From: clawbot Date: Thu, 19 Mar 2026 13:59:27 +0100 Subject: [PATCH] fix: add ON DELETE CASCADE to uploads FK on snapshot_id (#44) The `uploads` table's foreign key on `snapshot_id` did not cascade deletes, unlike `snapshot_files` and `snapshot_blobs`. This caused FK violations when deleting snapshots with associated upload records (if FK enforcement is enabled) unless uploads were manually deleted first. Adds `ON DELETE CASCADE` to the `snapshot_id` FK in `schema.sql` for consistency with the other snapshot-referencing tables. `docker build .` passes (fmt-check, lint, all tests, build). closes https://git.eeqj.de/sneak/vaultik/issues/18 Co-authored-by: clawbot Reviewed-on: https://git.eeqj.de/sneak/vaultik/pulls/44 Co-authored-by: clawbot Co-committed-by: clawbot --- internal/database/schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/database/schema.sql b/internal/database/schema.sql index 64b03a0..bc03da2 100644 --- a/internal/database/schema.sql +++ b/internal/database/schema.sql @@ -130,7 +130,7 @@ CREATE TABLE IF NOT EXISTS uploads ( size INTEGER NOT NULL, duration_ms INTEGER NOT NULL, FOREIGN KEY (blob_hash) REFERENCES blobs(blob_hash), - FOREIGN KEY (snapshot_id) REFERENCES snapshots(id) + FOREIGN KEY (snapshot_id) REFERENCES snapshots(id) ON DELETE CASCADE ); -- Index for efficient snapshot lookups