How to migrate with Prisma without downtime

Prisma Migrate is amazing, it helps you manage your database and generates typings for your database schema automatic.

https://github.com/prisma/migrate

However you can still make mistakes that takes down your app, so here is the rules:

You can not add and delete columns in same release

If you add columns, migrate first and deploy.

If you delete columns, deploy first and migrate.

You can not rename columns in the same release

Say to need to rename “cur” to “currency”.

If you do that in one deploy, you can not do that without taking your database offline and migrating. If not you code will try to select either the new or old column and it is impossible to deploy and migrate in the same second.

So to rename 3 deploys:

Create the new column, so you have both “cur” and “currency”.

Change the code to write to both columns.

Delete old column.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store