Overview

Prisma Migrate generates database migrations from changes in the Prisma schema. Sometimes, intent cannot be inferred from changes.

An example

Let's say as a developer you want to rename the field name to fullName.

Before

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
}

After

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  fullName  String?
}

Prisma Migrate currently diffs the two model definitions and generates a migration to drop the name column and create a new fullName column in the User table. Of course, if the intent of the change was to rename the column the generated migration will not be suitable, because although it leads to the same end-state in the database schema, it will cause data loss.

Solution

We are looking at solving some of these limitations via interactive prompts. Prisma Migrate could use some heuristics to infer if some of the changes picked up could be interpreted as a renaming operation and prompt the developer for a decision.

Based on the developer input, Prisma Migrate can generate a migration that hopefully better represents the intent of the changes in the Prisma schema.

Status

This is currently planned to follow shortly after Prisma Migrate is release in GA.