Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@prisma-utils/prismerge
Advanced tools
A handy CLI to merge multiple `*.prisma` files into one big `schema.prisma` file that can be processed and handled by `Prisma`.
A handy CLI to merge multiple *.prisma
files into one big schema.prisma
file that can be processed and handled by Prisma
.
Install the package via
npm i -D @prisma-utils/prismerge
Now you can call
npx prismerge -g -i prismerge.json
to create a default prismerge.json
configuration file. This file looks like this:
{
"app": {
"inputs": [],
"fragments": {},
"output": ""
}
}
Now simply add paths to your *.prisma
files for inputs
, and define the output
file, like follows:
{
"app": {
"inputs": [
"./libs/core/prisma/base.prisma",
"./libs/user/prisma/user.prisma",
"./libs/article/prisma/article.prisma"
],
"output": "./prisma/schema.prisma"
}
}
Executing
npx prismerge -i prismerge.json
will read all *.prisma
files defined in inputs
and merges them into one single schema.prisma
file that can be read and processed by Prisma
.
Of course you can add additional apps
(i.e., top level element of the prismerge.json
file), if you have multiple services.
{
"auth-service": {
"inputs": [
"./libs/auth/core/prisma/base.prisma",
"./libs/auth/user/prisma/user.prisma"
],
"output": "./prisma/auth/schema.prisma"
},
"article-service": {
"inputs": [
"./libs/article/core/prisma/base.prisma",
"./libs/article/article/prisma/article.prisma"
],
"output": "./prisma/article/schema.prisma"
},
"log-service": {
"inputs": [
"./libs/log/core/prisma/base.prisma",
"./libs/log/prisma/log.prisma"
],
"output": "./prisma/log/schema.prisma"
}
}
You can specify to exclude a specific app, via the --excludeApps
(-eA
) parameter. Running
npx prismerge --oA auth-service article-service
will exclude these specific apps from the generation process.
PrisMerge also allows to use glob
patterns for inputs
. Consider the following example:
{
"app": {
"inputs": [
"./libs/*/prisma/*.prisma"
],
"output": "./prisma/schema.prisma"
}
}
This will, for example, find the prisma
files in
./libs/user/prisma/user.prisma
./libs/article/prisma/article.prisma
See the glob docs for more ideas, how this can be used.
PrisMerge also allows for defining Fragments
, that can be inserted into models. These Fragments can be used to define reoccurring field definitions, like the description for id
fields.
Consider the following example for a fragent
file:
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
This information will be used over and over again in all your models.
Unfortunately, Prisma itself does not provide a suitable mechanism for extending / inheriting a base model.
With PrisMerge you can link to *.prisma.fragment
files. Fragment placeholders are then replaced during the merge-process with the actual content of these files.
First, define your fragment as follows:
# File: ./my/custom/path/id.prisma.fragment
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Second, add the fragment to your prismerge.json
file as follows and assign a proper key (i.e., id
in this example).
{
"app": {
"inputs": [
"./libs/core/prisma/base.prisma",
"./libs/user/prisma/user.prisma",
"./libs/article/prisma/article.prisma"
],
"fragments": {
"id": "./my/custom/path/id.prisma.fragment"
},
"output": "./prisma/schema.prisma"
}
}
Finally, add the placeholder to your model files, like so:
# File: ./libs/user/prisma/user.prisma
model User {
...id
// additional fields
email String @unique
password String
}
When running
npx prismerge
the placeholders are properly replaced, resulting in the final model
model User {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// additional fields
email String @unique
password String
}
This library also provides nrwl/nx generators that can be used to
Respective generators can be easily called via the Nx VSCode Extension or via cli. More information are provided within the description of the generators via
npx nx generate @prisma-utils/prismerge:init --help
npx nx generate @prisma-utils/prismerge:add-model --help
npx nx generate @prisma-utils/prismerge:add-fragment --help
You can also use a custom npm
script to align these commands, like so:
// in your package.json
{
"scripts": {
"prisma:generate": "npx prismerge -i prismerge.json && npx prisma generate"
}
}
This will first create the single schema file and then call the generators defined in the generated schema in one go.
Call
npx prismerge --help
for additional information or configuration options.
You can easily create an issue and request additional features or fix bugs.
Run nx lint prismerge
to execute the lint via ESLint.
Run nx test prismerge
to execute the unit tests via Jest.
FAQs
A handy CLI to merge multiple `*.prisma` files into one big `schema.prisma` file that can be processed and handled by `Prisma`.
The npm package @prisma-utils/prismerge receives a total of 532 weekly downloads. As such, @prisma-utils/prismerge popularity was classified as not popular.
We found that @prisma-utils/prismerge demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.