c6364d40e6
- Add imap_uid column + unique index for proper deduplication - Use deterministic message_id for emails without Message-ID header - Dedup by (account_id, folder_id, imap_uid) first, message_id fallback - Track folder moves: update folder_id when email appears in different folder - Fix Sent folder lookup: check Sent/INBOX.Sent/Sent Items/Sent Mail + ILIKE - Detect IMAP delimiter from LIST response instead of hardcoding dot - Use detected delimiter in stale folder name migration - Migration 0004_imap_uid.sql with imap_uid column and unique index
6 lines
391 B
SQL
6 lines
391 B
SQL
-- Add imap_uid column to mails table for proper deduplication
|
|
ALTER TABLE mails ADD COLUMN IF NOT EXISTS imap_uid VARCHAR(20);
|
|
CREATE INDEX IF NOT EXISTS ix_mails_imap_uid ON mails(account_id, imap_uid);
|
|
-- Unique constraint to prevent duplicates per folder
|
|
CREATE UNIQUE INDEX IF NOT EXISTS uq_mails_account_folder_uid ON mails(account_id, folder_id, imap_uid) WHERE imap_uid IS NOT NULL;
|