Skip to content

Commit

Permalink
Extend extend-prisma-schema example to demonstrate adding `previewF…
Browse files Browse the repository at this point in the history
…eatures` (#9097)
  • Loading branch information
dcousens committed Apr 16, 2024
1 parent c6b8884 commit 785f363
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
15 changes: 9 additions & 6 deletions examples/extend-prisma-schema/keystone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions examples/extend-prisma-schema/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion examples/extend-prisma-schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 785f363

Please sign in to comment.