prisma / prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
https://www.prisma.io
Apache License 2.0
38.82k stars 1.52k forks source link

schema.prisma Model Extensions #3520

Closed dilizarov closed 4 years ago

dilizarov commented 4 years ago

Problem

All my models include some basic columns. I'd like to be able to simplify this normalized process in my workflow instead of copying these columns over for every model.

Suggested solution

Model extensions. Maybe something like this:

abstract model Basics {
  id        Int       @id @default(autoincrement())
  updatedAt DateTime  @updatedAt
  createdAt DateTime  @default(now())
}

model User extends Basics {
  email String @unique
}

model Task extends Basics {
  title String
}

In the above, I created the idea of an abstract model which won't create a table in the database, and is made for the explicit purpose of extension.

Instead of abstract model, we could even call it an extension to simplify parsing and keep it as a uniform single word.

The User and Task models will have their respective DB tables include id, updatedAt and createdAt fields.

Alternatives

Aside from copy and pasting the Basics into every single model, I don't know of another way to achieve the above.

pantharshit00 commented 4 years ago

Hi,

Thanks for reporting this! It has already been reported before, so I am going to close this as a duplicate of https://github.com/prisma/prisma/issues/2371

I have posted your proposal there.

broisnischal commented 7 months ago

any updates on this?