Last active
April 26, 2022 23:16
-
-
Save amimaro/c39df54adea5b2e9cba1693c13877cd9 to your computer and use it in GitHub Desktop.
Remix tecno-brega-stack setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Create a table for Public Profiles | |
create table profiles ( | |
id uuid references auth.users not null, | |
updated_at timestamp with time zone, | |
username text unique, | |
avatar_url text, | |
website text, | |
primary key (id), | |
unique(username), | |
constraint username_length check (char_length(username) >= 3) | |
); | |
alter table profiles | |
enable row level security; | |
create policy "Public profiles are viewable by everyone." on profiles | |
for select using (true); | |
create policy "Users can insert their own profile." on profiles | |
for insert with check (auth.uid() = id); | |
create policy "Users can update own profile." on profiles | |
for update using (auth.uid() = id); | |
-- Set up Realtime! | |
begin; | |
drop publication if exists supabase_realtime; | |
create publication supabase_realtime; | |
commit; | |
alter publication supabase_realtime | |
add table profiles; | |
-- Set up Storage! | |
insert into storage.buckets (id, name) | |
values ('avatars', 'avatars'); | |
create policy "Avatar images are publicly accessible." on storage.objects | |
for select using (bucket_id = 'avatars'); | |
create policy "Anyone can upload an avatar." on storage.objects | |
for insert with check (bucket_id = 'avatars'); | |
create policy "Anyone can update an avatar." on storage.objects | |
for update with check (bucket_id = 'avatars'); | |
-- Create a table for Notes | |
create table notes ( | |
id uuid default uuid_generate_v4() primary key, | |
created_at timestamp default now(), | |
content text, | |
user_id uuid default uid(), | |
primary key (id), | |
constraint fk_user_id foreign key(user_id) references users(id) | |
); | |
create policy "Enable access only to notes owner" | |
on notes | |
for select using (uid() = user_id); | |
create policy "Enable insert for authenticated users only" | |
on notes | |
for insert with check ( | |
role() = 'authenticated'::text | |
); | |
create policy "Enable update for users based on user_id" | |
on notes | |
for update using (uid() = user_id) with check (uid() = user_id); | |
create policy "Enable delete for users based on user_id" | |
on notes | |
for delete using ( | |
auth.uid() = user_id | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment