Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to load prisma.schema path from pkg json #3874

Merged
merged 6 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
beerose marked this conversation as resolved.
Show resolved Hide resolved
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