Hello. I'm just seeking for advice. I need to norm...
# prisma-migrate
m
Hello. I'm just seeking for advice. I need to normalise my model a little bit. I need to go from:
Copy code
model Booking {
  id             String         @id @default(cuid()) @db.VarChar(30)
  name           String
  forename       String?
  email          String?
  phone          String?
}
to:
Copy code
model Booking {
  id             String         @id @default(cuid()) @db.VarChar(30)
  clientId       String
  client         Client         @relation(fields: [clientId], references: [id])
}

model Client {
  id             String         @id @default(cuid()) @db.VarChar(30)
  name           String
  forename       String?
  email          String?
  phone          String?
  bookings       Booking[]
}
I'm asking for the best way to approach this mostly in terms of the whole process and modifying the staging, production databases afterwards. Are there some script examples using prisma to modify the whole database? Couldn't find anything on the Prisma page except the seed scripts. Is there anything else I should consider by doing such normalisation. Any pitfalls I should be aware of? Thank You :)
r
@Maciek K 👋 You could go about this in two steps where dev and prod are updated after each step: 1. Create the relation and leave the fields in booking as is to prevent data loss. Add code in seed to make sure all the relations are transferred correctly. Then migrate and seed can be run on production for the same 2. Remove the fields from
Booking
as the data has been migrated.