fix(cleanup): delete queued rows before their objects
This commit is contained in:
@@ -64,12 +64,32 @@ ORDER BY message_id, position;
|
||||
SELECT id, s3_key FROM attachments
|
||||
WHERE status = 'queued' AND created_at < sqlc.arg(cutoff)::timestamptz;
|
||||
|
||||
-- name: ListAttachmentsForReconcile :many
|
||||
SELECT
|
||||
a.id,
|
||||
a.s3_key,
|
||||
a.status,
|
||||
a.size_bytes,
|
||||
a.created_at,
|
||||
EXISTS (
|
||||
SELECT 1 FROM message_attachments ma
|
||||
WHERE ma.attachment_id = a.id
|
||||
) AS referenced
|
||||
FROM attachments a;
|
||||
|
||||
-- name: MarkAttachmentFailedIfReady :execrows
|
||||
UPDATE attachments
|
||||
SET status = 'failed',
|
||||
error_code = sqlc.arg(error_code)::text,
|
||||
updated_at = now()
|
||||
WHERE id = sqlc.arg(id)::uuid AND status = 'ready';
|
||||
|
||||
-- name: MarkAttachmentReady :one
|
||||
UPDATE attachments
|
||||
SET status = 'ready', updated_at = now()
|
||||
WHERE id = $1::uuid
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteAttachment :exec
|
||||
-- name: DeleteQueuedAttachment :execrows
|
||||
DELETE FROM attachments
|
||||
WHERE id = $1::uuid;
|
||||
WHERE id = sqlc.arg(id)::uuid AND status = 'queued';
|
||||
|
||||
Reference in New Issue
Block a user