Skip to content

Commit

Permalink
templates: fixes the seeding for the website template when using post…
Browse files Browse the repository at this point in the history
…gres (#9758)
  • Loading branch information
paulpopus authored Dec 4, 2024
1 parent 0829a35 commit 3d1305d
Showing 1 changed file with 10 additions and 32 deletions.
42 changes: 10 additions & 32 deletions templates/website/src/endpoints/seed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ export const seed = async ({
// as well as the collections and globals
// this is because while `yarn seed` drops the database
// the custom `/api/seed` endpoint does not

payload.logger.info(`— Clearing media...`)
payload.logger.info(`— Clearing collections and globals...`)

// clear the database
await Promise.all(
globals.map((global) =>
Expand All @@ -57,31 +54,16 @@ export const seed = async ({
),
)

await Promise.all(
collections.map((collection) =>
payload.delete({
collection: collection,
where: {
id: {
exists: true,
},
},
depth: 0,
context: {
disableRevalidate: true,
},
}),
),
)

const pages = await payload.delete({
collection: 'pages',
where: {},
context: {
disableRevalidate: true,
},
depth: 0,
})
for (const collection of collections) {
await payload.delete({
collection: collection,
where: {},
depth: 0,
context: {
disableRevalidate: true,
},
})
}

payload.logger.info(`— Seeding demo author and user...`)

Expand Down Expand Up @@ -217,7 +199,6 @@ export const seed = async ({
context: {
disableRevalidate: true,
},
select: { content: false },
data: JSON.parse(
JSON.stringify({ ...post1, categories: [technologyCategory.id] })
.replace(/"\{\{IMAGE_1\}\}"/g, String(image1ID))
Expand All @@ -232,7 +213,6 @@ export const seed = async ({
context: {
disableRevalidate: true,
},
select: { content: false },
data: JSON.parse(
JSON.stringify({ ...post2, categories: [newsCategory.id] })
.replace(/"\{\{IMAGE_1\}\}"/g, String(image2ID))
Expand All @@ -247,7 +227,6 @@ export const seed = async ({
context: {
disableRevalidate: true,
},
select: { content: false },
data: JSON.parse(
JSON.stringify({ ...post3, categories: [financeCategory.id] })
.replace(/"\{\{IMAGE_1\}\}"/g, String(image3ID))
Expand Down Expand Up @@ -284,7 +263,6 @@ export const seed = async ({
const contactForm = await payload.create({
collection: 'forms',
depth: 0,
select: { title: true },
data: JSON.parse(JSON.stringify(contactFormData)),
})

Expand Down

0 comments on commit 3d1305d

Please sign in to comment.