Migrate: Lift in preview019 altering columns

Created on 20 Dec 2019  ·  11Comments  ·  Source: prisma/migrate

After I deleted the migration folder, truncated _migrations table and created a fresh migration, lift is altering fields (resets/drops value) that haven't been removed and schema has not changed. Details and reproduction below.

Most helpful comment

This should be fixed by https://github.com/prisma/prisma-engine/pull/318 :) It will be in the next alpha release.

All 11 comments

Also sometimes I am getting this error when lift up:

Reason: [src/libcore/result.rs:1165:5] Error parsing the migration steps: Error("missing field `tag`", line: 1,
 column: 58)

schema:

datasource db {
  provider = "postgresql"
  url      = env("POSTGRES_URL")
}

generator photon {
  provider = "photonjs"
}

model File {
  id      String  @id @default(cuid())
  name    String
  project Project
  url     String
  type    String
}

model User {
  id            String        @id @default(cuid())
  authId        String?       @unique
  email         String        @unique
  projects      Project[]
  projectsAdmin Project[]     @relation(name: "admins")
  name          String
  profileImg    String?
  postVersions  PostVersion[]
  faqs          Faq[]
  createdAt     DateTime      @default(now())
  updatedAt     DateTime      @updatedAt
}

model Company {
  id       String    @id @default(cuid())
  name     String
  projects Project[]
}

model Project {
  id                   String         @id @default(cuid())
  name                 String
  company              Company
  webUrl               String?
  logo                 String
  logoSmall            String
  postCategories       PostCategory[]
  faqCategories        FaqCategory[]
  posts                PostVersion[]
  faqs                 Faq[]
  users                User[]
  admins               User[]         @relation(name: "admins")
  files                File[]
  faqFeature           Boolean
  blogFeature          Boolean
  sectionFeature       Boolean
  establishmentFeature Boolean
  supplierFeature      Boolean
  languages            String
  editorConfig         String
}

model Post {
  id               String      @id @default(cuid())
  draftedVersion   PostVersion @relation(name: "draft")
  publishedVersion PostVersion @relation(name: "published")
}

model PostVersion {
  id            String         @id @default(cuid())
  draftedPost   Post?          @relation(name: "draft")
  publishedPost Post?          @relation(name: "published")
  title         String
  slug          String
  text          String
  language      String
  categories    PostCategory[]
  mainImg       String
  author        User
  published     Boolean
  project       Project
  ogTitle       String?
  ogDescription String?
  tags          String?
  createdAt     DateTime
  updatedAt     DateTime       @updatedAt
}

model Faq {
  id             String       @id @default(cuid())
  question       String
  answer         String
  category       FaqCategory?
  published      Boolean
  language       String
  project        Project
  author         User
  largeLinkTitle String?
  largeLink      String?
  createdAt      DateTime     @default(now())
  updatedAt      DateTime     @updatedAt
}

model PostCategory {
  id      String        @id @default(cuid())
  name    String
  project Project
  posts   PostVersion[]
}

model FaqCategory {
  id      String  @id @default(cuid())
  name    String
  project Project
  faqs    Faq[]
}

model Section {
  id      String        @id @default(cuid())
  project Project
  title   String
  items   SectionItem[] @relation(onDelete: CASCADE)
}

model SectionItem {
  id          String @id @default(cuid())
  amount      Int
  description String
}

model Establishment {
  id             String          @id @default(cuid())
  project        Project
  name           String
  country        String?
  street         String?
  city           String?
  postalCode     String?
  morningHours   BusinessHours[] @relation(name: "morning")
  afternoonHours BusinessHours[] @relation(name: "afternoon")
  departments    Department[]
  email          String?
  phone          String?
}

model BusinessHours {
  id        String         @id @default(cuid())
  morning   Establishment? @relation(name: "morning")
  afternoon Establishment? @relation(name: "afternoon")
  day       Int
  openTime  DateTime?
  closeTime DateTime?
}

model Department {
  id     String             @id @default(cuid())
  name   String
  people DepartmentPeople[]
}

model DepartmentPeople {
  id       String  @id @default(cuid())
  name     String
  jobTitle String?
  phone    String?
  email    String?
}

model SupplierCategory {
  id          String                @id @default(cuid())
  project     Project
  name        String
  subCategory SupplierSubCategory[]
}

model SupplierSubCategory {
  id        String     @id @default(cuid())
  name      String
  suppliers Supplier[]
}

model Supplier {
  id   String @id @default(cuid())
  name String
  logo String
}

Seed:

import { Photon } from "@prisma/photon";
const photon = new Photon();

const seed = async () => {
  const company = await photon.companies.create({
    data: {
      name: "xx"
    }
  });
  const user = await photon.users.create({
    data: {
      authId: "Ol6Vs1GxypQwkTbPT8P0PU0qVBI2",
      name: "Petr Vomáčka",
      email: "[email protected]",
      profileImg:
        "https://example/ck03tt3g80001dvltghhja3hv.jpeg"
    }
  });
  const admin = await photon.users.create({
    data: {
      authId: "Sxut9eM54maqdiXYLV5q0KK5i0x1",
      name: "Admin",
      email: "[email protected]",
      profileImg:
        "https://storage.googleapis.com/xx-xx/ck03tt3g80001dvltghhja3hv.jpeg"
    }
  });
  const project1 = await photon.projects.create({
    data: {
      sectionFeature: true,
      establishmentFeature: true,
      supplierFeature: true,
      name: "XX",
      logo:
        "https://storage.googleapis.com/xx-xx/xx.svg",
      faqFeature: true,
      blogFeature: true,
      languages: JSON.stringify({
        cz: true,
        en: true,
        de: false,
        pl: true
      }),
      editorConfig: JSON.stringify({
        font: "Arial",
        fontSize: "14",
        h1FontSize: "24",
        h2FontSize: "18"
      }),
      logoSmall:
        "https://storage.googleapis.com/xx-xx/bitstock-small.svg",
      company: {
        connect: {
          id: company.id
        }
      },
      users: {
        connect: [user.email].map((email: string) => ({
          email
        }))
      },
      admins: {
        connect: [user.email].map((email: string) => ({
          email
        }))
      }
    }
  });
  const project2 = await photon.projects.create({
    data: {
      sectionFeature: true,
      establishmentFeature: true,
      supplierFeature: true,
      name: "xx",
      logo: "https://storage.googleapis.com/xx-xx/xx.svg",
      faqFeature: true,
      blogFeature: true,
      languages: JSON.stringify({
        cz: true,
        en: true,
        de: false,
        pl: false
      }),
      editorConfig: JSON.stringify({
        font: "Verdana",
        fontSize: "18",
        h1FontSize: "32",
        h2FontSize: "24"
      }),
      logoSmall:
        "https://storage.googleapis.com/xx-xx/xx-small.svg",
      company: {
        connect: {
          id: company.id
        }
      },
      users: {
        connect: [user.email].map((email: string) => ({
          email
        }))
      },
      admins: {
        connect: [user.email].map((email: string) => ({
          email
        }))
      }
    }
  });
  await photon.postCategories.create({
    data: {
      name: "Category 1",
      project: {
        connect: {
          id: project1.id
        }
      }
    }
  });
  await photon.postCategories.create({
    data: {
      name: "Category 2",
      project: {
        connect: {
          id: project2.id
        }
      }
    }
  });
  await photon.faqCategories.create({
    data: {
      name: "Category 1",
      project: {
        connect: {
          id: project1.id
        }
      }
    }
  });
  await photon.faqCategories.create({
    data: {
      name: "Category 2",
      project: {
        connect: {
          id: project2.id
        }
      }
    }
  });
  const projects = [project1, project2];
  console.log({ company, projects, user });
  process.exit();
};

seed();

lift save command warns:

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

  • You are about to alter the column `A` on the `_admins` table, which still contains 4 non-null values. The data in that column will be lost.
  • You are about to alter the column `B` on the `_admins` table, which still contains 4 non-null values. The data in that column will be lost.
  • You are about to alter the column `closeTime` on the `BusinessHours` table, which still contains 6 non-null values. The data in that column will be lost.
  • You are about to alter the column `openTime` on the `BusinessHours` table, which still contains 6 non-null values. The data in that column will be lost.
  • You are about to alter the column `jobTitle` on the `DepartmentPeople` table, which still contains 6 non-null values. The data in that column will be lost.
  • You are about to alter the column `email` on the `Establishment` table, which still contains 1 non-null values. The data in that column will be lost.
  • You are about to alter the column `project` on the `Establishment` table, which still contains 1 non-null values. The data in that column will be lost.
  • You are about to alter the column `author` on the `Faq` table, which still contains 70 non-null values. The data in that column will be lost.
  • You are about to alter the column `createdAt` on the `Faq` table, which still contains 70 non-null values. The data in that column will be lost.
  • You are about to alter the column `largeLink` on the `Faq` table, which still contains 5 non-null values. The data in that column will be lost.
  • You are about to alter the column `largeLinkTitle` on the `Faq` table, which still contains 5 non-null values. The data in that column will be lost.
  • You are about to alter the column `project` on the `Faq` table, which still contains 70 non-null values. The data in that column will be lost.
  • You are about to alter the column `updatedAt` on the `Faq` table, which still contains 70 non-null values. The data in that column will be lost.
  • You are about to alter the column `project` on the `FaqCategory` table, which still contains 2 non-null values. The data in that column will be lost.
  • You are about to alter the column `project` on the `File` table, which still contains 40 non-null values. The data in that column will be lost.
  • You are about to alter the column `draftedVersion` on the `Post` table, which still contains 43 non-null values. The data in that column will be lost.
  • You are about to alter the column `publishedVersion` on the `Post` table, which still contains 43 non-null values. The data in that column will be lost.
  • You are about to alter the column `project` on the `PostCategory` table, which still contains 8 non-null values. The data in that column will be lost.
  • You are about to alter the column `A` on the `_PostCategoryToPostVersion` table, which still contains 73 non-null values. The data in that column will be lost.
  • You are about to alter the column `B` on the `_PostCategoryToPostVersion` table, which still contains 73 non-null values. The data in that column will be lost.
  • You are about to alter the column `author` on the `PostVersion` table, which still contains 120 non-null values. The data in that column will be lost.
  • You are about to alter the column `createdAt` on the `PostVersion` table, which still contains 120 non-null values. The data in that column will be lost.
  • You are about to alter the column `ogDescription` on the `PostVersion` table, which still contains 120 non-null values. The data in that column will be lost.
  • You are about to alter the column `ogTitle` on the `PostVersion` table, which still contains 120 non-null values. The data in that column will be lost.
  • You are about to alter the column `project` on the `PostVersion` table, which still contains 120 non-null values. The data in that column will be lost.
  • You are about to alter the column `tags` on the `PostVersion` table, which still contains 13 non-null values. The data in that column will be lost.
  • You are about to alter the column `updatedAt` on the `PostVersion` table, which still contains 120 non-null values. The data in that column will be lost.
  • You are about to alter the column `company` on the `Project` table, which still contains 4 non-null values. The data in that column will be lost.
  • You are about to alter the column `webUrl` on the `Project` table, which still contains 2 non-null values. The data in that column will be lost.
  • You are about to alter the column `A` on the `_ProjectToUser` table, which still contains 22 non-null values. The data in that column will be lost.
  • You are about to alter the column `B` on the `_ProjectToUser` table, which still contains 22 non-null values. The data in that column will be lost.
  • You are about to alter the column `project` on the `Section` table, which still contains 1 non-null values. The data in that column will be lost.
  • You are about to alter the column `project` on the `SupplierCategory` table, which still contains 1 non-null values. The data in that column will be lost.
  • You are about to alter the column `authId` on the `User` table, which still contains 16 non-null values. The data in that column will be lost.
  • You are about to alter the column `createdAt` on the `User` table, which still contains 22 non-null values. The data in that column will be lost.
  • You are about to alter the column `profileImg` on the `User` table, which still contains 8 non-null values. The data in that column will be lost.
  • You are about to alter the column `updatedAt` on the `User` table, which still contains 22 non-null values. The data in that column will be lost.

I'm having the same issue, thought I would mention report id 904 (as per the CLI's request).

Error in migration engine.
Reason: [src/libcore/result.rs:1165:5] Error parsing the migration steps: Error("missing field `tag`", line: 1, column: 83)

I also deleted the migrations folder.

Deleting the SQLite DB and then running Prisma2 dev fixed the issue, I assume it relates to there being DB records associated with a migration, but no physical files?

Might be related: https://github.com/prisma/lift/issues/239
I tried to delete the database and it migrates without an issue because there are no data in the database. Once I seed the database I have the same issue. It restarts all optional and DateTime fields.

This should be fixed by https://github.com/prisma/prisma-engine/pull/318 :) It will be in the next alpha release.

You had a _lot_ of columns with that problem, so the fix may not work for absolutely all of them. Please open an issue if it still doesn't look right in the next alpha (476).

@tomhoule Alpha fixed most issues, but I still have the warning with a Float type that is getting altered

Also I am getting this error after confirming it:

Response: {
  "jsonrpc": "2.0",
  "error": {
    "code": 4466,
    "message": "The migration engine panicked while handling the request.
 Check the data field for details.",
    "data": {
      "message": "Failure during a migration command: Generic error. (err
or: The enum PaymentFormat does not exist in this Datamodel. It is not po
ssible to update it.)",
      "backtrace": null
    }
  },
  "id": 10
}

PaymentFormat is an enum like this:

enum PaymentFormat {
  CARD
  CASH
}

what I have done is just deleted one enum key from the enum. Before it was

enum PaymentFormat {
  CARD
  CASH
  PAYPAL
}

Also @tomhoule if you create a database from the datamodel I posted above and seed it (as above), then running prisma2 lift save shows this warning:

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

  • You are about to alter the column `length` on the `File` table, which still contains 2 non-null values. The data in that column will be lost.
  • You are about to alter the column `preview` on the `File` table, which still contains 2 non-null values. The data in that column will be lost.
  • You are about to alter the column `password` 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 `username` on the `User` table, which still contains 1 non-null values. The data in that column will be lost.

Looking into it now

Weird, the warnings say that the columns are altered but they're not in the schema from the issue description. Can you try narrowing the issue down and opening a new issue? Sorry to ask this much but I don't have tons of time to investigate at the moment.

@tomhoule I put together a more detailed issue, hope it helps https://github.com/prisma/lift/issues/267

Thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings