feat: clean up staging objects after processing and during reconciliation

This commit is contained in:
kk10
2026-11-16 11:48:30 +03:00
parent 19152e7d18
commit b35faa5af8
7 changed files with 270 additions and 66 deletions
+9 -5
View File
@@ -50,6 +50,11 @@ INSERT INTO message_attachments (
SELECT * FROM attachments
WHERE id = $1::uuid;
-- name: LockAttachmentByStagingKey :one
SELECT * FROM attachments
WHERE staging_key = sqlc.arg(staging_key)::text
FOR UPDATE;
-- name: ListAttachmentsByIDs :many
SELECT status
FROM attachments
@@ -69,7 +74,7 @@ WHERE message_id = ANY(sqlc.arg(message_ids)::uuid[])
ORDER BY message_id, position;
-- name: ListAttachmentsForReconcile :many
SELECT id, s3_key, status, size_bytes
SELECT id, s3_key, staging_key, status, size_bytes, updated_at
FROM attachments;
-- name: LockAttachmentJob :one
@@ -90,11 +95,10 @@ ORDER BY lease_until, id
LIMIT sqlc.arg(batch_size)::int
FOR UPDATE SKIP LOCKED;
-- name: MarkAttachmentReady :one
-- name: ClearAttachmentStagingKey :exec
UPDATE attachments
SET status = 'ready', updated_at = now()
WHERE id = sqlc.arg(id)::uuid
RETURNING *;
SET staging_key = NULL
WHERE id = sqlc.arg(id)::uuid;
-- name: MarkAttachmentFailedIfReady :execrows
UPDATE attachments