MCPcopy
hub / github.com/epicweb-dev/epic-stack / seed

Function seed

prisma/seed.ts:15–220  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13import { insertGitHubUser } from '#tests/mocks/github.ts'
14
15async function seed() {
16 console.log('🌱 Seeding...')
17 console.time(`🌱 Database has been seeded`)
18
19 console.time('🧹 Cleaned up the database...')
20 await cleanupDb()
21 console.timeEnd('🧹 Cleaned up the database...')
22
23 const totalUsers = 5
24 console.time(`👤 Created ${totalUsers} users...`)
25 const noteImages = await getNoteImages()
26 const userImages = await getUserImages()
27
28 for (let index = 0; index < totalUsers; index++) {
29 const userData = createUser()
30 await prisma.user
31 .create({
32 select: { id: true },
33 data: {
34 ...userData,
35 password: { create: createPassword(userData.username) },
36 image: { create: userImages[index % userImages.length] },
37 roles: { connect: { name: 'user' } },
38 notes: {
39 create: Array.from({
40 length: faker.number.int({ min: 1, max: 3 }),
41 }).map(() => ({
42 title: faker.lorem.sentence(),
43 content: faker.lorem.paragraphs(),
44 images: {
45 create: Array.from({
46 length: faker.number.int({ min: 1, max: 3 }),
47 }).map(() => {
48 const imgNumber = faker.number.int({ min: 0, max: 9 })
49 const img = noteImages[imgNumber]
50 if (!img) {
51 throw new Error(`Could not find image #${imgNumber}`)
52 }
53 return img
54 }),
55 },
56 })),
57 },
58 },
59 })
60 .catch((e) => {
61 console.error('Error creating a user:', e)
62 return null
63 })
64 }
65 console.timeEnd(`👤 Created ${totalUsers} users...`)
66
67 console.time(`🐨 Created admin user "kody"`)
68
69 const kodyImages = await promiseHash({
70 kodyUser: img({ filepath: './tests/fixtures/images/user/kody.png' }),
71 cuteKoala: img({
72 altText: 'an adorable koala cartoon illustration',

Callers 1

seed.tsFile · 0.85

Calls 7

cleanupDbFunction · 0.90
getNoteImagesFunction · 0.90
getUserImagesFunction · 0.90
createUserFunction · 0.90
createPasswordFunction · 0.90
imgFunction · 0.90
insertGitHubUserFunction · 0.90

Tested by

no test coverage detected