traintrape-moi/server/prisma/seed.ts

32 lines
795 B
TypeScript
Raw Permalink Normal View History

2024-12-07 09:24:41 +00:00
import { PrismaClient } from '@prisma/client'
2024-12-07 12:06:15 +00:00
import * as bcrypt from 'bcrypt'
2024-12-07 09:24:41 +00:00
const prisma = new PrismaClient()
async function main() {
2024-12-08 15:34:06 +00:00
const game = await prisma.game.create({ data: {} })
2024-12-07 12:06:15 +00:00
const emmyPassword = await bcrypt.hash("Emmy", 10)
2024-12-08 12:41:37 +00:00
const emmy = await prisma.player.upsert({
where: { id: 1 },
update: { name: 'Emmy' },
2024-12-07 12:06:15 +00:00
create: { name: 'Emmy', password: emmyPassword },
2024-12-07 09:24:41 +00:00
})
2024-12-07 12:06:15 +00:00
const taminaPassword = await bcrypt.hash("Tamina", 10)
2024-12-08 12:41:37 +00:00
const tamina = await prisma.player.upsert({
where: { id: 2 },
update: { name: 'Tamina' },
2024-12-07 12:06:15 +00:00
create: { name: 'Tamina', password: taminaPassword },
2024-12-07 09:24:41 +00:00
})
2024-12-08 15:34:06 +00:00
console.log({ game, emmy, tamina })
}
main()
.catch((e) => {
2024-12-07 09:24:41 +00:00
console.error(e)
process.exit(1)
})
.finally(async () => {
2024-12-07 09:24:41 +00:00
await prisma.$disconnect()
})