Files
tenant-registry/migrations/0009_mail_outbox.up.sql
T
sharangandClaude Opus 5.5 e0bff8c793
ci / shared (push) Successful in 13s
ci / test (push) Successful in 23m16s
ci / image (push) Successful in 36s
feat(notify): branded mails for published documents and new findings (#35)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
2026-09-23 21:10:06 +00:00

21 lines
964 B
SQL

-- F3 (go-live 2026-09): platform emails (document published, new findings)
-- go through an outbox, one row per recipient, so a relay outage delays mail
-- instead of losing it. The body is rendered when the row is sent, from kind,
-- locale and data, so a template fix reaches queued mail too.
CREATE TABLE mail_outbox (
id BIGSERIAL PRIMARY KEY,
tenant_id UUID REFERENCES tenants(id) ON DELETE CASCADE,
kind TEXT NOT NULL,
recipient TEXT NOT NULL,
locale TEXT NOT NULL DEFAULT 'de',
data JSONB NOT NULL DEFAULT '{}'::jsonb,
idempotency_key TEXT NOT NULL UNIQUE,
attempts INT NOT NULL DEFAULT 0,
next_attempt_at TIMESTAMPTZ NOT NULL DEFAULT now(),
sent_at TIMESTAMPTZ,
last_error TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX mail_outbox_due ON mail_outbox (next_attempt_at) WHERE sent_at IS NULL;