-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update DB seed function to include new entities and properties
- Loading branch information
1 parent
a362070
commit 5ea1b05
Showing
1 changed file
with
44 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', | ||
|
@@ -28,10 +19,6 @@ const categoriesCity = [ | |
label: 'Transportation', | ||
color: '737373', | ||
}, | ||
{ | ||
label: 'Connectivity', | ||
color: '5ce1e6', | ||
}, | ||
{ | ||
label: 'Community', | ||
color: 'ff66c4', | ||
|
@@ -57,7 +44,7 @@ const categoriesUni = [ | |
}, | ||
] | ||
|
||
const listingsCity = [ | ||
const listingsCambridge = [ | ||
{ | ||
title: 'Cambridge Community Kitchen', | ||
slug: 'cambridge-community-kitchen', | ||
|
@@ -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() | ||
|
5ea1b05
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
resilience-web – ./
resilienceweb.org.uk
resilience-web-resilience-web.vercel.app
resilience-web-git-main-resilience-web.vercel.app
*.cambridgeresilienceweb.org.uk
www.resilienceweb.org.uk
*.resilienceweb.org.uk
cambridgeresilienceweb.org.uk
www.cambridgeresilienceweb.org.uk