Files
supabase/examples/todo/db/task_list_schema.sql
T

45 lines
1.4 KiB
SQL

create table lists (
id bigint generated by default as identity primary key,
name text not null,
user_id uuid references auth.users not null,
inserted_at timestamp with time zone default timezone('utc'::text, now()) not null
);
create table tasks (
id bigint generated by default as identity primary key,
task_text text not null,
complete boolean default false,
list_id bigint REFERENCES lists not null,
inserted_at timestamp with time zone default timezone('utc'::text, now()) not null
);
alter table lists enable row level security;
alter table tasks enable row level security;
create policy "Individuals can create lists." on lists for
insert with check (auth.uid() = user_id);
create policy "Individuals can view their own lists. " on lists for
select using (auth.uid() = user_id);
create policy "Individuals can update their own lists." on lists for
update using (auth.uid() = user_id);
create policy "Individuals can create tasks in their own lists." on tasks for
insert with check (
list_id in (
select id
from lists
where user_id = auth.uid()
)
);
create policy "Individuals can view tasks that exist in one of their lists." on tasks for
select using (
list_id in (
select id
from lists
where user_id = auth.uid()
)
);
create policy "Individuals can update their own tasks." on tasks for
update using (
list_id in (
select id
from lists
where user_id = auth.uid()
)
);