22[ ![ Tests] ( https://github.com/joydip007x/Prisma-MultiSchema/actions/workflows/tests.yml/badge.svg?branch=main )] ( https://github.com/joydip007x/Prisma-MultiSchema/actions/workflows/tests.yml ) [ ![ NPM] ( https://img.shields.io/github/languages/code-size/joydip007x/Prisma-MultiSchema?label=size )] ( https://github.com/joydip007x/Prisma-MultiSchema )
33[ ![ Snyk] ( https://github.com/joydip007x/Prisma-MultiSchema/actions/workflows/snyk.yml/badge.svg?branch=main )] ( https://github.com/joydip007x/Prisma-MultiSchema/actions/workflows/snyk.yml )
44
5- <p align =" center " >
6-
7- <img src =" https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExOTU5NmYyYzI0NGU2NTI4YTUyY2ZjN2IyZjBiY2QzYWIwZmRjMDQ2MCZlcD12MV9pbnRlcm5hbF9naWZzX2dpZklkJmN0PWc/cNWy8aU7WT0V2hwiUy/giphy.gif " >
85
6+ <p align =" center " >
7+ <img media =" (prefers-color-scheme: light) " src =" logo/logoDark.gif#gh-dark-mode-only " />
8+ <img media =" (prefers-color-scheme: dark) " src =" logo/logoLight.gif#gh-light-mode-only " />
99</p >
1010
1111# Prisma: MultiSchema [ ![ NPM] ( https://badgen.net/npm/types/prisma-multischema )] ( https://www.npmjs.com/package/prisma-multischema )
@@ -17,17 +17,211 @@ For Multiple files inter-relation you can import schemas , to manage the relati
1717Built using TypeScript to for ES Module and CommonJS (CJS),
1818to Unify Multiple Structured Schemas of [ Prisma-ORM] ( https://www.prisma.io/ )
1919
20- # Installation
20+ <details open >
21+ <summary >
22+
23+ ### Installation
24+ </summary >
25+ <p align =" center " >
26+
2127```
2228npm i prisma-multischema
2329```
2430```
2531yarn add prisma-multischema
2632```
33+ > ** Note** Using ** VS Code** ? Install Recommended VsCode Extensions from [ Dependencies (optional)] ( https://github.com/joydip007x/Prisma-MultiSchema#dependencies-optional )
34+ </p>
35+ </details>
36+
37+ <details close >
38+ <summary >
39+
40+ ### Usage
41+ </summary >
42+ <p align =" center " >
43+
44+ - #### How to Use Tutorial : 📚[ MediumBlog] ( https://medium.com/@joydip007x/how-to-use-multiple-schema-in-prisma-40cc6b6f8d9c ) || ✨[ YT Link] ( https://youtu.be/4GOuJLvGVko )
45+ - Place all your schemas in ` ProjectRoot/prisma/subschemas ` Folder.<br >
46+ Like this :
47+ ```st
48+ project_root
49+ ├───node_modules
50+ ├───prisma
51+ │ ├───subschemas <<<-----Place all your Schemas here
52+ │ │ ├───type
53+ │ │ │ └───user.types.prisma
54+ │ │ │ └───bookmark.types.prisma
55+ │ │ └───user
56+ │ │ │ └───userData.prisma
57+ │ │ │ └───validity.prisma
58+ │ │ ├───anything-you-want.prisma
59+ │ │ ├───base.prisma
60+ | | └───...
61+ │ └───schema.prisma <-- will be Auto-Generated
62+ ├───src
63+ │ └───...
64+ ├───package.json
65+ │
66+ └───.gitignore
67+ ```
68+ >For Clearer View : [ Image] ( https://i.ibb.co/JnyRhxT/oie-eg-Dr9-Y4ksb-NU.png )
69+
70+
71+ - Run in Terminal
72+ ``` bash
73+ npx prisma-multischema
74+ ```
75+
76+ < /p>
77+ < /details>
78+
79+ < details close >
80+ < summary >
81+
82+ # ## Project Demonstration
83+ < /summary>
84+ < p align=" center" >
85+
86+ working example is available below -
87+ - < b> JavaScript< /b> : [Prisma-MultiSchema-JS-Example](https://github.com/joydip007x/Prisma-MultiSchema-JS-Example)
88+ - < b> TypeScript< /b> : [Prisma-MultiSchema-TS-Example](https://github.com/joydip007x/Prisma-MultiSchema-TS-Example)
89+ < /p>
90+ < /details>
91+ < details close >
92+ < summary >
93+
94+ # ## Example
95+ < /summary>
96+ < p align=" center" >
97+
98+ Let' s go with two schemas <b>User</b> and <b>Bookmark</b> on different files ,where the relation is -
99+ - A User can have many bookmarks
100+ - Each bookmark has an userId field
101+
102+ ><b>base.prisma</b> [ root/prisma/subschemas/base.prisma ]
103+ ```prisma
104+ generator client {
105+ provider = "prisma-client-js"
106+ }
107+
108+ datasource db {
109+ provider = "mongodb"
110+ url = env("PRISMA_DATABASE_URL")
111+ }
112+ ```
113+ ><b>user.prisma</b> [ root/prisma/subschemas/User/user.prisma ]
114+ ```Prisma
115+ import { Bookmark } from "..\Bookmark\bookmark"
116+ model User {
117+
118+ id String @id @default(auto()) @map("_id") @db.ObjectId
119+ email String @unique
120+
121+ Bookmark Bookmark[]
122+ }
123+ //MongoDB model IDs in prisma -must have a @map("_id")
124+ //https://www.prisma.io/docs/concepts/components/prisma-schema
125+ ```
126+ ><b>bookmark.prisma</b> [ root/prisma/subschemas/Bookmark/bookmark.prisma ]
127+ ```Prisma
128+ import { User } from "..\User\user"
129+ model Bookmark {
130+
131+ id String @id @db.ObjectId @default(auto()) @map("_id")
132+ title String
133+
134+ user User @relation(fields: [userId], references: [id])
135+ userId String @db.ObjectId
136+ }
137+ ```
138+ >Generated <b>schema.prisma</b> [root/prisma/schema.prisma]</br>
139+ > after Running `npx prisma-multischema`
140+ ```Prisma
141+ generator client {
142+ provider = "prisma-client-js"
143+ }
144+
145+ datasource db {
146+ provider = "mongodb"
147+ url = env("PRISMA_DATABASE_URL")
148+ }
149+
150+ model User {
151+ id String @id @default(auto()) @map("_id") @db.ObjectId
152+ email String @unique
153+ Bookmark Bookmark[]
154+ }
155+
156+ model Bookmark {
157+ id String @id @default(auto()) @map("_id") @db.ObjectId
158+ title String
159+ user User @relation(fields: [userId], references: [id])
160+ userId String @db.ObjectId
161+ }
162+ ```
163+ >https://www.prisma.io/docs
164+ </p>
165+ </details>
166+
167+ <details >
168+ <summary >
169+
170+ ### Additional
171+ </summary>
172+ <p align="center">
173+
174+ - prisma schema files starting with header `//#exclude` will be excluded in final schema
175+ - Executing `npx prisma-multischema` will
176+ - <b>Automatically run</b> : `npx prisma generate`
177+ <br>So, You don' t need to update ` @prisma/client` manually, each time the schema updates
178+ - < b> Automatically run< /b> : ` npx prisma format`
179+ < br> because, Everyone likes clean code
180+
181+ - Add ` npx prisma-multischema` command as a prefix to your < b> start< /b> script in package.json.
182+ ` ` ` json
183+ {
184+ " name" : " my-app" ,
185+ " version" : " 1.0.0" ,
186+ " scripts" : {
187+ " unify" : " npx prisma-multischema" ,
188+ " start" : " npm run unify && node index.js" ,
189+ ...
190+ }
191+ }
192+ ` ` `
193+ < br> Now it will run & regenerate Main Schema everytime the project starts.
194+ < br></p>
195+ < /details>
196+ < details close >
197+ < summary >
198+
199+ # ## Dependencies (optional)
200+ < /summary>
201+ < p align=" center" >
202+
203+ To use < b> prisma import< /b> feature : (< i> if you are using VS code, its better to use these< /i> )< br>
204+ < br>
205+ - Install [prisma-import](https://marketplace.visualstudio.com/items? itemName=ajmnz.prisma-import) Extension (for VS code)
27206
28- ---
207+ - < b > Disable < /b > Official [prisma](https://marketplace.visualstudio.com/items ? itemName=Prisma.prisma) Extension (for VS code)
29208
30- # [ Documentation] ( https://github.com/joydip007x/Prisma-MultiSchema#readme ) : [ ![ NPM] ( https://img.shields.io/badge/Github-joydip007x%2Fprisma--multischema-blue )] ( https://github.com/joydip007x/Prisma-MultiSchema#readme )
209+ > These are < b> Optional Dependencies< /b> , If you can maintain multiple * .prisma schemas without < b> TYPO< /b> ,you can ignore these.
210+ < /p>
211+ < /details>
212+ < details close >
213+ < summary >
214+
215+ # ## To-do's
216+ < /summary>
217+ < p align=" center" >
218+
219+ - Add Support for keeping prisma' s in different folder and aggregate them ( like ` root/src/auth/auth.prisma ` )
31220
221+ - Add Command Flags
222+ - ~ ~Handle/Remove ` " Error validating datasource db: " ` Warning~~ Fixed
223+
224+ < /p>
225+ < /details>
32226
33- ## Authors - [ @joydip007x ] ( https://www.github.com/joydip007x )
227+ # ### Authors - [@joydip007x](https://www.github.com/joydip007x)
0 commit comments