Repository navigation
Expand file tree
/
Copy pathsupabase-setup.sql
More file actions
53 lines (45 loc) · 2.06 KB
/
Copy pathsupabase-setup.sql
File metadata and controls
53 lines (45 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- ============================================================
-- Dispatch Rush · Arena — Supabase setup
-- Run this once in your Supabase project:
-- Supabase Dashboard → SQL Editor → New query → paste → Run
-- ============================================================
-- 1) Leaderboard table
create table if not exists public.scores (
id bigint generated always as identity primary key,
name text not null check (char_length(name) between 1 and 24),
score integer not null check (score >= 0 and score <= 100000),
jobs integer not null default 0 check (jobs >= 0 and jobs <= 1000),
efficiency integer not null default 0 check (efficiency between 0 and 100),
created_at timestamptz not null default now()
);
create index if not exists scores_score_idx on public.scores (score desc, created_at asc);
-- 2) Row-Level Security: anonymous visitors may READ all scores and
-- INSERT their own — but never UPDATE or DELETE. The CHECK on insert
-- re-validates the payload server-side so a tampered client can't
-- write junk or huge values.
alter table public.scores enable row level security;
drop policy if exists "arena read scores" on public.scores;
drop policy if exists "arena insert scores" on public.scores;
create policy "arena read scores"
on public.scores for select
to anon
using (true);
create policy "arena insert scores"
on public.scores for insert
to anon
with check (
char_length(name) between 1 and 24
and score between 0 and 100000
and jobs between 0 and 1000
and efficiency between 0 and 100
);
-- 3) Let the Hall of Fame update in real time when a new score lands.
-- (Presence — "who's playing now" — needs no table; it's handled by
-- Supabase Realtime channels in the app.)
do $$ begin
alter publication supabase_realtime add table public.scores;
exception when duplicate_object then null;
end $$;
-- Done. Copy your Project URL + anon key from
-- Project Settings → API → Project URL / Project API keys (anon public)
-- into config.js.