Say I wanna create a table with RLS. what do i nee...
# orm-help
v
Say I wanna create a table with RLS. what do i need to do in the schema?
Copy code
create table todos (
  id bigint generated by default as identity primary key,
  user_id uuid references auth.users not null,
  task text check (char_length(task) > 3),
  is_complete boolean default false,
  inserted_at timestamp with time zone default timezone('utc'::text, now()) not null
);
alter table todos enable row level security;
create policy "Individuals can create todos." on todos for
    insert with check (auth.uid() = user_id);
create policy "Individuals can view their own todos. " on todos for
    select using (auth.uid() = user_id);
create policy "Individuals can update their own todos." on todos for
    update using (auth.uid() = user_id);
create policy "Individuals can delete their own todos." on todos for
    delete using (auth.uid() = user_id);
something like this, how to do in prisma?
1
a
Hey @ven v, RLS does not have first-class support in Prisma yet. See this GitHub issue for potential ideas and workarounds and please leave a comment with your use case.
v
Hi @Austin What happens in the case where I create the tables using RLS and do a DB pull? Will prisma be able to detect the RLS? I guess the most relevant use case that comes to mind is that only a user should be able to update/delete any content they create.
a
Prisma will not be able to add the RLS rules to the
schema.prisma
, but it shouldn’t affect any rules that you already have defined in the database.