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.
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.
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).
To convert schema.prisma
to JSON
we use pal schema. Unfortunately this skips default values. To illustrate:
- 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. - For
DateTime
,@default(now())
is not included. Again, this might not be an issue, because we could assume that every model hascreatedAt
fields, and automatically add them. Therefore we could automatically add it. The same could be said forupdatedAt
. - For
role
the defualtENUM
is not recorded. This is an issue, as loosing this information would signficantly change application behaviour.
The solution to this seem to be either:
- forking, contributing, or replacing pal schema.
- Never converting from
schema.prisma
toJSON
, and then extending theJSON
information to include the missing pieces.