#!/bin/sh set -eu : "${ATTACHMENT_ID:?Set ATTACHMENT_ID to the failed attachment UUID}" # Explicit operator action: only a failed job is moved back to the durable queue. docker compose --env-file .env exec -T postgres psql -U "${POSTGRES_USER:-messenger}" -d "${POSTGRES_DB:-messenger}" -v ON_ERROR_STOP=1 \ -v attachment_id="$ATTACHMENT_ID" <<'SQL' UPDATE attachment_jobs SET status = 'queued', attempt = 0, next_attempt_at = now(), lease_until = NULL, published_at = NULL, error_code = NULL, updated_at = now() WHERE attachment_id = :'attachment_id' AND status = 'failed'; UPDATE attachments SET status = 'queued', error_code = NULL, updated_at = now() WHERE id = :'attachment_id' AND status = 'failed'; SQL