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

Add the ability to customise the Generated Prisma Schema #8241

Merged
merged 22 commits into from
Jan 24, 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
6 changes: 6 additions & 0 deletions .changeset/pretty-books-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystone-6/fields-document': minor
'@keystone-6/core': minor
---

Adds an experimental `extendPrismaSchema` configuration option for lists and fields to mutate the prisma schema
28 changes: 28 additions & 0 deletions examples/extend-prisma-schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Example Project - Extend Prisma Schema

This project implements an example of mutating the Prisma Schema to:

- Set the Prisma Binary Target;
- Add a multi-column column unique constraint to a list; and
- Add a NOT NULL relationship field

These show three separate ways of mutating the Prisma Schema see `keystone.ts` and `schema.ts`.

## Instructions

To run this project, clone the Keystone repository locally, run `yarn` at the root of this repository, then navigate to this directory and run:

```shell
yarn dev
```

This will start the Admin UI at [localhost:3000](http://localhost:3000).
You can use the Admin UI to create items in your database.

You can also access a GraphQL Playground at [localhost:3000/api/graphql](http://localhost:3000/api/graphql), which allows you to directly run GraphQL queries and mutations.

Congratulations, you're now up and running with Keystone! 🚀

## Try it out in CodeSandbox 🧪

You can play with this example online in a web browser using the free [codesandbox.io](https://codesandbox.io/) service. To launch this example, open the URL <https://githubbox.com/keystonejs/keystone/tree/main/examples/extend-prisma-schema>. You can also fork this sandbox to make your own changes.
14 changes: 14 additions & 0 deletions examples/extend-prisma-schema/keystone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { config } from '@keystone-6/core';
import { lists } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',
extendPrismaSchema: schema => {
// as an example, we will change the Prisma binary to be linux-musl
return schema.replace(/(generator [^}]+)}/g, '$1binaryTargets = ["native", "linux-musl"]\n}');
},
},
lists,
});
19 changes: 19 additions & 0 deletions examples/extend-prisma-schema/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@keystone-6/example-extend-prisma-schema",
"version": "0.0.8",
"private": true,
"license": "MIT",
"scripts": {
"dev": "keystone dev",
"start": "keystone start",
"build": "keystone build"
},
"dependencies": {
"@keystone-6/core": "^4.0.0",
"@keystone-6/fields-document": "^6.0.0"
},
"devDependencies": {
"typescript": "~4.9.4"
},
"repository": "https://github.com/keystonejs/keystone/tree/main/examples/extend-prisma-schema"
}
7 changes: 7 additions & 0 deletions examples/extend-prisma-schema/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"template": "node",
"container": {
"startScript": "keystone dev",
"node": "16"
}
}
Loading