Skip to content

Commit

Permalink
fixing concurency in donationWish seeding (podkrepi-bg#570)
Browse files Browse the repository at this point in the history
* let db create the donationWish primary id

* fix: foreach creates problems with async/await, so replaced with sequential for()
  • Loading branch information
quantum-grit authored Oct 29, 2023
1 parent 4a6e572 commit 110443f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions db/seed/donationWish/factory.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Factory } from 'fishery'
import { faker } from '@faker-js/faker'
import { Prisma } from '@prisma/client'

import { DonationWish } from '.prisma/client'

export const donationWishFactory = Factory.define<DonationWish>(({ associations }) => ({
id: faker.datatype.uuid(),
message: faker.lorem.paragraph(),
campaignId: associations.campaignId || faker.datatype.uuid(),
personId: associations.personId || null,
donationId: associations.donationId || null,
createdAt: faker.date.past(),
updatedAt: faker.date.recent(),
}))
export const donationWishFactory = Factory.define<Prisma.DonationWishUncheckedCreateInput>(
({ associations }) => ({
message: faker.lorem.paragraph(),
campaignId: associations.campaignId || faker.datatype.uuid(),
personId: associations.personId || null,
donationId: associations.donationId || null,
createdAt: faker.date.past(),
updatedAt: faker.date.recent(),
}),
)
4 changes: 2 additions & 2 deletions db/seed/donationWish/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function donationsWishesSeed() {
throw new Error('There are no donations created yet!')
}

donations.forEach(async (donation) => {
for (const donation of donations) {
const person = await prisma.person.findFirst()
if (!person) {
throw new Error('There are no people created yet!')
Expand All @@ -41,5 +41,5 @@ export async function donationsWishesSeed() {
await prisma.donationWish.create({
data: donationWishData,
})
})
}
}

0 comments on commit 110443f

Please sign in to comment.