Skip to content

fix(coderd): clean up task snapshots on task deletion - #21949

Merged
mafredri merged 1 commit into
mainfrom
mafredri/feat-tasks-cleanup-snapshots
Feb 6, 2026
Merged

mafredri merged 1 commit into
mainfrom
mafredri/feat-tasks-cleanup-snapshots

Conversation

@mafredri

@mafredri mafredri commented Feb 5, 2026

Copy link
Copy Markdown
Member

Task snapshots were orphaned when tasks were soft-deleted. The
task_snapshots table has an ON DELETE CASCADE foreign key, but
that only fires on hard deletes.

Modified DeleteTask to use a CTE that atomically soft-deletes the
task and removes its snapshot in a single transaction. The query now
returns just the task UUID instead of the full row.

Closes coder/internal#1283

Task snapshots were orphaned when tasks were soft-deleted. The
`task_snapshots` table has an `ON DELETE CASCADE` foreign key, but
that only fires on hard deletes.

Modified DeleteTask to use a CTE that atomically soft-deletes the
task and removes its snapshot in a single transaction. The query now
returns just the task UUID instead of the full row.

Closes coder/internal#1283
@mafredri
mafredri force-pushed the mafredri/feat-tasks-cleanup-snapshots branch from 92c6f7d to 5b6dcce Compare February 6, 2026 09:24
@mafredri
mafredri marked this pull request as ready for review February 6, 2026 09:44
Comment on lines +68 to +71
), deleted_snapshot AS (
DELETE FROM task_snapshots
WHERE task_id = @id::uuid
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 😄

@mafredri
mafredri merged commit c60c373 into main Feb 6, 2026
50 of 52 checks passed
@mafredri
mafredri deleted the mafredri/feat-tasks-cleanup-snapshots branch February 6, 2026 09:55
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tasks: Database cleanup for soft-deleted task snapshots

3 participants