-
Notifications
You must be signed in to change notification settings - Fork 3
feat(migrations): create email_send_log table #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| -- Durable log of every POST /api/emails attempt (recoupable/chat#1829). | ||
| -- | ||
| -- When an empty/footer-only "Message from Recoup" email reached customers, we | ||
| -- could not recover what the API received: malformed bodies were swallowed, the | ||
| -- route logged nothing, and the agent sandbox that built the request is | ||
| -- ephemeral. This records every attempt — sent, send_failed, and rejected | ||
| -- (empty/malformed) — with a copy of the body, | ||
| -- so a send is debuggable several days back. Written by api `logEmailAttempt`. | ||
| -- | ||
| -- Append-only; loose ids, no FKs (like error_logs — a log shouldn't | ||
| -- cascade-delete with accounts, and rejected rows have no ids). Keyed by chat_id | ||
| -- only: chats.session_id reaches the session and sessions.account_id the account, | ||
| -- so session_id would be redundant (and isn't in the /api/emails contract). | ||
| -- account_id is denormalized (free at the API, the main query dimension). | ||
| -- Single responsibility = "what the API was asked to send"; Resend delivery | ||
| -- lifecycle is a future, separate concern keyed off resend_id. | ||
|
|
||
| CREATE TABLE IF NOT EXISTS public.email_send_log ( | ||
| id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
rg -n -i "create extension.*uuid" supabase/migrationsRepository: recoupable/database Length of output: 157 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '--- target migration ---'
cat -n supabase/migrations/20260630210000_create_email_send_log.sql
echo
echo '--- repository search: uuid_generate_v4 / uuid-ossp / gen_random_uuid / create extension ---'
rg -n -i "uuid_generate_v4|uuid-ossp|gen_random_uuid|create extension" .
echo
echo '--- migration files mentioning uuid ---'
rg -n -i "uuid_generate_v4|uuid-ossp|gen_random_uuid|create extension" supabase/migrationsRepository: recoupable/database Length of output: 29884 Add the UUID extension or switch to
🤖 Prompt for AI Agents |
||
| created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), | ||
| account_id UUID, -- sender account (denormalized) | ||
| chat_id TEXT, -- chat the send belongs to (chats.id is text); join chats.session_id for the session | ||
| status TEXT NOT NULL, -- 'sent' | 'send_failed' | 'rejected' | ||
| resend_id TEXT, -- Resend message id (forward hook for delivery events) | ||
| raw_body TEXT, -- the request body as received (full; bounded by the platform request-size limit) | ||
| error TEXT | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS email_send_log_created_at_idx ON public.email_send_log (created_at DESC); | ||
| CREATE INDEX IF NOT EXISTS email_send_log_account_id_idx ON public.email_send_log (account_id); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Enable RLS on email_send_log before merge. Otherwise a public Supabase table containing captured email request bodies may be exposed or mutable through client roles depending on grants/policies.
Prompt for AI agents