Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
67a87d356d
commit
e1514e8d0c
@@ -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