max / goingson
| 1 | -- Email threading support |
| 2 | -- Add In-Reply-To and References headers for conversation tracking |
| 3 | |
| 4 | -- Add threading fields to emails table |
| 5 | emails ADD COLUMN in_reply_to TEXT; |
| 6 | emails ADD COLUMN thread_id TEXT; |
| 7 | |
| 8 | -- Index for efficient thread lookups |
| 9 | NOT EXISTS idx_emails_thread ON emails(thread_id) WHERE thread_id IS NOT NULL; |
| 10 | 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 |