Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions supabase/migrations/20231212232610_create_hackathons_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
create table "public"."hackathons" (
"id" bigint generated by default as identity not null,
"created_at" timestamp with time zone default now(),
"title" text,
"description" text
);


alter table "public"."hackathons" enable row level security;

CREATE UNIQUE INDEX hackathons_pkey ON public.hackathons USING btree (id);

alter table "public"."hackathons" add constraint "hackathons_pkey" PRIMARY KEY using index "hackathons_pkey";
alter table "public"."hackathons" add column "updated_at" timestamp with time zone default now();
26 changes: 26 additions & 0 deletions supabase/migrations/20231212235012_create_user_roles_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CREATE TYPE user_role AS ENUM ('admin', 'event_coordinator', 'participant');

create table "public"."user_roles" (
"id" bigint generated by default as identity not null
);

alter table "public"."user_roles" add column "role" user_role default 'participant'::user_role;

alter table "public"."user_roles" add column "user_id" uuid;

alter table "public"."user_roles" enable row level security;

CREATE UNIQUE INDEX user_roles_pkey ON public.user_roles USING btree (id);

alter table "public"."user_roles" add constraint "user_roles_pkey" PRIMARY KEY using index "user_roles_pkey";

alter table "public"."user_roles" add constraint "user_roles_user_id_fkey" FOREIGN KEY (user_id) REFERENCES profiles(id) not valid;

alter table "public"."user_roles" validate constraint "user_roles_user_id_fkey";

create policy "Enable read access for user owned roles"
on "public"."user_roles"
as permissive
for select
to public
using ((auth.uid() = user_id));
38 changes: 38 additions & 0 deletions supabase/migrations/20231213001948_create_participants_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
create table "public"."hackathons_participants" (
"user_id" uuid not null,
"hackathon_id" bigint not null
);


alter table "public"."hackathons_participants" enable row level security;

create table "public"."participants" (
"id" bigint generated by default as identity not null,
"created_at" timestamp with time zone default now(),
"user_id" uuid
);


alter table "public"."participants" enable row level security;

alter table "public"."profiles" add column "bio" text;

CREATE UNIQUE INDEX hackathons_participants_pkey ON public.hackathons_participants USING btree (user_id, hackathon_id);

CREATE UNIQUE INDEX participants_pkey ON public.participants USING btree (id);

alter table "public"."hackathons_participants" add constraint "hackathons_participants_pkey" PRIMARY KEY using index "hackathons_participants_pkey";

alter table "public"."participants" add constraint "participants_pkey" PRIMARY KEY using index "participants_pkey";

alter table "public"."hackathons_participants" add constraint "hackathons_participants_hackathon_id_fkey" FOREIGN KEY (hackathon_id) REFERENCES hackathons(id) not valid;

alter table "public"."hackathons_participants" validate constraint "hackathons_participants_hackathon_id_fkey";

alter table "public"."hackathons_participants" add constraint "hackathons_participants_user_id_fkey" FOREIGN KEY (user_id) REFERENCES profiles(id) not valid;

alter table "public"."hackathons_participants" validate constraint "hackathons_participants_user_id_fkey";

alter table "public"."participants" add constraint "participants_user_id_fkey" FOREIGN KEY (user_id) REFERENCES profiles(id) not valid;

alter table "public"."participants" validate constraint "participants_user_id_fkey";
27 changes: 27 additions & 0 deletions supabase/migrations/20231213004446_update_rls_hackathons.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
create policy "Enable insert for authenticated users with admin/event_co role"
on "public"."hackathons"
as permissive
for insert
to authenticated
with check ((auth.uid() IN ( SELECT user_roles.user_id
FROM user_roles
WHERE ((user_roles.role = 'admin'::user_role) OR (user_roles.role = 'event_coordinator'::user_role)))));


create policy "Enable read access for all users"
on "public"."hackathons"
as permissive
for select
to public
using (true);


create policy "Enable update for authenticated users with admin/event_co role"
on "public"."hackathons"
as permissive
for update
to authenticated
using ((auth.uid() IN ( SELECT user_roles.user_id
FROM user_roles
WHERE ((user_roles.role = 'admin'::user_role) OR (user_roles.role = 'event_coordinator'::user_role)))))
with check (true);