【问题标题】:Prevent Postgres column to be EMPTY using supabase & prisma使用 supabase 和 prisma 防止 Postgres 列为 EMPTY
【发布时间】:2022-12-30 22:53:24
【问题描述】:

我已经使用 Prisma & Supabase 开始了一个新项目,但我遇到了一个问题。

我有一些必需的字符串列。有没有办法阻止这些列接受空字符串值 ('')。

你知道这是否可以在 prisma 模式级别完成(我猜这是最好的选择)?或者使用 supabase RLS 策略?

【问题讨论】:

  • alter table test add constraint disallow_empty_that_column check(that_column<>'');
  • 可以接受NULL,@BghinC 吗?只是空字符串是问题吗?

标签: postgresql prisma check-constraints supabase


【解决方案1】:

您可以使用 check 约束来实现:

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

您可以对 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

【讨论】:

    猜你喜欢
    • 2022-01-10
    • 2020-01-30
    • 2023-02-19
    • 2019-05-10
    • 2021-11-15
    • 2021-10-08
    • 2022-11-21
    • 1970-01-01
    • 2012-12-29
    相关资源
    最近更新 更多