Closed ymc9 closed 1 year ago
why putting both prisma and zmodel schemas in one file is odd? i would like to have all prisma related files in one folder
why putting both prisma and zmodel schemas in one file is odd? i would like to have all prisma related files in one folder
Hi @ericfel93 , let me elaborate on this a bit more.
The zenstack
CLI essentially generate two types of artifacts using its several builtin plugins:
Prisma schema
Via the @core/prisma
plugin - further consumed by the prisma
CLI. By default output to "prisma/schema.prisma".
TS/JS files for supporting runtime "enhancement" to PrismaClient.
By default to "node_modules/.zenstack". This is done by plugins "@core/model-meta", "@core/access-policy", and "@core/zod". The approach is very similar to how prisma generate
command outputs to "node_modules/.prisma" directory.
Developers usually don't need to mess with the second part directly since zenstack's runtime loads from the default location automatically. But there're cases when one doesn't want to run the CLI at deploy time but rather wants to check-in the generated code into the code base. The "--output" CLI option is for controlling the default output folder for this part.
As you can see, the two parts of generation serve very different purposes, so I feel it's very rare that people would want to have them output to the same folder ... but let me know if you see a scenario that I haven't seen. Thanks!
I'm using only the prisma schema, so I don't mind about the TS/JS files but I do want the both schemas to be on the same folder
Ah, I see what you mean now. You can actually define where to output the generated prisma schema file:
plugin prisma {
provider = "@core/prisma"
output = "./prisma/my.prisma"
}
@ericfel93
@ymc9 When I attempt to include the @core/prisma plugin, I encounter the following error:
Unable to load plugin module @core/prisma: @core/prisma, Error: Cannot find module '@core/prisma'
What steps should I take to address this issue?
@ymc9 When I attempt to include the @core/prisma plugin, I encounter the following error:
Unable to load plugin module @core/prisma: @core/prisma, Error: Cannot find module '@core/prisma'
What steps should I take to address this issue?
Hi @Val0429 , Which version of ZenStack are you one? Could you share your zmodel snippet?
I'm using zenstack@1.0.2 which I installed with npm i zenstack@latest
My ZModel: schema.zip
Just tried with a new project with the given zmodel but couldn't reproduce the error. Did you get it by running
npx zenstack generate
in the project folder? Is it possible to share the project?
Certainly, here is a straightforward repository to replicate the problem: zenstack-core-plugin-not-found-reproduction.
To reproduce the issue, follow these steps:
Clone the repository: git clone https://github.com/Val0429/zenstack-core-plugin-not-found-reproduction
Install dependencies: npm install
Generate with Zenstack using the provided schema: npx zenstack generate --schema=src/schema.zmodel
Certainly, here is a straightforward repository to replicate the problem: zenstack-core-plugin-not-found-reproduction.
To reproduce the issue, follow these steps:
Clone the repository:
git clone https://github.com/Val0429/zenstack-core-plugin-not-found-reproduction
Install dependencies:npm install
Generate with Zenstack using the provided schema:npx zenstack generate --schema=src/schema.zmodel
Hi @Val0429 ,
I don't know why, but your package-lock.json installed a deprecated version of "zenstack" 1.0.16... After reinstalling it works:
npm i -D zenstack@latest
It should install 1.0.2.
The version 1.0.16 has been deprecated for quite a while: https://www.npmjs.com/package/zenstack/v/1.0.16
Do you recall how you initially installed it?
Hi @ymc9 ,
I found the way to reproduce this problem. (which deprecation 1.0.16 being installed)
After running npm i zenstack -D
, the npm packager issues a warning:
4 low severity vulnerabilities To address all issues, run: npm audit fix
However, if I proceed with npm audit fix
, it rewrites the package-lock.json and inserts version 1.0.16 into it.
Thanks a bunch, and keep up the excellent work!
Hi @ymc9 ,
I found the way to reproduce this problem. (which deprecation 1.0.16 being installed)
After running
npm i zenstack -D
, the npm packager issues a warning:4 low severity vulnerabilities To address all issues, run: npm audit fix
However, if I proceed with
npm audit fix
, it rewrites the package-lock.json and inserts version 1.0.16 into it.Thanks a bunch, and keep up the excellent work!
Oh, thanks for the hint! Very helpful. I've been wondering why this happens sometimes for a while 😅. I guess the problem will be gone after we get to V1.1 (early next week).
You're welcome. Any time!
I thought about this again. The output of Prisma schema is, in nature, a bit different from the output of TS/JS files generated by other plugins; putting them all into one output folder seems quite odd. Instead of making the changes, I've updated the CLI documentation to make the meaning of the "--output" switch clearer.