schema: add ON DELETE CASCADE to snapshot_files.file_id and snapshot_blobs.blob_id FKs #46
Reference in New Issue
Block a user
Delete Branch "fix/issue-19-cascade-snapshot-fks"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add
ON DELETE CASCADEto 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 #19
REVIEW: PASS ✅
Reviewed PR #46 against issue #19.
Diff check: 1 file changed (
internal/database/schema.sql), exactly 2 lines modified. Each addsON DELETE CASCADEto the FK declarations forsnapshot_files.file_id → files(id)andsnapshot_blobs.blob_id → blobs(id). No other files touched, no new migration files (correct for pre-1.0).CI check:
docker build .passes — fmt-check, lint, and all tests green.Consistency: The existing
snapshot_idFKs in both tables already haveON DELETE CASCADE. This change makes thefile_idandblob_idFKs consistent, ensuring junction rows are cleaned up when referenced files or blobs are deleted.Clean, minimal, correct.
is this cascade delete in the right direction from table to table?
Yes — the cascades go from parent to junction table:
snapshot_filesjunction rows (which link files to snapshots)snapshot_blobsjunction rows (which link blobs to snapshots)The reverse does NOT happen — deleting a junction row doesn't touch the parent file/blob/snapshot.
These are junction tables (
snapshot_filesmaps snapshots↔files,snapshot_blobsmaps snapshots↔blobs). Without CASCADE, deleting a file or blob would either fail with an FK violation or leave orphaned junction rows pointing at nonexistent records. Thesnapshot_idFKs in both tables already had CASCADE — this just adds it to thefile_idandblob_idFKs for consistency.