Skip to main content

max / goingson

647 B · 14 lines History Blame Raw
1 -- Email threading support
2 -- Add In-Reply-To and References headers for conversation tracking
3
4 -- Add threading fields to emails table
5 ALTER TABLE emails ADD COLUMN in_reply_to TEXT;
6 ALTER TABLE emails ADD COLUMN thread_id TEXT;
7
8 -- Index for efficient thread lookups
9 CREATE INDEX IF NOT EXISTS idx_emails_thread ON emails(thread_id) WHERE thread_id IS NOT NULL;
10 CREATE INDEX IF NOT EXISTS idx_emails_in_reply_to ON emails(in_reply_to) WHERE in_reply_to IS NOT NULL;
11
12 -- Backfill thread_id from message_id for existing emails (they become thread roots)
13 UPDATE emails SET thread_id = message_id WHERE message_id IS NOT NULL AND thread_id IS NULL;
14