Hey, Prisma :prisma-rainbow: Do you all have a re...
# prisma-migrate
t
Hey, Prisma prisma rainbow Do you all have a recommended way of “renaming” ENUM fields for a non-empty DB? Say I have this schema.
Copy code
model Plan {
  id                  String                 @id @default(cuid())
  createdAt           DateTime               @default(now())
  updatedAt           DateTime?              @updatedAt
  name                String
  description         String?
  status              PlanStatus             @default(DRAFT)
}

enum PlanStatus {
  LIVE
  DRAFT
}
and I want to change it to….
Copy code
model Plan {
  id                  String                 @id @default(cuid())
  createdAt           DateTime               @default(now())
  updatedAt           DateTime?              @updatedAt
  name                String
  description         String?
  status              PlanStatus             @default(ACTIVE)
}

enum PlanStatus {
  ACTIVE
  INACTIVE
}
Essentially I want to change
LIVE
->
ACTIVE
and
DRAFT
->
INACTIVE
At the moment my current plan is to… 1. add ACTIVE and INACTIVE to the PlanStatus enum such that I would have.
Copy code
enum PlanStatus {
  ACTIVE
  INACTIVE
  LIVE
  DRAFT
}
2. migrate DB 3. run a script that would update all LIVE values to ACTIVE and all DRAFT values to INACTIVE 4. remove LIVE and DRAFT from my schema
Copy code
enum PlanStatus {
  ACTIVE
  INACTIVE
}
5. migrate again I’m hoping there is a cleaner way to achieve is 🙂 Thanks!
t
Hi Tyler! I think tat' the right way to go about it. Note that if you are on postgres, step 1 will have to be split in two since you can't add more than one value to an existing enum in a migration (it's a database limitation)
t
Ah interesting! Will prisma automatically handle that for me? Or will I need to add one enum field. Run the migration, add the other, and then migrate again??
t
We don't handle that automatically, you can run the migrations one after another in the same
deploy
, but you need to create two migrations.
t
Ok thanks. Last question…. will I get an error if I run
deploy dev
with both fields added? (assuming I would.) Just want to make sure there’s no room for me to break anything.
t
You mean just
deploy
with a migration that adds both values? You will get a regular database error, unfortunately
t
ah sorry I meant
prisma migrate dev
t
ah, that would generate a migration with a warning that applying it would be an error, and you need to split it into two migrations
t
gotcha gotcha. Alrighty, well thanks for your help!