feat(cleanup): remove stale queued attachments after grace period

This commit is contained in:
kk10
2026-11-03 15:12:55 +03:00
parent fbd9c56b1f
commit 1ee4f8ecec
7 changed files with 189 additions and 36 deletions
+14 -2
View File
@@ -8,7 +8,6 @@ INSERT INTO attachments (
content_type,
size_bytes,
sha256,
status,
error_code
)
SELECT
@@ -20,7 +19,6 @@ SELECT
sqlc.arg(content_type)::attachment_content_type,
sqlc.arg(size_bytes)::int,
sqlc.arg(sha256)::text,
sqlc.arg(status)::attachment_status,
NULLIF(sqlc.arg(error_code)::text, '')
WHERE EXISTS (
SELECT 1 FROM chat_members
@@ -61,3 +59,17 @@ SELECT message_id, attachment_id
FROM message_attachments
WHERE message_id = ANY(sqlc.arg(message_ids)::uuid[])
ORDER BY message_id, position;
-- name: ListStaleAttachmentUploads :many
SELECT id, s3_key FROM attachments
WHERE status = 'queued' AND created_at < sqlc.arg(cutoff)::timestamptz;
-- name: MarkAttachmentReady :one
UPDATE attachments
SET status = 'ready', updated_at = now()
WHERE id = $1::uuid
RETURNING *;
-- name: DeleteAttachment :exec
DELETE FROM attachments
WHERE id = $1::uuid;