From 60b6746db95059ec71387c57d46e019c8b6e30e0 Mon Sep 17 00:00:00 2001 From: clawbot Date: Thu, 19 Mar 2026 14:03:39 +0100 Subject: [PATCH] schema: add ON DELETE CASCADE to snapshot_files.file_id and snapshot_blobs.blob_id FKs (#46) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add `ON DELETE CASCADE` to the two foreign keys that were missing it: - `snapshot_files.file_id` → `files(id)` - `snapshot_blobs.blob_id` → `blobs(id)` This ensures that when a file or blob row is deleted, the corresponding snapshot junction rows are automatically cleaned up, consistent with the other CASCADE FKs already in the schema. closes https://git.eeqj.de/sneak/vaultik/issues/19 Co-authored-by: user Reviewed-on: https://git.eeqj.de/sneak/vaultik/pulls/46 Co-authored-by: clawbot Co-committed-by: clawbot --- internal/database/schema.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/database/schema.sql b/internal/database/schema.sql index bc03da2..84415b9 100644 --- a/internal/database/schema.sql +++ b/internal/database/schema.sql @@ -103,7 +103,7 @@ CREATE TABLE IF NOT EXISTS snapshot_files ( file_id TEXT NOT NULL, PRIMARY KEY (snapshot_id, file_id), FOREIGN KEY (snapshot_id) REFERENCES snapshots(id) ON DELETE CASCADE, - FOREIGN KEY (file_id) REFERENCES files(id) + FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE ); -- Index for efficient file lookups (used in orphan detection) @@ -116,7 +116,7 @@ CREATE TABLE IF NOT EXISTS snapshot_blobs ( blob_hash TEXT NOT NULL, PRIMARY KEY (snapshot_id, blob_id), FOREIGN KEY (snapshot_id) REFERENCES snapshots(id) ON DELETE CASCADE, - FOREIGN KEY (blob_id) REFERENCES blobs(id) + FOREIGN KEY (blob_id) REFERENCES blobs(id) ON DELETE CASCADE ); -- Index for efficient blob lookups (used in orphan detection)