-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
domain/clientIssue in the "Client" domain: Prisma Client, Prisma Studio etc.Issue in the "Client" domain: Prisma Client, Prisma Studio etc.domain/pslIssue in the "PSL" domain: Prisma Schema LanguageIssue in the "PSL" domain: Prisma Schema Languagekind/featureA request for a new feature.A request for a new feature.topic: schema
Description
Problem
Unions data types are handy in features like feeds. Right now it's difficult to model unions in Prisma and it would be great if we could make this feature higher-level.
You'll also find community use cases in this thread.
Possible solution
Facebook's feed is a good example. The feed has Videos, Photos and Posts.
Modeled in Typescript
type Activity = Video | Photo | Message
type Video = {
type: 'video'
url: string
media: 'webm' | 'mp4'
}
type Photo = {
type: 'photo'
width: number
height: number
}
type Post = {
type: 'post'
message: string
}
Modeled in Postgres
create sequence bigserial activity_id;
create table videos (
id activity_id primary key,
url text not null,
media text not null
)
create table photos (
id activity_id primary key,
width int,
height int
)
create table posts (
id activity_id primary key,
message text
)
Alternatives
There are lots of alternative table inheritance schemes. We'd need to weigh the pros and cons of each.
allistercsmith, ManAnRuck, aflatter, kafein, ledniy and 444 moreManAnRuck, znicholasbrown, husayt, nickreynke, ZenSoftware and 111 moreManAnRuck, aflatter, jorgenskogas, znicholasbrown, cometkim and 98 more
Metadata
Metadata
Assignees
Labels
domain/clientIssue in the "Client" domain: Prisma Client, Prisma Studio etc.Issue in the "Client" domain: Prisma Client, Prisma Studio etc.domain/pslIssue in the "PSL" domain: Prisma Schema LanguageIssue in the "PSL" domain: Prisma Schema Languagekind/featureA request for a new feature.A request for a new feature.topic: schema