Added IMAP polling infra
X-Lovable-Edit-ID: edt-c3e26cfd-d954-46c3-9e2f-b76d4163d970 Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
@@ -1290,6 +1290,126 @@ export type Database = {
|
||||
},
|
||||
]
|
||||
}
|
||||
imap_settings: {
|
||||
Row: {
|
||||
created_at: string
|
||||
enabled: boolean
|
||||
folder: string
|
||||
host: string
|
||||
id: string
|
||||
last_error: string | null
|
||||
last_polled_at: string | null
|
||||
last_uid: number | null
|
||||
notes: string | null
|
||||
port: number
|
||||
secure: boolean
|
||||
updated_at: string
|
||||
updated_by: string | null
|
||||
username: string
|
||||
}
|
||||
Insert: {
|
||||
created_at?: string
|
||||
enabled?: boolean
|
||||
folder?: string
|
||||
host: string
|
||||
id?: string
|
||||
last_error?: string | null
|
||||
last_polled_at?: string | null
|
||||
last_uid?: number | null
|
||||
notes?: string | null
|
||||
port?: number
|
||||
secure?: boolean
|
||||
updated_at?: string
|
||||
updated_by?: string | null
|
||||
username: string
|
||||
}
|
||||
Update: {
|
||||
created_at?: string
|
||||
enabled?: boolean
|
||||
folder?: string
|
||||
host?: string
|
||||
id?: string
|
||||
last_error?: string | null
|
||||
last_polled_at?: string | null
|
||||
last_uid?: number | null
|
||||
notes?: string | null
|
||||
port?: number
|
||||
secure?: boolean
|
||||
updated_at?: string
|
||||
updated_by?: string | null
|
||||
username?: string
|
||||
}
|
||||
Relationships: []
|
||||
}
|
||||
incoming_emails: {
|
||||
Row: {
|
||||
attachment_count: number
|
||||
body_html: string | null
|
||||
body_text: string | null
|
||||
case_id: string | null
|
||||
cc_addresses: string[]
|
||||
created_at: string
|
||||
from_address: string | null
|
||||
from_name: string | null
|
||||
has_attachments: boolean
|
||||
id: string
|
||||
imap_uid: number | null
|
||||
is_archived: boolean
|
||||
is_read: boolean
|
||||
message_id: string | null
|
||||
notes: string | null
|
||||
raw_size_bytes: number | null
|
||||
received_at: string
|
||||
snippet: string | null
|
||||
subject: string | null
|
||||
to_addresses: string[]
|
||||
}
|
||||
Insert: {
|
||||
attachment_count?: number
|
||||
body_html?: string | null
|
||||
body_text?: string | null
|
||||
case_id?: string | null
|
||||
cc_addresses?: string[]
|
||||
created_at?: string
|
||||
from_address?: string | null
|
||||
from_name?: string | null
|
||||
has_attachments?: boolean
|
||||
id?: string
|
||||
imap_uid?: number | null
|
||||
is_archived?: boolean
|
||||
is_read?: boolean
|
||||
message_id?: string | null
|
||||
notes?: string | null
|
||||
raw_size_bytes?: number | null
|
||||
received_at?: string
|
||||
snippet?: string | null
|
||||
subject?: string | null
|
||||
to_addresses?: string[]
|
||||
}
|
||||
Update: {
|
||||
attachment_count?: number
|
||||
body_html?: string | null
|
||||
body_text?: string | null
|
||||
case_id?: string | null
|
||||
cc_addresses?: string[]
|
||||
created_at?: string
|
||||
from_address?: string | null
|
||||
from_name?: string | null
|
||||
has_attachments?: boolean
|
||||
id?: string
|
||||
imap_uid?: number | null
|
||||
is_archived?: boolean
|
||||
is_read?: boolean
|
||||
message_id?: string | null
|
||||
notes?: string | null
|
||||
raw_size_bytes?: number | null
|
||||
received_at?: string
|
||||
snippet?: string | null
|
||||
subject?: string | null
|
||||
to_addresses?: string[]
|
||||
}
|
||||
Relationships: []
|
||||
}
|
||||
invoice_line_items: {
|
||||
Row: {
|
||||
amount: number
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
-- IMAP settings (single-row config for incoming mail)
|
||||
CREATE TABLE IF NOT EXISTS public.imap_settings (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
host text NOT NULL,
|
||||
port integer NOT NULL DEFAULT 993,
|
||||
secure boolean NOT NULL DEFAULT true,
|
||||
username text NOT NULL,
|
||||
folder text NOT NULL DEFAULT 'INBOX',
|
||||
enabled boolean NOT NULL DEFAULT true,
|
||||
last_uid bigint,
|
||||
last_polled_at timestamptz,
|
||||
last_error text,
|
||||
notes text,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_by uuid
|
||||
);
|
||||
|
||||
ALTER TABLE public.imap_settings ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
DROP POLICY IF EXISTS imap_settings_select ON public.imap_settings;
|
||||
CREATE POLICY imap_settings_select ON public.imap_settings
|
||||
FOR SELECT TO authenticated USING (true);
|
||||
|
||||
DROP POLICY IF EXISTS imap_settings_insert ON public.imap_settings;
|
||||
CREATE POLICY imap_settings_insert ON public.imap_settings
|
||||
FOR INSERT TO authenticated WITH CHECK (public.is_admin(auth.uid()));
|
||||
|
||||
DROP POLICY IF EXISTS imap_settings_update ON public.imap_settings;
|
||||
CREATE POLICY imap_settings_update ON public.imap_settings
|
||||
FOR UPDATE TO authenticated USING (public.is_admin(auth.uid()));
|
||||
|
||||
DROP POLICY IF EXISTS imap_settings_delete ON public.imap_settings;
|
||||
CREATE POLICY imap_settings_delete ON public.imap_settings
|
||||
FOR DELETE TO authenticated USING (public.is_admin(auth.uid()));
|
||||
|
||||
-- Incoming emails
|
||||
CREATE TABLE IF NOT EXISTS public.incoming_emails (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
message_id text,
|
||||
imap_uid bigint,
|
||||
received_at timestamptz NOT NULL DEFAULT now(),
|
||||
from_address text,
|
||||
from_name text,
|
||||
to_addresses text[] NOT NULL DEFAULT '{}',
|
||||
cc_addresses text[] NOT NULL DEFAULT '{}',
|
||||
subject text,
|
||||
body_text text,
|
||||
body_html text,
|
||||
snippet text,
|
||||
has_attachments boolean NOT NULL DEFAULT false,
|
||||
attachment_count integer NOT NULL DEFAULT 0,
|
||||
raw_size_bytes integer,
|
||||
is_read boolean NOT NULL DEFAULT false,
|
||||
is_archived boolean NOT NULL DEFAULT false,
|
||||
case_id uuid,
|
||||
notes text,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
UNIQUE (message_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS incoming_emails_received_at_idx ON public.incoming_emails (received_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS incoming_emails_is_read_idx ON public.incoming_emails (is_read);
|
||||
CREATE INDEX IF NOT EXISTS incoming_emails_case_id_idx ON public.incoming_emails (case_id);
|
||||
CREATE INDEX IF NOT EXISTS incoming_emails_imap_uid_idx ON public.incoming_emails (imap_uid);
|
||||
|
||||
ALTER TABLE public.incoming_emails ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
DROP POLICY IF EXISTS incoming_emails_select ON public.incoming_emails;
|
||||
CREATE POLICY incoming_emails_select ON public.incoming_emails
|
||||
FOR SELECT TO authenticated USING (true);
|
||||
|
||||
DROP POLICY IF EXISTS incoming_emails_insert ON public.incoming_emails;
|
||||
CREATE POLICY incoming_emails_insert ON public.incoming_emails
|
||||
FOR INSERT TO authenticated WITH CHECK (auth.uid() IS NOT NULL);
|
||||
|
||||
DROP POLICY IF EXISTS incoming_emails_update ON public.incoming_emails;
|
||||
CREATE POLICY incoming_emails_update ON public.incoming_emails
|
||||
FOR UPDATE TO authenticated USING (auth.uid() IS NOT NULL);
|
||||
|
||||
DROP POLICY IF EXISTS incoming_emails_delete ON public.incoming_emails;
|
||||
CREATE POLICY incoming_emails_delete ON public.incoming_emails
|
||||
FOR DELETE TO authenticated USING (public.is_admin(auth.uid()));
|
||||
Reference in New Issue
Block a user