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

Skip generating prisma client in keystone-next start #5102

Merged
merged 2 commits into from
Mar 12, 2021
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
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