update promo
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
CREATE TABLE IF NOT EXISTS public.visitor_stats (
|
||||
id text PRIMARY KEY,
|
||||
count bigint NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
INSERT INTO public.visitor_stats (id, count)
|
||||
VALUES ('global', 0)
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.increment_visitor()
|
||||
RETURNS bigint
|
||||
LANGUAGE sql
|
||||
AS $$
|
||||
UPDATE public.visitor_stats
|
||||
SET count = count + 1
|
||||
WHERE id = 'global'
|
||||
RETURNING count;
|
||||
$$;
|
||||
|
||||
ALTER TABLE public.visitor_stats ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
CREATE POLICY visitor_stats_select ON public.visitor_stats
|
||||
FOR SELECT TO anon
|
||||
USING (true);
|
||||
|
||||
GRANT SELECT ON public.visitor_stats TO anon;
|
||||
GRANT EXECUTE ON FUNCTION public.increment_visitor() TO anon, authenticated;
|
||||
Reference in New Issue
Block a user