Skip to content

Commit e382f9e

Browse files
dcousensJosh Calder
andauthored
Merge previous breaking changes (#8776)
Co-authored-by: Daniel Cousens <[email protected]> Co-authored-by: Josh Calder <[email protected]>
1 parent 32729a2 commit e382f9e

File tree

8 files changed

+124
-75
lines changed

8 files changed

+124
-75
lines changed

.changeset/fix-frozen-prisma.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@keystone-6/core': major
3+
---
4+
5+
Fix `keystone prisma` behaviour to respect `--frozen`, dont generate types or Prisma client when using `--frozen`

.changeset/more-errors-please.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@keystone-6/core': minor
3+
---
4+
5+
`KS_PRISMA_ERRORS` are now logged with `console.error` on the server

packages/core/src/lib/createSystem.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ function injectNewDefaults (prismaClient: unknown, lists: Record<string, Initial
156156
try {
157157
return await query(args)
158158
} catch (e: any) {
159+
console.error(e)
160+
159161
if ((e as any).code === undefined) {
160162
return new GraphQLError(`Prisma error`, {
161163
extensions: {

packages/core/src/scripts/prisma.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
getBuiltKeystoneConfiguration
66
} from '../lib/createSystem'
77
import {
8+
generateArtifacts,
9+
generatePrismaClient,
10+
generateTypes,
811
validateArtifacts,
9-
generatePrismaClient
1012
} from '../artifacts'
1113
import { getEsbuildConfig } from '../lib/esbuild'
1214
import { ExitError } from './utils'
@@ -21,8 +23,17 @@ export async function prisma (cwd: string, args: string[], frozen: boolean) {
2123
// TODO: this cannot be changed for now, circular dependency with getSystemPaths, getEsbuildConfig
2224
const config = getBuiltKeystoneConfiguration(cwd)
2325
const system = createSystem(config)
24-
await validateArtifacts(cwd, system)
25-
await generatePrismaClient(cwd, system)
26+
27+
if (frozen) {
28+
await validateArtifacts(cwd, system)
29+
console.log('✨ GraphQL and Prisma schemas are up to date')
30+
} else {
31+
await generateArtifacts(cwd, system)
32+
console.log('✨ Generated GraphQL and Prisma schemas')
33+
34+
await generatePrismaClient(cwd, system)
35+
await generateTypes(cwd, system)
36+
}
2637

2738
return new Promise<void>((resolve, reject) => {
2839
const p = spawn('node', [require.resolve('prisma'), ...args], {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`keystone prisma exits with the same code as the prisma child process exits with 1`] = `
4+
"? Generated GraphQL and Prisma schemas
5+
6+
! Unknown command "bad-thing"
7+
8+
? Prisma is a modern DB toolkit to query, migrate and model your database (https://prisma.io)
9+
10+
Usage
11+
12+
$ prisma [command]
13+
14+
Commands
15+
16+
init Set up Prisma for your app
17+
generate Generate artifacts (e.g. Prisma Client)
18+
db Manage your database schema and lifecycle
19+
migrate Migrate your database
20+
studio Browse your data with Prisma Studio
21+
validate Validate your Prisma schema
22+
format Format your Prisma schema
23+
24+
Flags
25+
26+
--preview-feature Run Preview Prisma commands
27+
28+
Examples
29+
30+
Set up a new Prisma project
31+
$ prisma init
32+
33+
Generate artifacts (e.g. Prisma Client)
34+
$ prisma generate
35+
36+
Browse your data
37+
$ prisma studio
38+
39+
Create migrations from your Prisma schema, apply them to the database, generate artifacts (e.g. Prisma Client)
40+
$ prisma migrate dev
41+
42+
Pull the schema from an existing database, updating the Prisma schema
43+
$ prisma db pull
44+
45+
Push the Prisma schema state to the database
46+
$ prisma db push
47+
48+
Validate your Prisma schema
49+
$ prisma validate
50+
51+
Format your Prisma schema
52+
$ prisma format
53+
"
54+
`;
55+
56+
exports[`keystone prisma uses the db url in the keystone config 1`] = `
57+
"? Generated GraphQL and Prisma schemas
58+
Prisma schema loaded from schema.prisma
59+
Datasource "sqlite": SQLite database "app.db" at "file:./app.db"
60+
Error: P1003: Database app.db does not exist at ./app.db"
61+
`;

tests/cli-tests/artifacts.test.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,34 @@ import {
99
testdir,
1010
} from './utils'
1111

12-
describe.each(['postinstall', ['build', '--frozen'], ['prisma', 'migrate', 'status']])(
13-
'%s',
14-
command => {
15-
test('logs an error and exits with 1 when the schemas do not exist', async () => {
16-
const tmp = await testdir({
17-
...symlinkKeystoneDeps,
18-
'keystone.js': basicKeystoneConfig,
19-
})
20-
const recording = recordConsole()
21-
await expect(runCommand(tmp, command)).rejects.toEqual(new ExitError(1))
22-
expect(recording()).toMatchInlineSnapshot(
23-
`"Your Prisma and GraphQL schemas are not up to date"`
24-
)
12+
describe.each(['postinstall', ['build', '--frozen']])('%s', command => {
13+
test('logs an error and exits with 1 when the schemas do not exist', async () => {
14+
const tmp = await testdir({
15+
...symlinkKeystoneDeps,
16+
'keystone.js': basicKeystoneConfig,
17+
})
18+
19+
const recording = recordConsole()
20+
await expect(runCommand(tmp, command)).rejects.toEqual(new ExitError(1))
21+
22+
expect(recording()).toMatchInlineSnapshot(`"Your Prisma and GraphQL schemas are not up to date"`)
23+
})
24+
})
25+
26+
describe('prisma migrate status', () => {
27+
test('logs an error and exits with 1 when the schemas do not exist', async () => {
28+
const tmp = await testdir({
29+
...symlinkKeystoneDeps,
30+
'keystone.js': basicKeystoneConfig,
2531
})
26-
}
27-
)
32+
await expect(runCommand(tmp, ['build', '--no-ui', '--frozen'])).rejects.toEqual(new ExitError(1))
33+
34+
const recording = recordConsole()
35+
await expect(runCommand(tmp, ['prisma', '--frozen', 'migrate', 'status'])).rejects.toEqual(new ExitError(1))
36+
37+
expect(recording()).toMatchInlineSnapshot(`"Your Prisma and GraphQL schemas are not up to date"`)
38+
})
39+
})
2840

2941
const schemasMatch = ['schema.prisma', 'schema.graphql']
3042

@@ -37,9 +49,11 @@ describe('postinstall', () => {
3749
...symlinkKeystoneDeps,
3850
'keystone.js': basicKeystoneConfig,
3951
})
52+
4053
const recording = recordConsole()
4154
await runCommand(tmp, ['postinstall', '--fix'])
4255
const files = await getFiles(tmp, schemasMatch)
56+
4357
expect(files).toEqual(await getFiles(`${__dirname}/fixtures/basic-project`, schemasMatch))
4458
expect(recording()).toMatchInlineSnapshot(`"? Generated GraphQL and Prisma schemas"`)
4559
})
@@ -50,9 +64,11 @@ describe('postinstall', () => {
5064
...schemas,
5165
'keystone.js': basicKeystoneConfig,
5266
})
67+
5368
const recording = recordConsole()
5469
await runCommand(tmp, 'postinstall')
5570
const files = await getFiles(tmp, schemasMatch)
71+
5672
expect(files).toEqual(await getFiles(`${__dirname}/fixtures/basic-project`, schemasMatch))
5773
expect(recording()).toMatchInlineSnapshot(`"? GraphQL and Prisma schemas are up to date"`)
5874
})
@@ -63,8 +79,10 @@ describe('postinstall', () => {
6379
...schemas,
6480
'keystone.js': basicKeystoneConfig,
6581
})
82+
6683
const recording = recordConsole()
6784
await runCommand(tmp, 'postinstall')
85+
6886
expect(await getFiles(tmp, ['node_modules/.keystone/**/*'])).toMatchSnapshot()
6987
expect(recording()).toMatchInlineSnapshot(`"? GraphQL and Prisma schemas are up to date"`)
7088
})

tests/cli-tests/migrations.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ describe('useMigrations: false', () => {
250250
}
251251

252252
expect(recording()).toMatchInlineSnapshot(`
253-
"? Starting Keystone
253+
"? Generated GraphQL and Prisma schemas
254+
? Starting Keystone
254255
? Server listening on :3000 (http://localhost:3000/)
255256
? GraphQL API available at /api/graphql
256257
? Generating GraphQL and Prisma schemas

tests/cli-tests/prisma.test.ts

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,7 @@ test('keystone prisma exits with the same code as the prisma child process exits
1414
all: true,
1515
cwd: tmp,
1616
})
17-
expect(result.all!.replace(/[^ -~\n]/g, '?')).toMatchInlineSnapshot(`
18-
"
19-
! Unknown command "bad-thing"
20-
21-
? Prisma is a modern DB toolkit to query, migrate and model your database (https://prisma.io)
22-
23-
Usage
24-
25-
$ prisma [command]
26-
27-
Commands
28-
29-
init Set up Prisma for your app
30-
generate Generate artifacts (e.g. Prisma Client)
31-
db Manage your database schema and lifecycle
32-
migrate Migrate your database
33-
studio Browse your data with Prisma Studio
34-
validate Validate your Prisma schema
35-
format Format your Prisma schema
36-
37-
Flags
38-
39-
--preview-feature Run Preview Prisma commands
40-
41-
Examples
42-
43-
Set up a new Prisma project
44-
$ prisma init
45-
46-
Generate artifacts (e.g. Prisma Client)
47-
$ prisma generate
48-
49-
Browse your data
50-
$ prisma studio
51-
52-
Create migrations from your Prisma schema, apply them to the database, generate artifacts (e.g. Prisma Client)
53-
$ prisma migrate dev
54-
55-
Pull the schema from an existing database, updating the Prisma schema
56-
$ prisma db pull
57-
58-
Push the Prisma schema state to the database
59-
$ prisma db push
60-
61-
Validate your Prisma schema
62-
$ prisma validate
63-
64-
Format your Prisma schema
65-
$ prisma format
66-
"
67-
`)
17+
expect(result.all!.replace(/[^ -~\n]/g, '?').replace(/ \n/g, '\n')).toMatchSnapshot()
6818
expect(result.exitCode).toBe(1)
6919
})
7020

@@ -79,10 +29,6 @@ test('keystone prisma uses the db url in the keystone config', async () => {
7929
all: true,
8030
cwd: tmp,
8131
})
82-
expect(result.all).toMatchInlineSnapshot(`
83-
"Prisma schema loaded from schema.prisma
84-
Datasource "sqlite": SQLite database "app.db" at "file:./app.db"
85-
Error: P1003: Database app.db does not exist at ./app.db"
86-
`)
32+
expect(result.all!.replace(/[^ -~\n]/g, '?').replace(/ \n/g, '\n')).toMatchSnapshot()
8733
expect(result.exitCode).toBe(1)
8834
})

0 commit comments

Comments
 (0)