diff --git a/src/integrations/supabase/types.ts b/src/integrations/supabase/types.ts index cf66644..aa50265 100644 --- a/src/integrations/supabase/types.ts +++ b/src/integrations/supabase/types.ts @@ -1771,6 +1771,42 @@ export type Database = { } Relationships: [] } + import_runs: { + Row: { + created_at: string + error_count: number + id: string + importer_key: string + inserted: number + ran_at: string + ran_by: string | null + skipped: number + total: number + } + Insert: { + created_at?: string + error_count?: number + id?: string + importer_key: string + inserted?: number + ran_at?: string + ran_by?: string | null + skipped?: number + total?: number + } + Update: { + created_at?: string + error_count?: number + id?: string + importer_key?: string + inserted?: number + ran_at?: string + ran_by?: string | null + skipped?: number + total?: number + } + Relationships: [] + } incoming_emails: { Row: { attachment_count: number diff --git a/supabase/migrations/20260419010828_bf9aa428-7c1f-410d-ab4a-9b2ce8c81254.sql b/supabase/migrations/20260419010828_bf9aa428-7c1f-410d-ab4a-9b2ce8c81254.sql new file mode 100644 index 0000000..91af866 --- /dev/null +++ b/supabase/migrations/20260419010828_bf9aa428-7c1f-410d-ab4a-9b2ce8c81254.sql @@ -0,0 +1,24 @@ +CREATE TABLE public.import_runs ( + id uuid NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY, + importer_key text NOT NULL, + total integer NOT NULL DEFAULT 0, + inserted integer NOT NULL DEFAULT 0, + skipped integer NOT NULL DEFAULT 0, + error_count integer NOT NULL DEFAULT 0, + ran_by uuid, + ran_at timestamptz NOT NULL DEFAULT now(), + created_at timestamptz NOT NULL DEFAULT now() +); + +CREATE INDEX idx_import_runs_key_ran_at ON public.import_runs (importer_key, ran_at DESC); + +ALTER TABLE public.import_runs ENABLE ROW LEVEL SECURITY; + +CREATE POLICY "import_runs_select_auth" ON public.import_runs + FOR SELECT TO authenticated USING (true); + +CREATE POLICY "import_runs_insert_auth" ON public.import_runs + FOR INSERT TO authenticated WITH CHECK (auth.uid() IS NOT NULL); + +CREATE POLICY "import_runs_delete_admin" ON public.import_runs + FOR DELETE TO authenticated USING (public.is_admin(auth.uid())); \ No newline at end of file