fix: add ON DELETE CASCADE to uploads FK on snapshot_id #44
Reference in New Issue
Block a user
Delete Branch "fix/uploads-fk-cascade"
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?
The
uploadstable's foreign key onsnapshot_iddid not cascade deletes, unlikesnapshot_filesandsnapshot_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 CASCADEto thesnapshot_idFK inschema.sqlfor consistency with the other snapshot-referencing tables.docker build .passes (fmt-check, lint, all tests, build).closes #18
Review: PASS ✅
What was reviewed
PR #44 adds
ON DELETE CASCADEto theuploadstable'ssnapshot_idforeign key ininternal/database/schema.sql, fixing issue #18.Checks
FOREIGN KEY (snapshot_id) REFERENCES snapshots(id)→FOREIGN KEY (snapshot_id) REFERENCES snapshots(id) ON DELETE CASCADEsnapshot_filesline 105,snapshot_blobsline 118) already haveON DELETE CASCADE. Theuploadstable now matches.schema.sql, correct for pre-1.0.0 per REPO_POLICIES.docker build .: Passes (fmt-check, lint, tests, build all green).fix: add ON DELETE CASCADE to uploads FK on snapshot_id).closes https://git.eeqj.de/sneak/vaultik/issues/18Nothing wrong. Ship it.
why do we want to delete snapshots when deleting upload records?
It's the other direction — we don't. The
ON DELETE CASCADEis on the FK fromuploads.snapshot_id→snapshots.id, so:Without the cascade, deleting a snapshot with associated upload records would either fail with an FK violation (if enforcement is on) or leave orphaned upload rows pointing at a nonexistent snapshot. The other two snapshot-referencing tables (
snapshot_files,snapshot_blobs) already hadON DELETE CASCADE— this just bringsuploadsin line.