-
Notifications
You must be signed in to change notification settings - Fork 301
Closed
Description
Persistent version: 2.7.1 (lts-9.17)
Behavior
Explicit composite primary keys do not imply uniqueness, leading to runtime exceptions when attempting upserts. This behavior is unexpected when using the Postgres backend.
Expectation
Postgres primary keys imply uniqueness (or upsert's Unique dependency is verified at compile time).
Example
Model:
User sql=users
Id UUID default=uuid_generate_v4
email Email sqltype=text
UniqueEmail email
deriving Show Eq Typeable
Project json sql=projects
Id UUID default=uuid_generate_v4
name Text
UniqueProject name
deriving Show Eq Typeable
UserProjectVote sql=user_project_votes
userId UserId
projectId ProjectId
vote Int
UniqueUserProjectVote userId projectId -- this line is required
Primary userId projectId
deriving Show Eq Typeable
Yields this exception when the UniqueUserProjectVote line is omitted:
> upsert (UserProjectVote userId projectId 3) [UserProjectVoteVote +=. 1]
uncaught exception: IOException of type UserError (user error (getByValue: UserProjectVote does not have any Unique))Reactions are currently unavailable