Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-23 21:31:16 +00:00
co-authored by renee-png
parent 208779fb48
commit 5322453341
2 changed files with 115 additions and 0 deletions
@@ -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()
);