Best practices for updating column type when there are existing records

I'm seeking some guidance on updating a column type when there are existing records in my database. Here's the scenario: Original Model:
model User {
id String @id @default(uuid())
posts String[]
}
model User {
id String @id @default(uuid())
posts String[]
}
New Model:
model User {
id String @id @default(uuid())
posts Int
}
model User {
id String @id @default(uuid())
posts Int
}
As you can see, I'm transitioning the posts field from an array of strings to a single integer. However, I'm unsure about the best approach for handling this change when there is existing records with the String[] type. If anyone has links, videos or documentation to share on this, would be greatly appreciated.
4 Replies
alessandroooo
alessandroooo2mo ago
you'd have to push the schema everytime
alessandroooo
alessandroooo2mo ago
Relations (Reference) | Prisma Documentation
A relation is a connection between two models in the Prisma schema. This page explains how you can define one-to-one, one-to-many and many-to-many relations in Prisma.
alessandroooo
alessandroooo2mo ago
this is what you want to do, relations @goofygoober
goofygoober
goofygoober2mo ago
no that's not what i'm looking for @alessandroooo I'm looking the change the field posts to have a type of Int from type String[] But my query is around, what are the best practices when there are existing records/entries in the database for posts with the old String[] type
Want results from more Discord servers?
Add your server
More Posts