https://github.com/capaj/prisma-generator-checker
tiny prisma generator to check whether you have the latest generated prisma schema
https://github.com/capaj/prisma-generator-checker
prisma typescript
Last synced: 6 months ago
JSON representation
tiny prisma generator to check whether you have the latest generated prisma schema
- Host: GitHub
- URL: https://github.com/capaj/prisma-generator-checker
- Owner: capaj
- Created: 2023-06-13T15:16:04.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-14T10:27:42.000Z (about 3 years ago)
- Last Synced: 2024-04-09T21:10:33.724Z (about 2 years ago)
- Topics: prisma, typescript
- Language: TypeScript
- Homepage:
- Size: 112 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# prisma-generator-checker
Very tiny/simple generator to check whether you have the latest generated prisma schema or not.
TODO automatically generate prisma schema when it is out of sync
## How to use
make sure you have `.env` file in your project root folder.
Add this:
```prisma
generator prisma_checker {
provider = "npx prisma-generator-checker"
}
```
to your `schema.prisma`
then at runtime, you can do
```ts
import { checkPrismaSchemaHash } from '../node_modules/prisma-generator-checker/dist/checkPrismaSchemaHash'
if (process.env.NODE_ENV !== 'production') {
// prisma generator checker should not be needed for prod as long as you trust your CI to generate the prisma client correctly
checkPrismaSchemaHash()
}
```
this will check sha hash of the schema.prisma file to make sure it matches to the one stored in `.env` when your prisma generation was last executed. If it does not match, it throws an error like this:
```
Error: Prisma schema hash does not match the one in .env, please run prisma generate and commit the changes.
at Object. (/home/capaj/oss/prisma-generator-checker/packages/generator/src/runtimeChecker.ts:7:11)
at Module._compile (node:internal/modules/cjs/loader:1155:14)
at Module.m._compile (/home/capaj/.local/share/pnpm/global/5/.pnpm/ts-node@10.9.1_typescript@4.8.2/node_modules/ts-node/src/index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
at Object.require.extensions. [as .ts] (/home/capaj/.local/share/pnpm/global/5/.pnpm/ts-node@10.9.1_typescript@4.8.2/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1033:32)
at Function.Module._load (node:internal/modules/cjs/loader:868:12)
at Module.require (node:internal/modules/cjs/loader:1057:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object. (/home/capaj/oss/prisma-generator-checker/packages/usage/
```