Skip to content

Commit

Permalink
Skip generating prisma client in keystone-next start (#5102)
Browse files Browse the repository at this point in the history
* Skip generating prisma client in keystone-next start

* Fix things
  • Loading branch information
emmatown authored Mar 12, 2021
1 parent a4002b0 commit 714bdad
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .changeset/lovely-days-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@keystone-next/adapter-prisma-legacy': minor
'@keystone-next/types': minor
'@keystone-next/keystone': minor
---

Added `none-skip-client-generation` migrationMode
6 changes: 5 additions & 1 deletion packages-next/keystone/src/scripts/run/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export const start = async ({ dotKeystonePath, projectAdminPath }: StaticPaths)
throw new Error('keystone-next build must be run before running keystone-next start');
}
const config = initConfig(require(apiFile).config);
const { keystone, graphQLSchema, createContext } = createSystem(config, dotKeystonePath, 'none');
const { keystone, graphQLSchema, createContext } = createSystem(
config,
dotKeystonePath,
'none-skip-client-generation'
);

console.log('✨ Connecting to the database');
await keystone.connect({ context: createContext().sudo() });
Expand Down
7 changes: 6 additions & 1 deletion packages-next/types/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ export function getGqlNames({
};
}

export type MigrationMode = 'none' | 'createOnly' | 'dev' | 'prototype';
export type MigrationMode =
| 'none-skip-client-generation'
| 'none'
| 'createOnly'
| 'dev'
| 'prototype';
20 changes: 8 additions & 12 deletions packages/adapter-prisma/src/adapter-prisma.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,17 @@ class PrismaAdapter extends BaseKeystoneAdapter {
}

async _generateClient(rels) {
// 1. Generate a formatted schema
// Generate a formatted schema
// note that we currently still need to call _prepareSchema even during
// a `keystone-next start` because it has various side effects
const { prismaSchema } = await this._prepareSchema(rels);

// 2. Check for existing schema
// 2a1. If they're the same, we're golden
// 2a2. If they're different, generate and run a migration
// 2b. If it doesn't exist, generate and run a migration
if (this.migrationMode !== 'none-skip-client-generation') {
this._writePrismaSchema({ prismaSchema });

// If any of our critical directories are missing, or if the schema has changed, then
// we've got things to do.

this._writePrismaSchema({ prismaSchema });

// Generate prisma client and run prisma migrations
await Promise.all([this._generatePrismaClient(), this._runMigrations({ prismaSchema })]);
// Generate prisma client and run prisma migrations
await Promise.all([this._generatePrismaClient(), this._runMigrations({ prismaSchema })]);
}
}

async _runMigrations({ prismaSchema }) {
Expand Down

1 comment on commit 714bdad

@vercel
Copy link

@vercel vercel bot commented on 714bdad Mar 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.