Skip to content

Commit

Permalink
fix(seed.ts): Fix seeding script failing due to unique constraint (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashko9807 authored Jul 17, 2024
1 parent cc7134f commit f344ecd
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions db/seed/donationWish/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,35 @@ export async function donationsWishesSeed() {
throw new Error('There are no campaigns created yet!')
}

const donations = await prisma.donation.findMany()
if (!donations) {
const donation = await prisma.donation.findFirst()
if (!donation) {
throw new Error('There are no donations created yet!')
}

for (const donation of donations) {
const person = await prisma.person.findFirst()
if (!person) {
throw new Error('There are no people created yet!')
}
const campaign = await prisma.campaign.findFirst({
where: {
vaults: {
some: {
id: donation.targetVaultId,
},
const person = await prisma.person.findFirst()
if (!person) {
throw new Error('There are no people created yet!')
}
const campaign = await prisma.campaign.findFirst({
where: {
vaults: {
some: {
id: donation.targetVaultId,
},
},
})
if (!campaign) {
throw new Error('There are no campaign with this vault created yet!')
}
const donationWishData = donationWishFactory.build({
campaignId: campaign.id,
personId: person.id,
donationId: donation.id,
})

await prisma.donationWish.create({
data: donationWishData,
})
},
})
if (!campaign) {
throw new Error('There are no campaign with this vault created yet!')
}
const donationWishData = donationWishFactory.build({
campaignId: campaign.id,
personId: person.id,
donationId: donation.id,
})

await prisma.donationWish.createMany({
data: [donationWishData],
skipDuplicates: true,
})
}

0 comments on commit f344ecd

Please sign in to comment.