I'm using Prisma with MySQL. My current database stores passwords in plain text, and I need to migrate them to bcrypt hashes.
When deploying this change via prisma migrate dev, I need to:
- Update the schema to accommodate hashed passwords.
- Transform existing plaintext passwords to bcrypt hashes.
Question:
Does Prisma provide a way to run custom scripts (e.g., a TypeScript function to hash passwords) during the migration process?
If not, what’s the recommended approach?
This is my schema:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model User {
id String @id @unique @db.Char(32) // unsigned UUID
name String @unique @db.VarChar(16)
password String @db.VarChar(32)
//hashedPassword String @db.VarChar(60)
articles Article[]
createdAt DateTime @default(now())
}
// more...
storepassword in plain text. well this is your end issue. you need encrypt the plain-text password with something likebcryptthen add the password data to database. and then when you view it n db, it won't be plain text anymore. this is how i do it in Nextjs