Skip to content

byrichardpowell/prisma-schema-to-json-to-prisma-schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Readme

What is this?

A proof of concept to convert a schema.prisma file to JSON and back. If the concept was proven, you could convert schema.prisma to JSON, then back to schema.prisma ending with output that matches the input.

Why does this matter?

In theory, an application could provide a UI for creating and editing a schema.prisma file. The UI would deal with JSON. The Backend would parse that JSON to a schema.prisma, and then run prisma generate to create the database.

How to run this

yarn install
yarn run prismaToJSON
yarn run JSONToPrisma

The output will be in ./output/. schema.js is the JSON representation of the prisma schema. schema.prisma is the result of converting the JSON schema back to a prisma schema. Both files are missing some information (see next section).

Known Limitations

To convert schema.prisma to JSON we use pal schema. Unfortunately this skips default values. To illustrate:

  1. For @id, @default(autoincreent()) is not included. This might not be an issue because we can assume that every model would have an ID, and that the user has no need to customize this. Therefore we could automatically add it.
  2. For DateTime, @default(now()) is not included. Again, this might not be an issue, because we could assume that every model has createdAt fields, and automatically add them. Therefore we could automatically add it. The same could be said for updatedAt.
  3. For role the defualt ENUM is not recorded. This is an issue, as loosing this information would signficantly change application behaviour.

The solution to this seem to be either:

  1. forking, contributing, or replacing pal schema.
  2. Never converting from schema.prisma to JSON, and then extending the JSON information to include the missing pieces.

About

A proof of concept attempt

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published