Migrate: Lift dropping and recreating unrelated fields during migration

Created on 15 Jan 2020  ·  2Comments  ·  Source: prisma/migrate

Heya, this is mostly a continuation/resurfacing of #100

When doing a simple migration, like adding an optional string filed to a model, lift warns about pretty much every column under the sun being dropped.
The interesting part is, this time, the steps that would lead to such data loss aren't actually a part of the steps.json or readme steps.

Reproduction

  1. Take a simple prisma schema like
model User {
  id        String  @default(cuid()) @id
  name      String
  posts     Post
  email     String
}

model Post {
  id        String  @default(cuid()) @id
  title     String?
  author    User
  content   String?
  published Boolean @default(false)
}
  1. Save the migration and apply it, add some seed data.
  2. Add a new field to one of the models:
    testField String?

  3. Try saving the migration.

Sample output

❯ prisma2 lift save --name add-field
📼  lift save --name add-field

Local datamodel Changes:

model User {
  id String @default(cuid()) @id
  name String
  posts Post
  email String
  testField String?
}


⚠️  There might be data loss when applying the migration:

  • You are about to alter the column `email` on the `User` table, which still contains 1 non-null values. The data in that column will be lost.
  • You are about to alter the column `name` on the `User` table, which still contains 1 non-null values. The data in that column will be lost.
  • You are about to alter the column `content` on the `Post` table, which still contains 1 non-null values. The data in that column will be lost.
  • You are about to alter the column `title` on the `Post` table, which still contains 1 non-null values. The data in that column will be lost.


Lift just created your migration 20200115071932-add-field in

migrations/
  └─ 20200115071932-add-field/
    └─ steps.json
    └─ schema.prisma
    └─ README.md

Run prisma2 lift up to apply the migration

EDIT: Just confirmed there is actual dataloss

Most helpful comment

Copying my reply to #267 here:

I am fairly confident this issue was fixed a few weeks ago (prisma/prisma-engine#326 and others), but we haven't released a preview version since. Please try again with the latest prisma2@alpha or wait for the next preview release, which should be very soon now.

edit: I tried with the latest alpha and I can't reproduce the problem.

All 2 comments

Experiencing the same issue. None of the below model fields were modified prior to the attempted migration. This is very debilitating:

image

Copying my reply to #267 here:

I am fairly confident this issue was fixed a few weeks ago (prisma/prisma-engine#326 and others), but we haven't released a preview version since. Please try again with the latest prisma2@alpha or wait for the next preview release, which should be very soon now.

edit: I tried with the latest alpha and I can't reproduce the problem.

Was this page helpful?
0 / 5 - 0 ratings