From d80748ea5084bed25e1c2973d66774a66c1bdf89 Mon Sep 17 00:00:00 2001 From: Daniel Cousens <413395+dcousens@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:51:43 +1000 Subject: [PATCH] Fix Prisma errors not showing when a Prisma migration errors internally (#9273) --- .changeset/fix-prisma-migrate.md | 5 +++++ packages/core/src/lib/migrations.ts | 5 ++--- packages/core/src/scripts/dev.ts | 2 +- tests/cli-tests/migrations.test.ts | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .changeset/fix-prisma-migrate.md diff --git a/.changeset/fix-prisma-migrate.md b/.changeset/fix-prisma-migrate.md new file mode 100644 index 00000000000..6db756a5ad4 --- /dev/null +++ b/.changeset/fix-prisma-migrate.md @@ -0,0 +1,5 @@ +--- +'@keystone-6/core': minor +--- + +Fix Prisma errors not showing when a Prisma migration errors internally diff --git a/packages/core/src/lib/migrations.ts b/packages/core/src/lib/migrations.ts index 88c477aff72..55d2727f662 100644 --- a/packages/core/src/lib/migrations.ts +++ b/packages/core/src/lib/migrations.ts @@ -1,4 +1,3 @@ -import { type ChildProcess } from 'node:child_process' import { toSchemasContainer } from '@prisma/internals' // @ts-expect-error @@ -62,9 +61,9 @@ export async function withMigrate ( } }) } finally { + await migrate.engine.initPromise const closePromise = new Promise(resolve => { - const { child } = migrate.engine as { child: ChildProcess } - child.once('exit', () => resolve()) + migrate.engine.child.once('exit', resolve) }) migrate.stop() await closePromise diff --git a/packages/core/src/scripts/dev.ts b/packages/core/src/scripts/dev.ts index f1a0d3cb3ba..74c03b3c71f 100644 --- a/packages/core/src/scripts/dev.ts +++ b/packages/core/src/scripts/dev.ts @@ -161,7 +161,7 @@ export async function dev ( const paths = system.getPaths(cwd) if (dbPush) { const created = await createDatabase(system.config.db.url, path.dirname(paths.schema.prisma)) - if (created) console.log(`✨ database created`) + if (created) console.log(`✨ Database created`) const migration = await withMigrate(paths.schema.prisma, system, async (m) => { // what does force on migrate.engine.schemaPush mean? diff --git a/tests/cli-tests/migrations.test.ts b/tests/cli-tests/migrations.test.ts index e6f4a4f03d2..eed30040ed8 100644 --- a/tests/cli-tests/migrations.test.ts +++ b/tests/cli-tests/migrations.test.ts @@ -125,7 +125,7 @@ describe('dev', () => { ? Server listening on :3000 (http://localhost:3000/) ? GraphQL API available at /api/graphql ? Generating GraphQL and Prisma schemas - ? database created + ? Database created ? Database synchronized with Prisma schema ? Connecting to the database ? Creating server