From 8a8651c690c0ae63f1d998824981641c549423ae Mon Sep 17 00:00:00 2001 From: sneak Date: Fri, 19 Dec 2025 12:27:05 +0700 Subject: [PATCH] Fix foreign key error when deleting incomplete snapshots Delete uploads table entries before deleting the snapshot itself. The uploads table has a foreign key to snapshots(id) without CASCADE, so we must explicitly delete upload records first. --- internal/snapshot/snapshot.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/snapshot/snapshot.go b/internal/snapshot/snapshot.go index 7a6e769..9e6052a 100644 --- a/internal/snapshot/snapshot.go +++ b/internal/snapshot/snapshot.go @@ -676,6 +676,11 @@ func (sm *SnapshotManager) deleteSnapshot(ctx context.Context, snapshotID string return fmt.Errorf("deleting snapshot blobs: %w", err) } + // Delete uploads entries (has foreign key to snapshots without CASCADE) + if err := sm.repos.Snapshots.DeleteSnapshotUploads(ctx, snapshotID); err != nil { + return fmt.Errorf("deleting snapshot uploads: %w", err) + } + // Delete the snapshot itself if err := sm.repos.Snapshots.Delete(ctx, snapshotID); err != nil { return fmt.Errorf("deleting snapshot: %w", err)