Skip to content
This repository was archived by the owner on Aug 25, 2021. It is now read-only.
This repository was archived by the owner on Aug 25, 2021. It is now read-only.

Migration fails when changing an enum value in Postgres #614

@kraglalbert

Description

@kraglalbert

Bug description

Today I updated prisma-cli from version 2.4.x to the latest version and a migration that previously worked now fails. The migration itself is pretty simple since it's just changing an enum value. Below are the generated files for the migration:

steps.json:

{
  "version": "0.3.14-fixed",
  "steps": [
    {
      "tag": "UpdateEnum",
      "enum": "ConsultationStatus",
      "createdValues": [
        "CONFIRMED"
      ],
      "deletedValues": [
        "ACCEPTED"
      ]
    }
  ]
}

README.md:

# Migration `20201001212409-update-consultation-status-enum`

This migration has been generated by kraglalbert at 10/1/2020, 2:24:09 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.

## Database Steps

CREATE TYPE "ConsultationStatus_new" AS ENUM ('PENDING', 'REJECTED', 'CONFIRMED', 'COMPLETED');
ALTER TABLE "public"."Consultation" ALTER COLUMN "status" DROP DEFAULT,
                        ALTER COLUMN "status" TYPE "ConsultationStatus_new" USING ("status"::text::"ConsultationStatus_new"),
                        ALTER COLUMN "status" SET DEFAULT 'PENDING';
ALTER TYPE "ConsultationStatus" RENAME TO "ConsultationStatus_old";
ALTER TYPE "ConsultationStatus_new" RENAME TO "ConsultationStatus";
DROP TYPE "ConsultationStatus_old"

## Changes

diff --git schema.prisma schema.prisma
migration 20200922171456-add-start-and-end-time-to-consultation..20201001212409-update-consultation-status-enum
--- datamodel.dml
+++ datamodel.dml
@@ -1,7 +1,7 @@
 datasource postgres {
   provider = "postgresql"
-  url = "***"
+  url = "***"
 }
 generator client {
   provider = "prisma-client-js"
@@ -115,7 +115,7 @@
 enum ConsultationStatus {
   PENDING
   REJECTED
-  ACCEPTED
+  CONFIRMED
   COMPLETED
 }

I'm working with Postgres which allows enum types to be defined. The migrations before this one are applied successfully but this one fails which prevents the migrations after it from being applied as well. Is this a bug or is there something I'm doing wrong on my end?

How to reproduce

  1. Update a value in an existing enum in schema.prisma
  2. Save the migration with prisma migrate save --experimental
  3. Apply the migration with prisma migrate up --experimental
  4. Get the following output:
Database Changes:

Migration                                       Database actions  Status

20201001212409-update-consultation-status-enum   statements.

You can get the detailed db changes with prisma migrate up --experimental --verbose
Or read about them here:
      ./migrations/20201001212409-update-consultation-status-enum/README.md

Error: Connector error: Error querying the database: Error querying the database: db error: ERROR: current transaction is aborted, commands ignored until end of transaction block
   0: migration_core::api::ApplyMigration
           with migration_id="20201001212409-update-consultation-status-enum"
             at migration-engine/core/src/api.rs:93

Expected behavior

The migration is applied successfully.

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: v12.14.1
  • Prisma version:
@prisma/cli          : 2.9.0
@prisma/client       : 2.4.1
Current platform     : darwin
Query Engine         : query-engine 369b3694b7edb869fad14827a33ad3f3f49bbc20 (at node_modules/@prisma/cli/query-engine-darwin)
Migration Engine     : migration-engine-cli 369b3694b7edb869fad14827a33ad3f3f49bbc20 (at node_modules/@prisma/cli/migration-engine-darwin)
Introspection Engine : introspection-core 369b3694b7edb869fad14827a33ad3f3f49bbc20 (at node_modules/@prisma/cli/introspection-engine-darwin)
Format Binary        : prisma-fmt 369b3694b7edb869fad14827a33ad3f3f49bbc20 (at node_modules/@prisma/cli/prisma-fmt-darwin)
Studio               : 0.296.0

Thank you!

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