sqlnode.jstypescriptormprisma

How to split Prisma Model into separate file?


I'm learning Prisma ORM from video tutorials and official docs. They are explain and write All model code in one file called schema.prisma. It's ok but, when application grow it became messy. So, how should I separate my Model definition into separate file?


Solution

  • Starting from Prisma 5.15 this can be done without any external tools, please see the following blog post.

    Sample project

    Briefly, all you need to do is:

    1. In your schema.prisma file - make sure you have this feature enabled as follows:

      generator client {
        provider        = "prisma-client-js"
        previewFeatures = ["prismaSchemaFolder"]
      }
      
    2. Create a dir named schema under your prisma directory

    3. Move your schema.prisma file into that directory. You should now be able to create more .prisma files in there and define your models. It all gets hooked up automatically, no need to import anything.