Skip to content

Commit

Permalink
Try to load prisma.schema path from pkg json (#3874)
Browse files Browse the repository at this point in the history
* Try to load prisma.schema path from pkg json
  • Loading branch information
Zeko369 authored Oct 3, 2022
1 parent eb970f7 commit d6717b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-pants-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blitzjs/generator": patch
---

Load schema.prisma path from `package.json` instead of assuming it's `db/schema.prisma`
7 changes: 5 additions & 2 deletions packages/generator/src/generators/model-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export class ModelGenerator extends Generator<ModelGeneratorOptions> {

// eslint-disable-next-line require-await
async write() {
const schemaPath = path.resolve("db/schema.prisma")
const pkgJson = this.fs.readJSON("package.json", {}) as {[key: string]: any}
const rawSchemaPath = pkgJson?.prisma?.schema || "db/schema.prisma"

const schemaPath = path.resolve(rawSchemaPath)
if (!this.fs.exists(schemaPath)) {
throw new Error("Prisma schema file was not found")
}
Expand All @@ -50,7 +53,7 @@ export class ModelGenerator extends Generator<ModelGeneratorOptions> {
try {
schema = ast.getSchema(this.fs.read(schemaPath))
} catch (err) {
console.error("Failed to parse db/schema.prisma file")
console.error(`Failed to parse ${rawSchemaPath} file`)
throw err
}
const {modelName, extraArgs, dryRun} = this.options
Expand Down

0 comments on commit d6717b9

Please sign in to comment.