From 785f363815fd41d41bb4456457c48fbc0bd4849c Mon Sep 17 00:00:00 2001 From: Daniel Cousens <413395+dcousens@users.noreply.github.com> Date: Tue, 16 Apr 2024 12:19:46 +1000 Subject: [PATCH] Extend `extend-prisma-schema` example to demonstrate adding `previewFeatures` (#9097) --- examples/extend-prisma-schema/keystone.ts | 15 +++++++++------ examples/extend-prisma-schema/schema.prisma | 8 +++++--- examples/extend-prisma-schema/schema.ts | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/examples/extend-prisma-schema/keystone.ts b/examples/extend-prisma-schema/keystone.ts index fc338180939..bc7d0245756 100644 --- a/examples/extend-prisma-schema/keystone.ts +++ b/examples/extend-prisma-schema/keystone.ts @@ -5,13 +5,16 @@ import { lists } from './schema' export default config({ db: { provider: 'sqlite', - url: process.env.DATABASE_URL || 'file:./keystone-example.db', + url: process.env.DATABASE_URL ?? 'file:./keystone-example.db', - extendPrismaSchema: (schema: any) => { - return schema.replace( - /(generator [^}]+)}/g, - ['$1binaryTargets = ["native", "linux-musl"]', '}'].join('\n') - ) + extendPrismaSchema: (schema) => { + return schema + .replace(/(generator [^}]+)}/g, [ + '$1', + ' binaryTargets = ["native", "linux-musl"]', + ' previewFeatures = ["metrics"]', + '}' + ].join('\n')) }, // WARNING: this is only needed for our monorepo examples, dont do this diff --git a/examples/extend-prisma-schema/schema.prisma b/examples/extend-prisma-schema/schema.prisma index b3db2d52a23..74d4125cf30 100644 --- a/examples/extend-prisma-schema/schema.prisma +++ b/examples/extend-prisma-schema/schema.prisma @@ -8,9 +8,11 @@ datasource sqlite { } generator client { - provider = "prisma-client-js" - output = "node_modules/.myprisma/client" - binaryTargets = ["native", "linux-musl"] + provider = "prisma-client-js" + output = "node_modules/.myprisma/client" + + binaryTargets = ["native", "linux-musl"] + previewFeatures = ["metrics"] } model Author { diff --git a/examples/extend-prisma-schema/schema.ts b/examples/extend-prisma-schema/schema.ts index 17e81f6815c..47f84b7ad13 100644 --- a/examples/extend-prisma-schema/schema.ts +++ b/examples/extend-prisma-schema/schema.ts @@ -29,7 +29,7 @@ export const lists = { db: { extendPrismaSchema: field => { // change relationship to enforce NOT NULL - // WARNING: this won't be easy to use, but this is nice if you know what you're doing + // WARNING: this won't be easy to use, but if you know what you're doing... return field .replace(/tags Tag\?/g, 'tags Tag') .replace(/tagsId String\?/g, 'tagsId String')