Move push notification to client instead of db trigger

This commit is contained in:
2026-02-28 16:19:08 +08:00
parent dab43a7f30
commit 0a8e388757
8 changed files with 698 additions and 226 deletions
@@ -0,0 +1,20 @@
-- Create a table to record which notifications have been pushed by the edge function
CREATE TABLE IF NOT EXISTS public.notification_pushes (
notification_id uuid PRIMARY KEY,
pushed_at timestamptz NOT NULL DEFAULT now()
);
-- Helper function: try to mark a notification as pushed. Returns true if the
-- insert succeeded (i.e. this notification was not previously pushed), false
-- if it already existed.
CREATE OR REPLACE FUNCTION public.try_mark_notification_pushed(p_notification_id uuid)
RETURNS boolean LANGUAGE plpgsql AS $$
BEGIN
INSERT INTO public.notification_pushes(notification_id) VALUES (p_notification_id)
ON CONFLICT DO NOTHING;
RETURN FOUND; -- true if insert happened, false if ON CONFLICT prevented insert
END;
$$;
-- index for quick lookup by pushed_at if needed
CREATE INDEX IF NOT EXISTS idx_notification_pushes_pushed_at ON public.notification_pushes(pushed_at);