1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Prisma]PostgreSQLで大文字小文字を区別せずuniqueな制約をつける

Posted at

prisma: 4.7.1
db: PostgreSql(supabase)

prisma使いのみなさんこんにちは。
PostgreSQLでは「大文字」と「小文字」の区別をつけてくれます。
Abc == abc -> false

しかし、unique制約を付ける際に「大文字」「小文字」の区別つけずに重複を許したくない時はあるでしょう。
Abc == abc -> true

幸運なことにpostgreではcitext型というものが用意されています。これをprismaで指定してあげれば実現できるでしょう。

実装

schema.prisma

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["postgresqlExtensions"] // 追加
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
  extensions = [citext] //追加
}

model User {
  email String @unique @db.Citext
}

参考

公式に載っているので正確にはそちらを参照してください。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?