Fuxi/supabase/migrations/20231210135930_challenges.sql
2023-12-12 20:20:36 +08:00

36 lines
1.1 KiB
SQL

create table public.challenges
(
id bigint generated by default as identity,
answers jsonb not null,
details jsonb not null,
author uuid not null,
problem int8 not null,
status varchar(256) not null,
created_at timestamp with time zone null default now(),
constraint challenges_pkey primary key (id),
constraint challenges_author_fkey foreign key (author) references auth.users (id),
constraint challenges_problem_fkey foreign key (problem) references public.problems (id)
) tablespace pg_default;
alter table public.challenges enable row level security;
create
policy "Enable insert for everyone" on "public"."challenges"
as permissive for insert
to public
with check (true);
create
policy "Enable read access for users' own items" on "public"."challenges"
as permissive for
select
to public
using (author = auth.uid());
create
policy "Enable update access for users' own items" on "public"."challenges"
as permissive for
update
to public
using (author = auth.uid() and status = 'in-progress')
with check (author = auth.uid())