Clean-room Rust rewrite (written without reference to useSend source). Crates: mail-types, mail-core, mail-server, mail-auth, mail-submit, mail-hooks, mail-deliverability; sdks/ts (@scribase/mail); docs/. Each verified by running locally (see plans/scribase-mail-rust-2026-11-12.md). mail-mta, mail-inbound, mail-oci are still in progress and not in this commit. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
43 lines
1.9 KiB
SQL
43 lines
1.9 KiB
SQL
-- Scribase Mail: Supabase Send Email Hook projects. Idempotent; applied by
|
|
-- `mail_hooks::migrate(pool)` at start-up. Independent implementation,
|
|
-- written without reference to useSend source.
|
|
|
|
CREATE TABLE IF NOT EXISTS hook_projects (
|
|
id UUID PRIMARY KEY,
|
|
-- Owning Scribase Mail account (mail_accounts.id); 0...1 is the system account.
|
|
account_id UUID NOT NULL DEFAULT '00000000-0000-0000-0000-000000000001',
|
|
-- URL segment: POST /hooks/supabase/{slug}
|
|
slug TEXT NOT NULL UNIQUE,
|
|
name TEXT NOT NULL,
|
|
-- Supabase's hook secret as shown in the dashboard: `v1,whsec_<base64>`.
|
|
hook_secret TEXT NOT NULL,
|
|
from_address TEXT NOT NULL,
|
|
app_name TEXT NOT NULL,
|
|
-- Optional: build verify links against this instead of the payload's site_url.
|
|
site_url TEXT,
|
|
-- {"magiclink": {"subject": "...", "html": "...", "text": "..."}, ...}
|
|
templates JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
-- API key that created the project.
|
|
api_key_id UUID,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
);
|
|
CREATE INDEX IF NOT EXISTS hook_projects_account_idx ON hook_projects (account_id, created_at DESC);
|
|
|
|
-- One row per hook call. (project_id, webhook_id) is unique: a replayed
|
|
-- webhook-id is answered from here without sending again.
|
|
CREATE TABLE IF NOT EXISTS hook_deliveries (
|
|
id UUID PRIMARY KEY,
|
|
project_id UUID NOT NULL REFERENCES hook_projects(id) ON DELETE CASCADE,
|
|
webhook_id TEXT NOT NULL,
|
|
action_type TEXT NOT NULL,
|
|
recipients TEXT[] NOT NULL,
|
|
email_ids TEXT[] NOT NULL DEFAULT '{}',
|
|
status TEXT NOT NULL,
|
|
error TEXT,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
UNIQUE (project_id, webhook_id)
|
|
);
|
|
CREATE INDEX IF NOT EXISTS hook_deliveries_project_idx
|
|
ON hook_deliveries (project_id, created_at DESC);
|