goofygoober
goofygoober
Explore posts from servers
PPrisma
Created by goofygoober on 4/24/2024 in #help-and-questions
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.
7 replies
TTCTheo's Typesafe Cult
Created by goofygoober on 9/27/2023 in #questions
Prisma migration issue on vercel deployment
Hi Gang, I'm facing a persistent migration issue with my prisma model in my PostgreSQL database hosted on Railway. Here's a breakdown of the situation: My original prisma schema model was the following:
model LenderFees {
id String @id @default(uuid())
lenderProductId String @unique @default(cuid())
lender LenderProduct @relation(fields: [lenderProductId], references: [id], onDelete: Cascade)
exitFee String
lineFee String
solicitorFee String
valuationFee String
otherFee String
model LenderFees {
id String @id @default(uuid())
lenderProductId String @unique @default(cuid())
lender LenderProduct @relation(fields: [lenderProductId], references: [id], onDelete: Cascade)
exitFee String
lineFee String
solicitorFee String
valuationFee String
otherFee String
I removed some columns and added new ones on a feature branch feat/edit-lender-fees
model LenderFees {
id String @id @default(uuid())
lenderProductId String @unique @default(cuid())
lender LenderProduct @relation(fields: [lenderProductId], references: [id], onDelete: Cascade)
exitFeeFlat String
lineFeeFlat String
solicitorFeeFlat String
valuationFeeFlat String
otherFeeFlat String
exitFeePercent String
lineFeePercent String
solicitorFeePercent String
valuationFeePercent String
otherFeePercent String
}
model LenderFees {
id String @id @default(uuid())
lenderProductId String @unique @default(cuid())
lender LenderProduct @relation(fields: [lenderProductId], references: [id], onDelete: Cascade)
exitFeeFlat String
lineFeeFlat String
solicitorFeeFlat String
valuationFeeFlat String
otherFeeFlat String
exitFeePercent String
lineFeePercent String
solicitorFeePercent String
valuationFeePercent String
otherFeePercent String
}
And quickly learnt that dropping columns with existing data had caused a few problems. After creating a migration file by running prisma migrate dev I had warnings that were in the migration.sql (which i called 20230925134023_lender_product_fees) but i did not see initially Issues: Removing columns with data resulted in warnings upon running npx prisma migrate dev. Deploying to Vercel produced an error while running the script "production:build": "npx prisma generate && npx prisma migrate deploy && next build" Persistent error:
migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>
The `20230925134023_lender_product_fees` migration started at 2023-09-25 14:30:12.419795 UTC failed
Error: Command "npm run production:build" exited with 1
migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>
The `20230925134023_lender_product_fees` migration started at 2023-09-25 14:30:12.419795 UTC failed
Error: Command "npm run production:build" exited with 1
Note again, this was all done on a feature branch feat/edit-lender-fees So I've abandoned that branch for now and gone to branched off main again to add some new feature. This new branch does have the before mentioned migration.sql file 20230925134023_lender_product_fees but I am still getting issues when deploying in the "Building step" with the same problem mentioned above.
Error: P3009
migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve
The `20230925134023_lender_product_fees` migration started at 2023-09-25 14:30:12.419795 UTC failed
Error: Command "npm run production:build" exited with 1
Error: P3009
migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve
The `20230925134023_lender_product_fees` migration started at 2023-09-25 14:30:12.419795 UTC failed
Error: Command "npm run production:build" exited with 1
Would anyone know why a branch that has nothing to do with the schema changes still be affecting the deployment?
2 replies
TTCTheo's Typesafe Cult
Created by goofygoober on 6/27/2023 in #questions
Setting up unit tests with Jest and React Testing Library
1 replies