Improve prototyping speed of Prisma
Lukáš Huvar
2 min read
~ views
Prisma is really great "next-generation" ORM. It enables developers to work with databases effortlessly. It had one downside and that was prototyping annoying the developer experience.
Single command for schema changes
From 2.10.0 release release everything improved with possibility run just one single command! Prisma introduced a new prisma db
namespace for commands that operates directly against the database.
prisma db push --preview-feature
prisma db push --preview-feature
It greatly improves prototyping speed, because the developer is no longer required to write migrations. The command's usage is mainly for prototyping and local environments. For production environments, you should use prisma migrate
commands to run propper database migrations.
Save and run
If you are using VSCode we can improve prototyping even more. There is Save and Run extension, which enables us to run a command on save. You can install this extension trough Extensions
in VScode or run this command:
code --install-extension wk-j.save-and-run
code --install-extension wk-j.save-and-run
Next, you need to add settings file to your Prisma
project to enable Save and Run
to work on schema.prisma
file.
{
"saveAndRun": {
"commands": [
{
"match": "schema.prisma",
"cmd": "yarn prisma db push --preview-feature",
"silent": false
}
]
}
}
{
"saveAndRun": {
"commands": [
{
"match": "schema.prisma",
"cmd": "yarn prisma db push --preview-feature",
"silent": false
}
]
}
}
Here you can see whole flow in action. It deploys a new schema to database and generates types for PrismaClient
.
You can use Save and run
with oter tools, such as:
- GraphQL code generator - generating code from your
GraphQL
schema - Nexus.js - generating code-first
GraphQL
schema
If you are not using VSCode
you can use Watchman, entr or any other tools for watching file change.