Skip to content

Prisma Migrate generates incorrect sql when chaining different types of table altering operations (remove map from @id, add native type to other field) #24331

@omaziarz

Description

@omaziarz

Bug description

If you perform two different types of alteration on a table for instance renaming a constraint and altering the data type of a column then prisma migrate dev will generate incorrect sql code.

How to reproduce

  1. Consider the following schema:
    model Fruits {
       id Int @id(map:"custom_name")
       name String @db.VarChar
    }
  2. edit it in this way :
    model Fruits {
       id Int @id()
       name String
    }
  3. run prisma migrate dev
  4. you will get the following error
    Database error code: 42601
    
    Database error:
    ERROR: syntax error at or near ","
    

This is because the generated sql will look like this:

ALTER TABLE "Fruits" RENAME CONSTRAINT "custom_name" TO "fruits_pkey",
ALTER COLUMN "name" SET DATA TYPE TEXT; -- this should be a separate ALTER TABLE statement --

Expected behavior

the generated sql should look like this :

ALTER TABLE "Fruits" RENAME CONSTRAINT "custom_name" TO "fruits_pkey";
ALTER TABLE "Fruits" ALTER COLUMN "name" SET DATA TYPE TEXT;

Prisma information

// Add your schema.prisma
// Add your code using Prisma Client

Environment & setup

  • OS: macOS,
  • Database: PostgreSQL
  • Node.js version: v20.13.1

Prisma Version

5.14.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions