Files
buzz/schema/tables/public/relay_admin_outbox.sql

37 lines
1.7 KiB
SQL

-- ── Relay admin outbox (durable enforcement delivery) ────────────────────────
-- Transactional outbox for durable artifact/notice delivery.
CREATE TABLE relay_admin_outbox (
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
action_id UUID NOT NULL REFERENCES relay_admin_actions(id),
-- Delivery task type: 'tombstone' | 'system_message' | 'reporter_notice'.
task_type TEXT NOT NULL,
-- Task payload (JSON).
payload JSONB NOT NULL DEFAULT '{}'::jsonb,
-- Lease-based delivery: held_by identifies the worker pod.
held_by TEXT,
lease_expires_at TIMESTAMPTZ,
-- Delivery state: pending → delivered | failed.
state TEXT NOT NULL DEFAULT 'pending'
CHECK (state IN ('pending', 'delivered', 'failed')),
-- Deduplication key: prevents re-creating an artifact after delivery.
dedup_key TEXT UNIQUE,
error_message TEXT,
-- Retryable delivery with backoff (migration 0037): failures reschedule via
-- retry_after rather than terminating immediately.
attempt_count INT NOT NULL DEFAULT 0,
retry_after TIMESTAMPTZ,
-- Per-claim ownership fence (migration 0038): completion/failure updates
-- require the token written at claim time, so a stale worker cannot overwrite
-- a newer worker's terminal update.
outbox_claim_token UUID,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_relay_admin_outbox_action
ON relay_admin_outbox (action_id);
CREATE INDEX idx_relay_admin_outbox_pending
ON relay_admin_outbox (retry_after, created_at)
WHERE state = 'pending';