feat(attachments): add pipeline and outbox schema and queries

This commit is contained in:
kk10
2026-11-14 14:39:56 +03:00
parent 36d9b0c8f6
commit f2fc4b3e1f
9 changed files with 846 additions and 37 deletions
+32
View File
@@ -0,0 +1,32 @@
-- name: CreateOutboxEntry :one
INSERT INTO outbox (
job_id,
attachment_id,
pipeline_version,
attempt,
available_at
)
SELECT
job_id,
id,
pipeline_version,
sqlc.arg(attempt)::int,
sqlc.arg(available_at)::timestamptz
FROM attachments
WHERE id = sqlc.arg(attachment_id)::uuid
AND job_id IS NOT NULL
RETURNING *;
-- name: LockPendingOutboxEntries :many
SELECT * FROM outbox
WHERE published_at IS NULL
AND available_at <= now()
ORDER BY available_at, id
LIMIT sqlc.arg(batch_size)::int
FOR UPDATE SKIP LOCKED;
-- name: MarkOutboxPublished :execrows
UPDATE outbox
SET published_at = now()
WHERE id = sqlc.arg(id)::bigint
AND published_at IS NULL;