'npx prisma db seed' not responding

anyone have this issue where seeding the db does nothing and gets stuck? screenshot at the bottom of this post this is my seed.ts
import { PrismaClient } from "@prisma/client";
import { hash } from "bcrypt";
const prisma = new PrismaClient();


export async function main(){
const password = await hash('test', 123)
const user = await prisma.user.upsert({
where: {
},
update:{},
create:{
name: 'Test User',
password: password
}
})

console.log(user)
}

main()
.then(() => prisma.$disconnect())
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
import { PrismaClient } from "@prisma/client";
import { hash } from "bcrypt";
const prisma = new PrismaClient();


export async function main(){
const password = await hash('test', 123)
const user = await prisma.user.upsert({
where: {
},
update:{},
create:{
name: 'Test User',
password: password
}
})

console.log(user)
}

main()
.then(() => prisma.$disconnect())
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
Solution:
oh i figured it out, you don't set the schema to password: password, you just say password
Jump to solution
5 Replies
Ryan
RyanOP17mo ago
also, when i change the seeding file to:
import { PrismaClient } from "@prisma/client";
import { hash } from "bcrypt";
const prisma = new PrismaClient();


export async function main(){

const user = await prisma.user.upsert({
where: {
},
update:{},
create:{
name: 'Test User',
password: "password"
}
})

console.log(user)
}

main()
.then(() => prisma.$disconnect())
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
import { PrismaClient } from "@prisma/client";
import { hash } from "bcrypt";
const prisma = new PrismaClient();


export async function main(){

const user = await prisma.user.upsert({
where: {
},
update:{},
create:{
name: 'Test User',
password: "password"
}
})

console.log(user)
}

main()
.then(() => prisma.$disconnect())
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
it now works so it seems like the seed.ts file doesn't like me using bcrypt.hash() in the way i'm using it
Solution
Ryan
Ryan17mo ago
oh i figured it out, you don't set the schema to password: password, you just say password
Mocha
Mocha17mo ago
Isn't that just an ESLint rule? { password } is equivalent to { password : password }
Ryan
RyanOP17mo ago
yeah on second thought it might have been the hash('test', 123) i think thats an invalid second argument but i changed both at the same time before running npx prisma db seed again and after that it worked. I think maybe 12 is a specific thing and not an random seed to a hash function
Mocha
Mocha17mo ago
from their README, argument 2 is:
salt - [REQUIRED] - the salt to be used to hash the password. if specified as a number then a salt will be generated with the specified number of rounds and used
https://github.com/kelektiv/node.bcrypt.js#api
GitHub
GitHub - kelektiv/node.bcrypt.js: bcrypt for NodeJs
bcrypt for NodeJs. Contribute to kelektiv/node.bcrypt.js development by creating an account on GitHub.
Want results from more Discord servers?
Add your server