Prisma Schema Generator is a tool for joining multiple prisma files into one, allowing a more structured and maintainable prisma schemas.
Prisma Schema Generator use prisma and prisma-aurora under the hood.
Since you will have separate files for each schema, take a look at prisma-aurora to check how you will relate schemas between each other before attempting to execute the command.
https://github.com/sabinadams/aurora
Dependencies
npm install @prisma/client
npm install prisma
npm install prisma-aurora
Install...
npm install prisma-schema-generator
In your package.json, make sure you have the following key:
{
....
"prisma": {
"schema": "path/to/your/schemas/schema.prisma"
}
}
In this folder path/to/your/schemas (the one where you will have all you schemas), create the following file including the underscore:
_main.prisma
In this file you can add your prisma db configuration and any other related data that should only be once in the final generated file.
_main.prisma
datasource db {
url = env("DATABASE_URL")
provider = "mysql"
}
generator client {
provider = "prisma-client-js"
}
In you current working directory, run the following command:
psgen
This command will do the following:
- Generate a aurora.config.json file based on all the files inside your schema's folder defined in the package.json
- Execute aurora command to make relationship between all files.
- Merge the _main.prisma and _aurora.prisma files into the final schema.prisma file the will be used with any prisma commands
_aurora.prisma file will be generated everytime you execute the psgen command.
Now execute prisma commands as usual:
Example:
npx prisma generate