0

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...
3
  • can you share your schema please. Commented Jul 12 at 18:01
  • This is a matter of opinion, so I won't post it as an answer, but I would add a column for the password hash. Then UPDATE that column myself. Then drop the old plaintext password column in a separate migration. That way I'd give myself some safety margin so I can confirm the application is authenticating against the hashes successfully before obliterating the original plaintext passwords. Commented Jul 12 at 18:03
  • you say your database store password in plain text. well this is your end issue. you need encrypt the plain-text password with something like bcrypt then 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 Commented Aug 2 at 20:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.