diff --git a/src/integrations/supabase/types.ts b/src/integrations/supabase/types.ts index 0476004..de7924c 100644 --- a/src/integrations/supabase/types.ts +++ b/src/integrations/supabase/types.ts @@ -2993,6 +2993,67 @@ export type Database = { }, ] } + task_reminders: { + Row: { + created_at: string + created_by: string | null + id: string + note: string | null + recipient_email: string + recipient_user_id: string | null + remind_at: string + sent_at: string | null + task_id: string + updated_at: string + } + Insert: { + created_at?: string + created_by?: string | null + id?: string + note?: string | null + recipient_email: string + recipient_user_id?: string | null + remind_at: string + sent_at?: string | null + task_id: string + updated_at?: string + } + Update: { + created_at?: string + created_by?: string | null + id?: string + note?: string | null + recipient_email?: string + recipient_user_id?: string | null + remind_at?: string + sent_at?: string | null + task_id?: string + updated_at?: string + } + Relationships: [ + { + foreignKeyName: "task_reminders_created_by_fkey" + columns: ["created_by"] + isOneToOne: false + referencedRelation: "profiles" + referencedColumns: ["id"] + }, + { + foreignKeyName: "task_reminders_recipient_user_id_fkey" + columns: ["recipient_user_id"] + isOneToOne: false + referencedRelation: "profiles" + referencedColumns: ["id"] + }, + { + foreignKeyName: "task_reminders_task_id_fkey" + columns: ["task_id"] + isOneToOne: false + referencedRelation: "tasks" + referencedColumns: ["id"] + }, + ] + } tasks: { Row: { case_id: string | null diff --git a/supabase/migrations/20260423213112_c6553e42-f949-41a7-be6f-13f5ae9f987b.sql b/supabase/migrations/20260423213112_c6553e42-f949-41a7-be6f-13f5ae9f987b.sql new file mode 100644 index 0000000..9f2926c --- /dev/null +++ b/supabase/migrations/20260423213112_c6553e42-f949-41a7-be6f-13f5ae9f987b.sql @@ -0,0 +1,54 @@ +CREATE TABLE public.task_reminders ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + task_id uuid NOT NULL REFERENCES public.tasks(id) ON DELETE CASCADE, + recipient_email text NOT NULL, + recipient_user_id uuid REFERENCES public.profiles(id), + remind_at timestamptz NOT NULL, + note text, + sent_at timestamptz, + created_by uuid REFERENCES public.profiles(id), + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now() +); + +CREATE INDEX task_reminders_due_idx ON public.task_reminders (remind_at) WHERE sent_at IS NULL; +CREATE INDEX task_reminders_task_id_idx ON public.task_reminders (task_id); + +CREATE TRIGGER task_reminders_set_updated_at +BEFORE UPDATE ON public.task_reminders +FOR EACH ROW EXECUTE FUNCTION public.tg_set_updated_at(); + +ALTER TABLE public.task_reminders ENABLE ROW LEVEL SECURITY; + +CREATE POLICY "view task reminders if task accessible" +ON public.task_reminders FOR SELECT +TO authenticated +USING (public.can_access_task(task_id, auth.uid())); + +CREATE POLICY "creator or admin can insert task reminders" +ON public.task_reminders FOR INSERT +TO authenticated +WITH CHECK ( + public.can_access_task(task_id, auth.uid()) + AND created_by = auth.uid() +); + +CREATE POLICY "creator or admin can update task reminders" +ON public.task_reminders FOR UPDATE +TO authenticated +USING ( + public.is_admin(auth.uid()) + OR created_by = auth.uid() +) +WITH CHECK ( + public.is_admin(auth.uid()) + OR created_by = auth.uid() +); + +CREATE POLICY "creator or admin can delete task reminders" +ON public.task_reminders FOR DELETE +TO authenticated +USING ( + public.is_admin(auth.uid()) + OR created_by = auth.uid() +); \ No newline at end of file