Keine Challenge ausgewählt
Bereit
00:00:00
Bestzeit: --:--:--
Tasks
Wähle eine Challenge oder erstelle eine neue.
create table if not exists public.challenges (
id text primary key,
room_code text not null,
data jsonb not null,
updated_at timestamptz default now()
);
create index if not exists challenges_room_code_idx on public.challenges (room_code);
alter table public.challenges enable row level security;
grant select, insert, update, delete on public.challenges to anon, authenticated;
drop policy if exists "anon read" on public.challenges;
drop policy if exists "anon insert" on public.challenges;
drop policy if exists "anon update" on public.challenges;
drop policy if exists "anon delete" on public.challenges;
create policy "anon read" on public.challenges for select using (true);
create policy "anon insert" on public.challenges for insert with check (true);
create policy "anon update" on public.challenges for update using (true);
create policy "anon delete" on public.challenges for delete using (true);
do $$ begin
alter publication supabase_realtime add table public.challenges;
exception when duplicate_object then null; end $$;
create table if not exists public.visits (
id bigint generated by default as identity primary key,
ip text,
user_agent text,
created_at timestamptz default now()
);
alter table public.visits enable row level security;
grant select, insert on public.visits to anon, authenticated;
drop policy if exists "anon visits read" on public.visits;
drop policy if exists "anon visits insert" on public.visits;
create policy "anon visits insert" on public.visits for insert with check (true);
-- ERSETZE 'CHANGE_ME_TO_SECRET' durch deinen eigenen Admin-Code:
create or replace function public.get_visits(passcode text)
returns table (id bigint, ip text, user_agent text, created_at timestamptz)
language plpgsql security definer set search_path = public as $$
begin
if passcode = 'CHANGE_ME_TO_SECRET' then
return query select v.id, v.ip, v.user_agent, v.created_at
from public.visits v
order by v.created_at desc limit 100;
end if;
return;
end; $$;
grant execute on function public.get_visits(text) to anon, authenticated;
Hinweis: jeder mit URL + Key + Room-Code kann mitlesen/-schreiben — nimm einen Code, den nur ihr kennt.