AndrewSouthpaw / crdb-prisma-migration-repro-2022-12-12

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Demonstrates issue with Prisma generating migration that is incompatible with CRDB. Related ticket: https://support.cockroachlabs.com/hc/en-us/requests/14983?page=1

Setup

  1. npm install
  2. Have CRDB v22.2 running on port 26257
  3. npx prisma migrate dev
  4. 💥

Should get this error:

Applying migration `20221212204348_breaking_migration`
Error: P3018

A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve

Migration name: 20221212204348_breaking_migration

Database error code: 55000

Database error:
ERROR: column "balance" being dropped, try again later

DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E55000), message: "column \"balance\" being dropped, try again later", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("add_column.go"), line: Some(244), routine: Some("checkColumnDoesNotExist") }

Then change to running v22.1.11 with a fresh DB. Run npx prisma migrate dev and now it'll work.

Discussion

The problematic migration is here: https://github.com/AndrewSouthpaw/crdb-prisma-migration-repro-2022-12-12/commit/e69b1e590c8fc5645113072482d76af86bf5cb08. If you change a column Int -> BigInt it'll create a migration file that is incompatible with CRDB.

About


Languages

Language:JavaScript 96.2%Language:Shell 3.8%