syncWithRemote deletes snapshot records without cleaning up related tables #10

Closed
opened 2026-02-08 17:16:24 +01:00 by clawbot · 1 comment
Collaborator

In snapshot.go syncWithRemote(), local snapshots not found in remote are deleted with just:

if err := v.Repositories.Snapshots.Delete(v.ctx, snapshotIDStr); err != nil {

This only deletes the snapshots row. The snapshot_files, snapshot_blobs, and uploads rows are NOT deleted first. Depending on FK constraints, this may either fail (FK violation) or leave orphaned records.

Compare with ListSnapshots() which correctly deletes related records first, and deleteSnapshotFromLocalDB() which also handles this.

Ref: parent issue #1

In `snapshot.go` `syncWithRemote()`, local snapshots not found in remote are deleted with just: ```go if err := v.Repositories.Snapshots.Delete(v.ctx, snapshotIDStr); err != nil { ``` This only deletes the `snapshots` row. The `snapshot_files`, `snapshot_blobs`, and `uploads` rows are NOT deleted first. Depending on FK constraints, this may either fail (FK violation) or leave orphaned records. Compare with `ListSnapshots()` which correctly deletes related records first, and `deleteSnapshotFromLocalDB()` which also handles this. Ref: parent issue #1
clawbot self-assigned this 2026-03-15 22:09:09 +01:00
Author
Collaborator

Closing: this is no longer an issue. PR #44 and PR #46 added ON DELETE CASCADE to all relevant FKs, and FK enforcement is enabled (PRAGMA foreign_keys = ON). Deleting a snapshot row now automatically cascades to delete related snapshot_files, snapshot_blobs, and uploads rows. The explicit cleanup in deleteSnapshotFromLocalDB() is redundant belt-and-suspenders. sneak closed PR #47 as unnecessary for the same reason.

Closing: this is no longer an issue. [PR #44](https://git.eeqj.de/sneak/vaultik/pulls/44) and [PR #46](https://git.eeqj.de/sneak/vaultik/pulls/46) added `ON DELETE CASCADE` to all relevant FKs, and FK enforcement is enabled (`PRAGMA foreign_keys = ON`). Deleting a snapshot row now automatically cascades to delete related `snapshot_files`, `snapshot_blobs`, and `uploads` rows. The explicit cleanup in `deleteSnapshotFromLocalDB()` is redundant belt-and-suspenders. sneak closed [PR #47](https://git.eeqj.de/sneak/vaultik/pulls/47) as unnecessary for the same reason.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/vaultik#10