Skip to content

Commit

Permalink
Fix crash if the prisma client directory exists but the prisma schema…
Browse files Browse the repository at this point in the history
… doesn't (#4984)

* Fix crash if the prisma client directory existed but the prisma schema didn't

* Update wet-nails-move.md
  • Loading branch information
emmatown authored Mar 2, 2021
1 parent 0c3b456 commit f826f15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/wet-nails-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystonejs/adapter-prisma': patch
---

Fixed crash if the prisma client directory exists but the prisma schema doesn't.
38 changes: 19 additions & 19 deletions packages/adapter-prisma/lib/adapter-prisma.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,28 @@ class PrismaAdapter extends BaseKeystoneAdapter {
// 2a2. If they're different, generate and run a migration
// 2b. If it doesn't exist, generate and run a migration

// // If any of our critical directories are missing, or if the schema has changed, then
// // we've got things to do.
if (
!fs.existsSync(this.clientPath) ||
!fs.existsSync(this.schemaPath) ||
fs.readFileSync(this.schemaPath, { encoding: 'utf-8' }) !== prismaSchema
) {
if (fs.existsSync(this.clientPath)) {
const existing = fs.readFileSync(this.schemaPath, { encoding: 'utf-8' });
if (existing === prismaSchema) {
// If they're the same, we're golden
return;
}
// If any of our critical directories are missing, or if the schema has changed, then
// we've got things to do.

try {
const existing = fs.readFileSync(this.schemaPath, { encoding: 'utf-8' });
if (existing === prismaSchema && fs.existsSync(this.clientPath)) {
// If they're the same, we're golden
return;
}
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
this._writePrismaSchema({ prismaSchema });
}

// Generate prisma client
await this._generatePrismaClient();
this._writePrismaSchema({ prismaSchema });

// Run prisma migrations
await this._runMigrations();
}
// Generate prisma client
await this._generatePrismaClient();

// Run prisma migrations
await this._runMigrations();
}

async _runMigrations() {
Expand Down

0 comments on commit f826f15

Please sign in to comment.