Is your feature request related to a problem? Please describe.
Currently, it is not possible to describe partial indexes/unique constraint in the model itself, requiring external sql migration file.
This feature would allow for unique email for accounts that are active for example, or index only records created after a certain date, index active tasks only or allow for better soft deletion flexibility.
Describe the solution you'd like
model User {
id String @id
accountId String
status String
email String
deletedAt DateTime?
// Unique active emails per account (exclude soft-deleted)
@@unique([accountId, email], where: { deletedAt: null })
// Index only active or pending account
@@index([accountId, status], where: { status: { in: ["pending", "active"] } })
// Sparse index, only index rows where field is non-null
@@index([accountId, email], where: { email: { not: null } })
}
Additional context
Add any other context or screenshots about the feature request here.