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.
This commit is contained in:
parent
a1d559c30d
commit
8a8651c690
@ -676,6 +676,11 @@ func (sm *SnapshotManager) deleteSnapshot(ctx context.Context, snapshotID string
|
|||||||
return fmt.Errorf("deleting snapshot blobs: %w", err)
|
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
|
// Delete the snapshot itself
|
||||||
if err := sm.repos.Snapshots.Delete(ctx, snapshotID); err != nil {
|
if err := sm.repos.Snapshots.Delete(ctx, snapshotID); err != nil {
|
||||||
return fmt.Errorf("deleting snapshot: %w", err)
|
return fmt.Errorf("deleting snapshot: %w", err)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user