Can i create multiple schema in prisma for each model?

Viewed 836

This is a default structure of prisma schema...

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

model User {
  id Int  @id @default(autoincrement())
  username String @unique @db.VarChar(255)
  role UserRole @default(admin)
  posts Post[]
}

model Post {
  id Int @id @default(autoincrement())
  title String 
  post String @db.VarChar(500)
  created_at DateTime @default(now())
  updated_at DateTime @updatedAt
  user_id Int
  user User @relation(fields: [user_id], references: [id])
}

//custom enums
enum UserRole {
  client
  admin
}

I want to create multiple schema for each models. User schema for user model, Post schema for post model. Like we use models in mongoose. Is it possible in Prisma ORM?

2 Answers

Since Prisma hasn't introduced any solution for this matter yet, used this awesome package Prismix and solved the issue. Thanks, everyone!

Yes, We Can create multiple schemas for each model.

Related