Make the implicit unique constraints on 1:1 relations explicit #10503
Labels
kind/improvement
An improvement to existing feature and code.
team/client
Issue for team Client.
team/psl-wg
team/schema
Issue for team Schema.
tech/engines/datamodel
Issue about parsing/validation/rendering of the Prisma schema
tech/engines/migration engine
Issue in the Migration Engine
topic: breaking change
topic: indexes
topic: prisma4
topic: relations
topic: schema
Milestone
Problem
The following Prisma schema:
doesn't contain an
@unique
, but if you migrate it, you will have a unique index onb_id
so that it's enforced that the relation is really one-to-one and not one-to-many. If you introspect it, it would become explicit in the schema. This is a very old opinionation. Prisma as a whole has evolved towards more explicitness, less "magic" in the schema to better reflect the reality of the database.This issue is here to propose that we enforce that the backing scalar fields of the relation are covered by a unique constraint, meaning we would validate (and possibly help with autoformatting or code actions) so that the valid schema would be:
This works exactly the same if the relation is backed by multiple scalar fields.
Suggested solution
This is a breaking change, because existing valid Prisma schemas would not pass validation anymore. It can only be released in a new major version.
Alternatives
Additional context
The text was updated successfully, but these errors were encountered: