|
| 1 | +import { Prisma, PrismaClient } from "@prisma/client"; |
| 2 | +import bcrypt from "bcrypt"; |
| 3 | + |
| 4 | +const prisma = new PrismaClient(); |
| 5 | + |
| 6 | +const userData: Prisma.UserCreateInput = { |
| 7 | + email: "example@gmail.com", |
| 8 | + hashedPassword: "", |
| 9 | + pets: { |
| 10 | + create: [ |
| 11 | + { |
| 12 | + name: "Benjamin", |
| 13 | + ownerName: "John Doe", |
| 14 | + imageUrl: |
| 15 | + "https://images.unsplash.com/photo-1517849845537-4d257902454a?auto=format&fit=crop&q=100&w=1935&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", |
| 16 | + age: 2, |
| 17 | + notes: |
| 18 | + "Doesn't like to be touched on the belly. Plays well with other dogs.", |
| 19 | + }, |
| 20 | + { |
| 21 | + name: "Richard", |
| 22 | + ownerName: "Josephine Dane", |
| 23 | + imageUrl: |
| 24 | + "https://images.unsplash.com/photo-1583337130417-3346a1be7dee?auto=format&fit=crop&q=100&w=1964&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", |
| 25 | + age: 5, |
| 26 | + notes: "Needs medication twice a day.", |
| 27 | + }, |
| 28 | + { |
| 29 | + name: "Anna", |
| 30 | + ownerName: "Frank Doe", |
| 31 | + imageUrl: |
| 32 | + "https://images.unsplash.com/photo-1537151625747-768eb6cf92b2?auto=format&fit=crop&q=100&w=1970&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", |
| 33 | + age: 4, |
| 34 | + notes: "Allergic to chicken.", |
| 35 | + }, |
| 36 | + ], |
| 37 | + }, |
| 38 | +}; |
| 39 | + |
| 40 | +async function main() { |
| 41 | + console.log(`Start seeding ...`); |
| 42 | + |
| 43 | + const hashedPassword = await bcrypt.hash("example", 10); |
| 44 | + userData.hashedPassword = hashedPassword; |
| 45 | + |
| 46 | + await prisma.user.create({ |
| 47 | + data: userData, |
| 48 | + }); |
| 49 | + |
| 50 | + console.log(`Seeding finished.`); |
| 51 | +} |
| 52 | + |
| 53 | +main() |
| 54 | + .then(async () => { |
| 55 | + await prisma.$disconnect(); |
| 56 | + }) |
| 57 | + .catch(async (e) => { |
| 58 | + console.error(e); |
| 59 | + await prisma.$disconnect(); |
| 60 | + process.exit(1); |
| 61 | + }); |
0 commit comments