1

I've started a new project using Prisma & Supabase but I'm facing an issue.

I have some required String columns. Is there a way to prevent those columns to accept empty string value ('').

Do you know if this can be done at the prisma schema level (this would be the best option I guess)? Or using subapase RLS policies?

BghinC
  • 101
  • 1
  • 11

1 Answers1

1

You can achieve that with a check constraint:

alter table my_table 
add constraint disallow_empty_in_that_column check(that_column<>'');

You can do the same with RLS:

create table test2(a text);
alter table test2 enable row level security;
alter table test2 force row level security;--applies this to table owner as well
create policy disallow_empty_in_that_column on test2 using ( a<>'' );

Online demo

Zegarek
  • 6,424
  • 1
  • 13
  • 24