Skip to content

Commit

Permalink
Update DB seed function to include new entities and properties
Browse files Browse the repository at this point in the history
  • Loading branch information
DinerIsmail committed Nov 4, 2023
1 parent a362070 commit 5ea1b05
Showing 1 changed file with 44 additions and 29 deletions.
73 changes: 44 additions & 29 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@ import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

const locationCity = {
title: 'Cambridge City',
slug: 'cambridge-city',
}
const locationUni = {
title: 'University of Cambridge',
slug: 'cambridge-university',
}

const categoriesCity = [
const categoriesCambridge = [
{
label: 'Environment',
color: '7ed957',
Expand All @@ -28,10 +19,6 @@ const categoriesCity = [
label: 'Transportation',
color: '737373',
},
{
label: 'Connectivity',
color: '5ce1e6',
},
{
label: 'Community',
color: 'ff66c4',
Expand All @@ -57,7 +44,7 @@ const categoriesUni = [
},
]

const listingsCity = [
const listingsCambridge = [
{
title: 'Cambridge Community Kitchen',
slug: 'cambridge-community-kitchen',
Expand All @@ -66,73 +53,101 @@ const listingsCity = [
},
]

const listingsUni = [
const listingsDurham = [
{
title: 'Conservation Research Institute',
slug: 'conservation-research-institute',
},
]

async function main() {
const newLocationCity = await prisma.location.create({
data: locationCity,
const newWebCambridge = await prisma.location.create({
data: {
title: 'Cambridge',
slug: 'cambridge',
published: true,
image:
'https://resilienceweb.ams3.digitaloceanspaces.com/d395de3529d0bb86b05ee6501.jpg',
},
})

for (const category of categoriesCity) {
for (const category of categoriesCambridge) {
await prisma.category.create({
data: {
...category,
webId: newLocationCity.id,
webId: newWebCambridge.id,
},
})
}

const newLocationUni = await prisma.location.create({
data: locationUni,
const newWebDurham = await prisma.location.create({
data: {
title: 'Durham',
slug: 'durham',
published: true,
image:
'https://resilienceweb.ams3.digitaloceanspaces.com/f0b36873107d6cef9da5f2400.webp',
},
})

for (const category of categoriesUni) {
await prisma.category.create({
data: {
...category,
webId: newLocationUni.id,
webId: newWebDurham.id,
},
})
}

for (const listing of listingsCity) {
for (const listing of listingsCambridge) {
const newCategory = await prisma.category.findFirst({
where: {
webId: newLocationCity.id,
webId: newWebCambridge.id,
},
})

await prisma.listing.create({
data: {
...listing,
webId: newLocationCity.id,
webId: newWebCambridge.id,
categoryId: newCategory.id,
},
})
}

// eslint-disable-next-line @typescript-eslint/no-misused-promises
setTimeout(async () => {
for (const listing of listingsUni) {
for (const listing of listingsDurham) {
const newCategory = await prisma.category.findFirst({
where: {
webId: newLocationUni.id,
webId: newWebDurham.id,
},
})

await prisma.listing.create({
data: {
...listing,
webId: newLocationUni.id,
webId: newWebDurham.id,
categoryId: newCategory.id,
},
})
}
}, 1000)

const userCambridgeOwner = await prisma.user.create({
data: {
email: '[email protected]',
},
})

await prisma.ownership.create({
data: {
email: userCambridgeOwner.email,
webs: {
connect: [{ id: newWebCambridge.id }],
},
},
})
}

main()
Expand Down

1 comment on commit 5ea1b05

@vercel
Copy link

@vercel vercel bot commented on 5ea1b05 Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.