From 110443f7e38042185a82468483776cf9497da5a0 Mon Sep 17 00:00:00 2001 From: quantum-grit <91589884+quantum-grit@users.noreply.github.com> Date: Sun, 29 Oct 2023 21:49:17 +0200 Subject: [PATCH] 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() --- db/seed/donationWish/factory.ts | 22 +++++++++++----------- db/seed/donationWish/seed.ts | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/db/seed/donationWish/factory.ts b/db/seed/donationWish/factory.ts index 588095a47..50a92cc86 100644 --- a/db/seed/donationWish/factory.ts +++ b/db/seed/donationWish/factory.ts @@ -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(({ 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( + ({ 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(), + }), +) diff --git a/db/seed/donationWish/seed.ts b/db/seed/donationWish/seed.ts index b70ff273a..491f99cd6 100644 --- a/db/seed/donationWish/seed.ts +++ b/db/seed/donationWish/seed.ts @@ -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!') @@ -41,5 +41,5 @@ export async function donationsWishesSeed() { await prisma.donationWish.create({ data: donationWishData, }) - }) + } }