Skip to content

Commit 110443f

Browse files
authored
fixing concurency in donationWish seeding (#570)
* let db create the donationWish primary id * fix: foreach creates problems with async/await, so replaced with sequential for()
1 parent 4a6e572 commit 110443f

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

db/seed/donationWish/factory.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Factory } from 'fishery'
22
import { faker } from '@faker-js/faker'
3+
import { Prisma } from '@prisma/client'
34

4-
import { DonationWish } from '.prisma/client'
5-
6-
export const donationWishFactory = Factory.define<DonationWish>(({ associations }) => ({
7-
id: faker.datatype.uuid(),
8-
message: faker.lorem.paragraph(),
9-
campaignId: associations.campaignId || faker.datatype.uuid(),
10-
personId: associations.personId || null,
11-
donationId: associations.donationId || null,
12-
createdAt: faker.date.past(),
13-
updatedAt: faker.date.recent(),
14-
}))
5+
export const donationWishFactory = Factory.define<Prisma.DonationWishUncheckedCreateInput>(
6+
({ associations }) => ({
7+
message: faker.lorem.paragraph(),
8+
campaignId: associations.campaignId || faker.datatype.uuid(),
9+
personId: associations.personId || null,
10+
donationId: associations.donationId || null,
11+
createdAt: faker.date.past(),
12+
updatedAt: faker.date.recent(),
13+
}),
14+
)

db/seed/donationWish/seed.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function donationsWishesSeed() {
1515
throw new Error('There are no donations created yet!')
1616
}
1717

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

0 commit comments

Comments
 (0)