Skip to content

Commit

Permalink
Adds config.db.prismaSchemaPath (#8777)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens authored Aug 29, 2023
1 parent 859257a commit e3438dc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/add-prisma-schema-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': minor
---

Adds `config.db.prismaSchemaPath`
1 change: 1 addition & 0 deletions examples/custom-output-paths/keystone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default config({
// when working in a monorepo environment you may want to output the prisma client elsewhere
// you can use .db.prismaClientPath to configure where that is
prismaClientPath: 'node_modules/.myprisma/client',
prismaSchemaPath: 'my-prisma.prisma',
},
lists,

Expand Down
20 changes: 20 additions & 0 deletions examples/custom-output-paths/my-prisma.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is automatically generated by Keystone, do not modify it manually.
// Modify your Keystone config when you want to change this.

datasource sqlite {
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
provider = "sqlite"
}

generator client {
provider = "prisma-client-js"
output = "node_modules/.myprisma/client"
}

model Post {
id String @id @default(cuid())
title String @default("")
content String @default("")
publishDate DateTime?
}
6 changes: 5 additions & 1 deletion packages/core/src/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export function getSystemPaths(cwd: string, config: KeystoneConfig) {
? path.join(cwd, config.types.path)
: path.join(cwd, 'node_modules/.keystone/types.ts');

const builtPrismaPath = config.db?.prismaSchemaPath
? path.join(cwd, config.db.prismaSchemaPath)
: path.join(cwd, 'schema.prisma');

const relativePrismaPath = prismaClientPath
? `./${posixify(path.relative(path.dirname(builtTypesPath), prismaClientPath))}`
: '@prisma/client';
Expand All @@ -113,7 +117,7 @@ export function getSystemPaths(cwd: string, config: KeystoneConfig) {
},
schema: {
types: builtTypesPath,
prisma: path.join(cwd, 'schema.prisma'),
prisma: builtPrismaPath,
graphql: builtGraphqlPath,
},
};
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/types/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export type DatabaseConfig<TypeInfo extends BaseKeystoneTypeInfo> = {
enableLogging?: boolean | PrismaLogLevel | Array<PrismaLogLevel | PrismaLogDefinition>;
idField?: IdFieldConfig;
prismaClientPath?: string;
prismaSchemaPath?: string;

extendPrismaSchema?: (schema: string) => string;

/** @deprecated */
Expand Down

0 comments on commit e3438dc

Please sign in to comment.