Generate KeyStone.js 6 schema from modified Prisma schema

765 Views Asked by At

I had a project that was using the latest version of Prisma (3.9.1) and was planning to place a CMS on top of it. Keystone seemed like a very good fit as they already use Prisma internally. Unfortunately I couldn't modify the Prisma schema because it was auto-generated from the Keystone schema. Is there a way to reverse the process and get a Keystone schema from Prisma ?

2

There are 2 best solutions below

2
On BEST ANSWER

At the moment there's no way to generate a Keystone schema from an existing Prisma schema. You'd need to create the Keystone schema manually so Keystone could generate a new Prisma schema file.

There's also currently no way to modify the Prisma schema generated by Keystone, though there's been talk of opening this up.

0
On

One option is to paste your Prisma schema into extendedPrismaSchema in keystone/schema.ts as following:

SomeSchema: list({
    fields: {},
    db: {
      extendPrismaSchema() {
        return `
        model YourSchema {
          id         String
          name       String
          email      String
        }
        `;
      }
    }
  })

I don't know how this would affect things, but it's one way!