Dự án này đã lâu không có cập nhật mới nên không còn hiển thị trên trang chủ, danh mục hay kết quả tìm kiếm — dữ liệu vẫn được giữ nguyên và trang này vẫn xem được bình thường.
RepositoryTypeScript
joydip007x

joydip007x/Prisma-MultiSchema

Organized Multi-Schema support for Prisma

91sao
4fork
0issue
0lượt xem

NPM NPM Tests NPM Snyk

Prisma: MultiSchema NPM

Prisma normally limits your schema to one file, but with prisma-multischema, you can write multiple prisma schema files in an organized manner without any restrictions.

For Multiple files inter-relation you can import schemas , to manage the relation.

Built using TypeScript to for ES Module and CommonJS (CJS), to Unify Multiple Structured Schemas of Prisma-ORM

Installation

npm i prisma-multischema
yarn add prisma-multischema

Note Using VS Code ? Install Recommended VsCode Extensions from Dependencies (optional)

𝙻𝚎𝚊𝚟𝚎 𝚊 𝚂𝚝𝚊𝚛⭐ 𝚘𝚗 𝚝𝚑𝚎 𝚁𝚎𝚙𝚘 ,𝚒𝚏 𝚢𝚘𝚞 𝚏𝚘𝚞𝚗𝚍 𝚒𝚝 𝚑𝚎𝚕𝚙𝚏𝚞𝚕.
𝚂𝚞𝚙𝚙𝚘𝚛𝚝𝚜 𝚊𝚗𝚍 𝚏𝚎𝚎𝚍𝚋𝚊𝚌𝚔 𝚖𝚎𝚊𝚗𝚜 𝚊 𝚕𝚘𝚝 𝚊𝚗𝚍 𝚎𝚗𝚌𝚘𝚞𝚛𝚊𝚐𝚎𝚜 𝚖𝚎❤️.

Buy Me A Coffee

Usage

  • Place all your schemas in ProjectRoot/prisma/subschemas Folder.
    Like this :

    project_root 
        ├───node_modules
        ├───prisma 
        │   ├───subschemas <<<-----Place all your Schemas here
        │   │   ├───type 
        │   │   │    └───user.types.prisma
        │   │   │    └───bookmark.types.prisma
        │   │   └───user
        │   │   │    └───userData.prisma
        │   │   │    └───validity.prisma
        │   │   ├───anything-you-want.prisma
        │   │   ├───base.prisma  
        |   |   └───...  
        │   └───schema.prisma   <-- will be Auto-Generated
        ├───src
        │   └───...
        ├───package.json
        │        
        └───.gitignore
    

    For Clearer View : Image

  • Run in Terminal

    npx prisma-multischema
    

Project Demonstration

working example is available below -

Example

Let's go with two schemas User and Bookmark on different files ,where the relation is -

  • A User can have many bookmarks
  • Each bookmark has an userId field

base.prisma [ root/prisma/subschemas/base.prisma ]

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

datasource db {
  provider = "mongodb"
  url      = env("PRISMA_DATABASE_URL")
}

user.prisma [ root/prisma/subschemas/User/user.prisma ]

import { Bookmark } from "..\Bookmark\bookmark"
model User {

    id String @id @default(auto()) @map("_id") @db.ObjectId
    email String @unique

    Bookmark Bookmark[]
}
//MongoDB model IDs in prisma -must have a @map("_id") 
//https://www.prisma.io/docs/concepts/components/prisma-schema

bookmark.prisma [ root/prisma/subschemas/Bookmark/bookmark.prisma ]

import {  User } from "..\User\user"
model Bookmark {

    id String     @id  @db.ObjectId @default(auto()) @map("_id") 
    title String
    
    user  User    @relation(fields: [userId], references: [id])
    userId String @db.ObjectId
}

Generated schema.prisma [root/prisma/schema.prisma]
after Running npx prisma-multischema

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

datasource db {
  provider = "mongodb" 
  url      = env("PRISMA_DATABASE_URL")
}

model User {
  id       String     @id @default(auto()) @map("_id") @db.ObjectId
  email    String     @unique
  Bookmark Bookmark[]
}

model Bookmark {
  id          String  @id @default(auto()) @map("_id") @db.ObjectId 
  title       String
  user        User    @relation(fields: [userId], references: [id])
  userId      String  @db.ObjectId
}

https://www.prisma.io/docs

Additional

  • prisma schema files starting with header //#exclude will be excluded in final schema

  • Executing npx prisma-multischema will

    • Automatically run : npx prisma generate
      So, You don't need to update @prisma/client manually, each time the schema updates
    • Automatically run : npx prisma format
      because, Everyone likes clean code
  • Add npx prisma-multischema command as a prefix to your start script in package.json.

    {
    "name": "my-app",
    "version": "1.0.0",
    "scripts": {
        "unify": "npx prisma-multischema",
        "start": "npm run unify && node index.js",
        ...
      }
    }
    


    Now it will run & regenerate Main Schema everytime the project starts.

Dependencies (optional)

To use prisma import feature : (if you are using VS code, its better to use these)

  • Install prisma-import Extension (for VS code)

  • Disable Official prisma Extension (for VS code)

These are Optional Dependencies, If you can maintain multiple *.prisma schemas without TYPO ,you can ignore these.

To-do's

  • Add Support for keeping prisma's in different folder and aggregate them ( like root/src/auth/auth.prisma )

  • Add Command Flags

  • Handle/Remove " Error validating datasource db: " Warning Fixed

Authors - @joydip007x

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryTypeScript
mohammed-bahumaish/prisma-editor

Prisma Editor - A powerful tool to visualize and edit Prisma Schema.

1.0k
Sep 9, 2026
RepositoryTypeScript
graphql-nexus/nexus-prisma

Prisma plugin for Nexus

556
Oct 23, 2026
RepositoryMarkdown
DigitalPlatDev/FreeDomain

Free domain registration and practical DNS learning resources for everyone.

205.9k
Aug 12, 2026
RepositoryPython
yt-dlp/yt-dlp

A feature-rich command-line audio/video downloader

202.5k
Oct 23, 2026
Repository
getify/You-Dont-Know-JS

A book series (2 published editions) on the JS language.

184.8k
Feb 15, 2026
RepositoryPython
521xueweihan/HelloGitHub

:octocat: 分享 GitHub 上有趣、入门级的开源项目。Share interesting, entry-level open source projects on GitHub.

184.7k
Sep 28, 2026
RepositoryTypeScript
calcom/cal.diy

Scheduling infrastructure for absolutely everyone.

49.4k
Oct 26, 2026
RepositoryTypeScript
prisma/orm

The Prisma ORM: write your application in TypeScript with human-readable queries instead of SQL. Host your database on Prisma Postgres and your app on Prisma Compute.

47.7k
Oct 23, 2026
RepositoryTypeScript
trpc/trpc

🧙‍♀️ Move Fast and Break Nothing. End-to-end typesafe APIs made easy.

40.7k
Oct 20, 2026