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

Adds config.db.prismaSchemaPath #8777

Merged
merged 1 commit into from
Aug 29, 2023
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
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